#!/usr/bin/env bash set -euo pipefail [[ $# -eq 1 ]] || { echo "usage: render-native-recovery-beacon.sh " >&2 exit 64 } mkdir -p "$1" output_root=$(cd "$1" && pwd) 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)68+2' guanghu_recovery; then if [ "${guanghu_recovery}" = "ubuntu" ]; then set default="gnulinux-simple-9842d3d6-a839-4127-bda7-f19137effe71" 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"