#!/usr/bin/env bash set -euo pipefail [[ $# -eq 2 ]] || { echo "usage: arm-native-physical-once.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") /guanghu/bin/ghctl authorize "${world_root}" reboot_and_recover_bs_sh_005 \ >/dev/null grep -q "menuentry 'Guanghu OS native one-time proof'.*'guanghu-native-once'" \ /boot/grub/grub.cfg proof_before=$(mktemp) trap 'rm -f "${proof_before}"' EXIT dd if=/dev/vda of="${proof_before}" bs=512 skip=50 count=1 status=none cmp -s "${proof_before}" <(head -c 512 /dev/zero) grub-editenv /boot/grub/grubenv unset initrdfail prev_entry next_entry grub-reboot guanghu-native-once grub_state=$(grub-editenv /boot/grub/grubenv list) grep -q '^next_entry=guanghu-native-once$' <<<"${grub_state}" if grep -Eq '^(initrdfail|prev_entry)=' <<<"${grub_state}"; then echo "stale GRUB fallback state remains" >&2 exit 65 fi previous_boot_id=$(cat /proc/sys/kernel/random/boot_id) observed_at=$(date --iso-8601=seconds) cat >"${recovery_root}/ARMED-RECEIPT.hldp" <