diff --git a/product-source/hololake-platform/guanghu-os/scripts/replace-jd-native-final-resident-candidate.sh b/product-source/hololake-platform/guanghu-os/scripts/replace-jd-native-final-resident-candidate.sh index eb82a8a..4019983 100755 --- a/product-source/hololake-platform/guanghu-os/scripts/replace-jd-native-final-resident-candidate.sh +++ b/product-source/hololake-platform/guanghu-os/scripts/replace-jd-native-final-resident-candidate.sh @@ -43,8 +43,21 @@ dd if=/dev/vda bs=512 skip=141 count=1 status=none | grep -aq '^GHOS_GHCIP_INDEX_V1' dd if=/dev/vda bs=512 skip=142 count=1 status=none | grep -aq '^GHOS_GHCIP_ROOT_V1' -grep -q '^GRUB_DEFAULT=guanghu-jd-native-once$' /etc/default/grub -grep -q 'set default="guanghu-jd-native-once"' /boot/grub/grub.cfg +grub_default=$(awk -F= '$1 == "GRUB_DEFAULT" { print $2; found = 1 } END { if (!found) exit 1 }' \ + /etc/default/grub) +case "${grub_default}" in + guanghu-jd-native-once) + grep -q 'set default="guanghu-jd-native-once"' /boot/grub/grub.cfg + ;; + gnulinux-simple-9e4550a0-452b-4f28-b5a5-d5364aa450f6) + grep -q 'set default="gnulinux-simple-9e4550a0-452b-4f28-b5a5-d5364aa450f6"' \ + /boot/grub/grub.cfg + ;; + *) + echo "unsupported GRUB_DEFAULT for bounded native candidate replacement: ${grub_default}" >&2 + exit 65 + ;; +esac mkdir -m 0700 "${recovery_root}" printf '%s\n' "${partition_dump}" >"${recovery_root}/sfdisk-before.txt" @@ -85,7 +98,7 @@ preserved: world_and_code_store_lba_135_138: true recovery_beacon_lba_139_140: true gestational_index_lba_141_142: true - grub_default_native: true + grub_default_unchanged: ${grub_default} rollback: recovery_root: ${recovery_root} first_and_last_2mib_backed_up: true diff --git a/product-source/hololake-platform/guanghu-os/scripts/test-jd-final-candidate-replacement-contract.sh b/product-source/hololake-platform/guanghu-os/scripts/test-jd-final-candidate-replacement-contract.sh new file mode 100755 index 0000000..2bc43f2 --- /dev/null +++ b/product-source/hololake-platform/guanghu-os/scripts/test-jd-final-candidate-replacement-contract.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +[[ $# -eq 1 ]] || { + echo "usage: test-jd-final-candidate-replacement-contract.sh " >&2 + exit 64 +} + +source_root=$(cd "$1" && pwd -P) +script="${source_root}/scripts/replace-jd-native-final-resident-candidate.sh" + +grep -Fq 'guanghu-jd-native-once)' "${script}" +grep -Fq 'gnulinux-simple-9e4550a0-452b-4f28-b5a5-d5364aa450f6)' "${script}" +grep -Fq 'unsupported GRUB_DEFAULT for bounded native candidate replacement' "${script}" +grep -Fq 'grub_default_unchanged: ${grub_default}' "${script}" +! grep -Fq 'grub_default_native: true' "${script}" + +echo "JD_FINAL_CANDIDATE_REPLACEMENT_CONTRACT_OK"