#!/bin/sh # vmix agent: LaunchDaemon that runs at every boot as root (installed by the vmix # agent pkg via startosinstall --installpackage). If a volume named VMIX carrying # vmix-run.sh is attached, run it, record the result on the volume and power off. # Without the volume it is a no-op (normal boot). Counterpart of the Windows Audit # Mode RunOnce script; the generalize step removes it once the image is sealed. LOG=/var/log/vmix-agent.log exec >>"$LOG" 2>&1 echo "=== vmix agent: $(date) ===" # The agent pkg bootstraps this daemon during the OS install (to approve it past # Background Task Management, so launchd runs it at first boot). Don't do the job # in that installer environment — only on the installed system's first boot. if pgrep -x bootinstalld >/dev/null 2>&1 || pgrep -qx "Installer Progress" 2>/dev/null \ || [ -d /System/Volumes/Update/mnt1 ]; then echo "vmix agent: OS installer is running, skipping" exit 0 fi # let DiskArbitration settle so the VMIX volume is mountable sleep 5 V=/Volumes/VMIX i=0 while [ ! -f "$V/vmix-run.sh" ] && [ $i -lt 30 ]; do diskutil mount VMIX >/dev/null 2>&1 sleep 2 i=$((i + 1)) done if [ ! -f "$V/vmix-run.sh" ]; then echo "vmix agent: no VMIX volume, normal boot" exit 0 fi echo "vmix agent: running vmix-run.sh" cd "$V" || exit 1 sh "$V/vmix-run.sh" >"$V/vmix-run.log" 2>&1 rc=$? echo "vmix agent: vmix-run.sh exited $rc" echo "$rc" >"$V/vmix-run.status" cp "$LOG" "$V/vmix-agent.log" 2>/dev/null cp /var/log/vmix-agent-install.log "$V/vmix-agent-install.log" 2>/dev/null sync sleep 2 diskutil unmount force "$V" >/dev/null 2>&1 shutdown -h now