#!/usr/bin/env bash set -euo pipefail [[ $# -ge 1 && $# -le 3 ]] || { echo "usage: render-native-recovery-beacon.sh [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" <"${output_root}/SHA256SUMS"