59 lines
2.2 KiB
Shell
Executable file
59 lines
2.2 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
test_root=$(mktemp -d)
|
|
trap 'rm -rf "${test_root}"' EXIT
|
|
|
|
"${source_root}/scripts/render-native-recovery-beacon.sh" "${test_root}"
|
|
|
|
active=${test_root}/guanghu-recovery-active.env
|
|
clear=${test_root}/guanghu-recovery-clear.env
|
|
grub=${test_root}/08_guanghu_native_recovery
|
|
|
|
[[ $(stat -c %s "${active}" 2>/dev/null || stat -f %z "${active}") -eq 1024 ]]
|
|
[[ $(stat -c %s "${clear}" 2>/dev/null || stat -f %z "${clear}") -eq 1024 ]]
|
|
grep -aFxq 'guanghu_recovery=ubuntu' "${active}"
|
|
if grep -aFq 'guanghu_recovery=ubuntu' "${clear}"; then
|
|
echo "clear recovery beacon contains the active marker" >&2
|
|
exit 1
|
|
fi
|
|
|
|
grep -Fq "load_env --file '(hd0)68+2' guanghu_recovery" "${grub}"
|
|
grep -Fq 'if [ "${guanghu_recovery}" = "ubuntu" ]; then' "${grub}"
|
|
grep -Fq 'set default="gnulinux-simple-9842d3d6-a839-4127-bda7-f19137effe71"' \
|
|
"${grub}"
|
|
if grep -Fq "save_env --file '(hd0)68+2' guanghu_recovery" "${grub}"; then
|
|
echo "GRUB must not write the raw GHNRP blocklist" >&2
|
|
exit 1
|
|
fi
|
|
|
|
python3 - "${active}" "${clear}" <<'PY'
|
|
import pathlib
|
|
import sys
|
|
|
|
header = (
|
|
b"# GRUB Environment Block\n"
|
|
b"# WARNING: Do not edit this file by tools other than grub-editenv!!!\n"
|
|
)
|
|
active = pathlib.Path(sys.argv[1]).read_bytes()
|
|
clear = pathlib.Path(sys.argv[2]).read_bytes()
|
|
assert active.startswith(header + b"guanghu_recovery=ubuntu\n")
|
|
assert clear.startswith(header)
|
|
assert active.rstrip(b"#").endswith(b"guanghu_recovery=ubuntu\n")
|
|
assert clear[len(header):] == b"#" * (1024 - len(header))
|
|
PY
|
|
|
|
disk=${test_root}/recovery-layout.img
|
|
truncate -s $((70 * 512)) "${disk}"
|
|
dd if="${active}" of="${disk}" bs=512 seek=68 count=2 conv=notrunc status=none
|
|
cmp "${active}" <(dd if="${disk}" bs=512 skip=68 count=2 status=none)
|
|
"${source_root}/scripts/clear-native-recovery-beacon.sh" "${disk}" "${clear}"
|
|
cmp "${clear}" <(dd if="${disk}" bs=512 skip=68 count=2 status=none)
|
|
|
|
grep -q '^%define NATIVE_RECOVERY_BEACON_LBA 68$' \
|
|
"${source_root}/native/x86_64-bios/ghal-virtio.asm"
|
|
grep -q 'db "guanghu_recovery=ubuntu", 10' \
|
|
"${source_root}/native/x86_64-bios/ghal-virtio.asm"
|
|
|
|
echo "GUANGHU_NATIVE_RECOVERY_BEACON_CONTRACT_OK"
|