#!/bin/bash # Inside a new macOS node VM, once, as root (Packer runs it). Makes the VM a # node: the `build` user every session runs as, /work and /config at the root # like on Linux, Rust with the Apple targets, git-lfs, sshd hooked into midas, # and the start job. Then the base image's admin password goes. set -euo pipefail here=$(cd "$(dirname "$0")" && pwd) # Packer's ssh session has no /usr/local/bin or Homebrew on its PATH, and # `sudo -u build` passes this PATH on: without it git cannot find git-lfs. export PATH=/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin # The account anything that lands here runs as. No password ever matches. if ! id build >/dev/null 2>&1; then uid=$(( $(dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1) + 1 )) dscl . -create /Users/build dscl . -create /Users/build UserShell /bin/bash dscl . -create /Users/build RealName "midas build" dscl . -create /Users/build UniqueID "$uid" dscl . -create /Users/build PrimaryGroupID 20 dscl . -create /Users/build NFSHomeDirectory /Users/build dscl . -create /Users/build Password '*' mkdir -p /Users/build && chown build:staff /Users/build fi # /work and /config at the root, as on Linux nodes. The system volume is # sealed, so they are synthetic links into the data volume. mkdir -p /Users/build/work /usr/local/etc/midas chown build:staff /Users/build/work grep -q '^work' /etc/synthetic.conf 2>/dev/null || printf 'work\tUsers/build/work\n' >> /etc/synthetic.conf grep -q '^config' /etc/synthetic.conf 2>/dev/null || printf 'config\tusr/local/etc/midas\n' >> /etc/synthetic.conf /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t || true # Tools. Homebrew belongs to the base image's admin user. QEMU boots a # bare-metal kernel a project builds (pinnacle) and checks what it prints, # as on Linux nodes. sudo -u admin -H /opt/homebrew/bin/brew install git-lfs rsync oven-sh/bun/bun qemu >/dev/null install -d /usr/local/bin # sshd runs its AuthorizedKeysCommand (/usr/local/bin/midas) only from a path # no other user can write, and the base image gives /usr/local/bin to admin. chown root:wheel /usr/local/bin && chmod 755 /usr/local/bin ln -sf /opt/homebrew/bin/git-lfs /usr/local/bin/git-lfs # Login shells (every node session) take their PATH from /etc/paths{,.d}. printf '/opt/homebrew/bin\n' > /etc/paths.d/50-homebrew sudo -u build -H bash -c ' curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable . "$HOME/.cargo/env" rustup target add aarch64-apple-ios aarch64-apple-ios-sim git lfs install ' xcodebuild -license accept 2>/dev/null || true # sshd's settings for midas are put in place by the start job on first boot, # not here: they admit only `build`, and Packer still logs in as admin to # finish and shut the VM down. install -d /usr/local/etc install -m 644 "$here/sshd.conf" /usr/local/etc/midas-sshd.conf systemsetup -setremotelogin on >/dev/null 2>&1 || launchctl load -w /System/Library/LaunchDaemons/ssh.plist || true # The node's start job: install the owner's midas, then serve. install -d /usr/local/libexec install -m 755 "$here/start.sh" /usr/local/libexec/midas-node-start install -m 644 "$here/eu.midas.node.plist" /Library/LaunchDaemons/eu.midas.node.plist rm -rf "$here"