Parameterize the raw recovery beacon, add one-time JD resident preparation and return verification, and provide an external ICMP peer for HLDP login, code, branch, and recovery commands.
55 lines
1.5 KiB
Shell
Executable file
55 lines
1.5 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
[[ $# -ge 1 && $# -le 3 ]] || {
|
|
echo "usage: render-native-recovery-beacon.sh <output-directory> [beacon-lba] [hosted-entry-id]" >&2
|
|
exit 64
|
|
}
|
|
|
|
mkdir -p "$1"
|
|
output_root=$(cd "$1" && pwd)
|
|
beacon_lba=${2:-68}
|
|
hosted_entry_id=${3:-gnulinux-simple-9842d3d6-a839-4127-bda7-f19137effe71}
|
|
[[ ${beacon_lba} =~ ^[0-9]+$ ]]
|
|
[[ ${hosted_entry_id} =~ ^[A-Za-z0-9._-]+$ ]]
|
|
|
|
python3 - "${output_root}" <<'PY'
|
|
import pathlib
|
|
import sys
|
|
|
|
output = pathlib.Path(sys.argv[1])
|
|
header = (
|
|
b"# GRUB Environment Block\n"
|
|
b"# WARNING: Do not edit this file by tools other than grub-editenv!!!\n"
|
|
)
|
|
|
|
def write_environment(name: str, variables: bytes = b"") -> None:
|
|
prefix = header + variables
|
|
if len(prefix) > 1024:
|
|
raise SystemExit(f"{name} exceeds the GRUB environment-block size")
|
|
(output / name).write_bytes(prefix + b"#" * (1024 - len(prefix)))
|
|
|
|
write_environment(
|
|
"guanghu-recovery-active.env",
|
|
b"guanghu_recovery=ubuntu\n",
|
|
)
|
|
write_environment("guanghu-recovery-clear.env")
|
|
PY
|
|
|
|
install -m 0755 /dev/stdin "${output_root}/08_guanghu_native_recovery" <<EOF
|
|
#!/bin/sh
|
|
exec tail -n +3 \$0
|
|
insmod loadenv
|
|
set guanghu_recovery=
|
|
if load_env --file '(hd0)${beacon_lba}+2' guanghu_recovery; then
|
|
if [ "\${guanghu_recovery}" = "ubuntu" ]; then
|
|
set default="${hosted_entry_id}"
|
|
fi
|
|
fi
|
|
EOF
|
|
|
|
sha256sum \
|
|
"${output_root}/guanghu-recovery-active.env" \
|
|
"${output_root}/guanghu-recovery-clear.env" \
|
|
"${output_root}/08_guanghu_native_recovery" \
|
|
>"${output_root}/SHA256SUMS"
|