#!/bin/bash # vmix PE hook. Runs as root from launchd when the patched Recovery boots # (injected by makeRecoveryPE). If a VMIX volume is attached it runs # /Volumes/VMIX/run.sh, records the exit status on the volume and powers off; # without one it does nothing and the recovery behaves normally. # Everything printed here goes to /dev/console, i.e. the host's serial log. exec >/dev/console 2>&1 echo "VMIX-PE: hook started $(date) uid=$(id -u)" V=/Volumes/VMIX i=0 while [ ! -f "$V/run.sh" ] && [ $i -lt 90 ]; do diskutil mount VMIX >/dev/null 2>&1 sleep 2; i=$((i + 1)) done if [ ! -f "$V/run.sh" ]; then echo "VMIX-PE: no VMIX volume, leaving the recovery alone" exit 0 fi echo "VMIX-PE: VMIX mounted after $i retries" caffeinate -dimsu -t 86400 >/dev/null 2>&1 & [ -f "$V/vmix.conf" ] && . "$V/vmix.conf" # certificate checks need a sane clock; a fresh VM RTC can be off [ -n "${BUILD_DATE:-}" ] && date -u "$BUILD_DATE" >/dev/null 2>&1 && echo "VMIX-PE: clock set to $(date -u)" export V cd "$V" echo "VMIX-PE: running run.sh" /bin/bash "$V/run.sh" 2>&1 | tee "$V/vmix-run.log" rc=${PIPESTATUS[0]} echo "$rc" > "$V/vmix-run.status" echo "VMIX-PE: run.sh exited $rc" if [ -f "$V/vmix-reboot" ]; then rm -f "$V/vmix-reboot"; sync echo "VMIX-PE: rebooting as requested" reboot exit 0 fi sync; sleep 1 diskutil unmount force "$V" >/dev/null 2>&1 echo "VMIX-PE-DONE rc=$rc" shutdown -h now