#!/usr/bin/env bash set -Eeuo pipefail [[ $# == 2 ]] || { echo 'usage: install-jd-guanghu-master-candidate.sh ' >&2; exit 64; } source_file=$(readlink -f "$1") source_commit=$2 readonly node_id=JD-FD-PRIMARY readonly instance_id=f3d4b730-7f02-452f-975b-7091a4800431 readonly root_uuid=9e4550a0-452b-4f28-b5a5-d5364aa450f6 readonly linux_entry=gnulinux-simple-9e4550a0-452b-4f28-b5a5-d5364aa450f6 readonly master_entry=guanghu-jd-master-20260816 readonly install_path=/usr/local/libexec/guanghu/guanghu-master-init readonly grub_source=/etc/grub.d/42_guanghu_master readonly receipt_root=/guanghu/recovery/JD-FD-PRIMARY-master-20260816 [[ $source_commit =~ ^[0-9a-f]{40}$ ]] [[ -f $source_file && ! -L $source_file ]] bash -n "$source_file" [[ $(tr A-F a-f "$grub_source" </dev/null grep -Fq "'${master_entry}'" /boot/grub/grub.cfg grep -Fq "guanghu.master=1 init=${install_path}" /boot/grub/grub.cfg grep -Eq "^GRUB_DEFAULT=${linux_entry}$" /etc/default/grub "$install_path" preflight installed_sha=$(sha256sum "$install_path" | awk '{print $1}') source_sha=$(sha256sum "$source_file" | awk '{print $1}') [[ $installed_sha == "$source_sha" ]] boot_id=$(cat /proc/sys/kernel/random/boot_id) cat >"$receipt_root/CANDIDATE-INSTALL-RECEIPT.hldp" <"$receipt_root/CANDIDATE-INSTALL-RECEIPT.hldp.sha256" sync printf 'GUANGHU_MASTER_CANDIDATE_INSTALLED entry=%s sha256=%s default=%s\n' "$master_entry" "$installed_sha" "$linux_entry"