#!/usr/bin/env bash set -Eeuo pipefail [[ $# == 1 && $1 =~ ^[0-9a-f]{40}$ ]] || { echo 'usage: set-jd-guanghu-master-default.sh ' >&2; exit 64; } source_commit=$1 readonly instance_id=f3d4b730-7f02-452f-975b-7091a4800431 readonly linux_entry=gnulinux-simple-9e4550a0-452b-4f28-b5a5-d5364aa450f6 readonly master_entry=guanghu-jd-master-20260816 readonly receipt_root=/guanghu/recovery/JD-FD-PRIMARY-master-20260816 readonly subcontrol=/usr/local/sbin/guanghu-linux-subcontrol [[ $(tr A-F a-f "$subcontrol" <<'EOF' #!/bin/bash set -Eeuo pipefail readonly linux_entry=gnulinux-simple-9e4550a0-452b-4f28-b5a5-d5364aa450f6 readonly master_entry=guanghu-jd-master-20260816 readonly receipt_root=/guanghu/recovery/JD-FD-PRIMARY-master-20260816 case ${1:-status} in status) printf 'pid1=%s\n' "$(tr '\0' ' ' "$receipt_root/LINUX-SUBCONTROL-REQUEST.hldp" chmod 0600 "$receipt_root/LINUX-SUBCONTROL-REQUEST.hldp" sync systemctl --force --force reboot ;; return-to-master) [[ $(tr '\0' ' ' &2; exit 64 ;; esac EOF chmod 0755 "$subcontrol" update-grub >/dev/null grub-editenv /boot/grub/grubenv unset next_entry grep -Eq "^GRUB_DEFAULT=${master_entry}$" /etc/default/grub grep -Fq "'${master_entry}'" /boot/grub/grub.cfg grep -Fq "$linux_entry" /boot/grub/grub.cfg "$subcontrol" status cat >"$receipt_root/DEFAULT-CUTOVER-ARMED-RECEIPT.hldp" <"$receipt_root/DEFAULT-CUTOVER-ARMED-RECEIPT.hldp.sha256" sync echo GUANGHU_MASTER_DEFAULT_ARMED linux_subcontrol=ONE_TIME linux_rescue=PRESERVED