57 lines
1.8 KiB
Shell
Executable file
57 lines
1.8 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
[[ $# -eq 4 ]] || {
|
|
echo "usage: consume-ghal-physical-probe.sh <world-root> <recovery-root> <probe-stage> <receipt-destination>" >&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" <<EOF
|
|
schema: guanghu.ghal-probe-consumption/v1
|
|
receipt_id: GH-OS-LAB-001-GHAL-PROBE-${probe_stage}-CONSUMPTION
|
|
status: VERIFIED_AND_CLEARED
|
|
observed_at: ${observed_at}
|
|
node_id: BS-SH-005
|
|
probe_stage: ${probe_stage}
|
|
proof_lba: 63
|
|
proof_cleared: true
|
|
observation_installed_at: ${receipt_destination}
|
|
next_action: INSTALL_NEXT_GHAL_PROBE_STAGE
|
|
EOF
|
|
chmod 0400 "${recovery_root}/GHAL-PROBE-CONSUMPTION.hldp"
|
|
cat "${recovery_root}/GHAL-PROBE-CONSUMPTION.hldp"
|