# vmix PE helpers, sourced by run.sh scripts running in the recovery. # Expects V=/Volumes/VMIX (set by pe.sh) and VOLUME_NAME from vmix.conf. V=${V:-/Volumes/VMIX} [ -f "$V/vmix.conf" ] && . "$V/vmix.conf" VOLUME_NAME=${VOLUME_NAME:-Macintosh HD} pe_log() { echo "VMIX: $*"; } pe_fail() { echo "VMIX-FAIL: $*"; exit 1; } # Mount the installed system's APFS volume group (System read-only, Data rw) and # export SYS / DATA mount points plus SYS_ID / DATA_ID device identifiers. pe_mount_target() { local list; list=$(diskutil list) DATA_ID=$(echo "$list" | awk -v n="APFS Volume $VOLUME_NAME - Data" 'index($0, n) {print $NF; exit}') SYS_ID=$(echo "$list" | awk -v n="APFS Volume $VOLUME_NAME " '!/ - Data/ && index($0, n) {print $NF; exit}') [ -n "$DATA_ID" ] && [ -n "$SYS_ID" ] || { pe_log "target volumes not found"; echo "$list"; return 1; } diskutil mount "$SYS_ID" >/dev/null 2>&1 || true diskutil mount "$DATA_ID" >/dev/null 2>&1 || true SYS=$(diskutil info "$SYS_ID" | sed -n 's/^ *Mount Point: *//p') DATA=$(diskutil info "$DATA_ID" | sed -n 's/^ *Mount Point: *//p') [ -d "$DATA/private/var/db" ] || { pe_log "Data volume not mounted (SYS=[$SYS] DATA=[$DATA])"; return 1; } pe_log "target mounted: SYS=[$SYS] DATA=[$DATA]" export SYS DATA SYS_ID DATA_ID } pe_unmount_target() { sync diskutil unmount "$DATA_ID" >/dev/null 2>&1 || true diskutil unmount "$SYS_ID" >/dev/null 2>&1 || true } # plist helpers on files of the (offline) target: create the file if missing. pe_plist_set() { # FILE KEYPATH TYPE VALUE (TYPE: string|bool|integer|float) local f=$1 k=$2 t=$3 v=$4 [ -f "$f" ] || plutil -create xml1 "$f" plutil -replace "$k" "-$t" "$v" "$f" } pe_plist_dict() { # FILE KEYPATH — make sure a dictionary exists at KEYPATH local f=$1 k=$2 [ -f "$f" ] || plutil -create xml1 "$f" plutil -extract "$k" xml1 -o /dev/null "$f" >/dev/null 2>&1 || plutil -insert "$k" -dictionary "$f" } # launchd service override on the target (disabled.plist): pe_service LABEL true|false pe_service_disabled() { local f="$DATA/private/var/db/com.apple.xpc.launchd/disabled.plist" mkdir -p "$(dirname "$f")" pe_plist_set "$f" "$1" bool "$2" } # version of the installed system pe_target_version() { plutil -extract ProductVersion raw -o - "$SYS/System/Library/CoreServices/SystemVersion.plist" 2>/dev/null; } pe_target_build() { plutil -extract ProductBuildVersion raw -o - "$SYS/System/Library/CoreServices/SystemVersion.plist" 2>/dev/null; }