#!/bin/sh # vmix agent: LaunchDaemon that runs at every boot as root. 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). # This is the macOS counterpart of the Windows Audit Mode RunOnce script. LOG=/var/log/vmix-agent.log exec >>"$LOG" 2>&1 echo "=== vmix agent: $(date) ===" V=/Volumes/VMIX i=0 while [ ! -f "$V/vmix-run.sh" ] && [ $i -lt 60 ]; 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 sync sleep 2 diskutil unmount force "$V" >/dev/null 2>&1 shutdown -h now