#!/usr/bin/env bash set -euo pipefail [[ $# -eq 4 ]] || { echo "usage: consume-ghal-physical-probe.sh " >&2 exit 64 } [[ ${EUID} -eq 0 ]] || { echo "must run as root" >&2 exit 77 } world_root=$(readlink -f "$1") recovery_root=$(readlink -f "$2") probe_stage=$3 receipt_destination=$(readlink -m "$4") [[ ${probe_stage} =~ ^[1-9]$ ]] /guanghu/bin/ghctl authorize "${world_root}" \ write_bootloader_and_system_partitions >/dev/null proof=${recovery_root}/lba63.ghal-observation.bin observation=${recovery_root}/GHAL-DIAGNOSTIC-OBSERVATION.hldp [[ -f ${proof} && -f ${observation} ]] python3 - "${proof}" "${probe_stage}" <<'PY' import pathlib import sys proof = pathlib.Path(sys.argv[1]).read_bytes() stage = int(sys.argv[2]) assert len(proof) == 512 assert proof[0] == 0xA5 assert proof[1:].startswith(b"GHOS_NATIVE_LONG64_DISK_PROOF\x00") assert proof[42] == 0x80 + stage assert proof[43] == 0 PY install -o root -g root -m 0400 "${observation}" "${receipt_destination}" dd if=/dev/zero of=/dev/vda bs=512 seek=63 count=1 \ conv=notrunc,fsync status=none cleared=$(mktemp) trap 'rm -f "${cleared}"' EXIT dd if=/dev/vda of="${cleared}" bs=512 skip=63 count=1 status=none cmp -s "${cleared}" <(head -c 512 /dev/zero) observed_at=$(date --iso-8601=seconds) cat >"${recovery_root}/GHAL-PROBE-CONSUMPTION.hldp" <