From a3e40cb8b074fa30a094c56efa604da4dafdd96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Tue, 6 Oct 2026 21:13:37 -0400 Subject: [PATCH] Set up China before moving the mirrors so a failed switch leaves the machine Global --- bin/omarchy-region | 5 +++-- install/config/region.sh | 12 ++++++++---- test/shell.d/region-switch-test.sh | 8 ++++++++ test/shell.d/region-test.sh | 9 +++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bin/omarchy-region b/bin/omarchy-region index 67abb946..060297f9 100755 --- a/bin/omarchy-region +++ b/bin/omarchy-region @@ -30,10 +30,11 @@ pacman_files=(/etc/pacman.conf /etc/pacman.d/mirrorlist) drop_cn_servers='/^Server = https:\/\/[a-z-]*\.omarchy\.cn\//d' if [[ $1 == "china" ]]; then - sudo sed -i -e "$drop_cn_servers" -f "$OMARCHY_PATH/default/region/china/pacman.sed" "${pacman_files[@]}" - echo "Package mirrors -> .cn first, .org after" + # Mirrors move last, so a failed setup leaves the machine wholly Global. omarchy-update-pacman -Syu --noconfirm sudo env OMARCHY_REGION=china OMARCHY_PATH="$OMARCHY_PATH" bash -e "$OMARCHY_PATH/install/config/region.sh" + sudo sed -i -e "$drop_cn_servers" -f "$OMARCHY_PATH/default/region/china/pacman.sed" "${pacman_files[@]}" + echo "Package mirrors -> .cn first, .org after" if [[ ! -f $HOME/.local/share/fcitx5/rime/rime_ice.schema.yaml ]]; then # A running fcitx5 only sees the new Rime addon after a restart. systemctl --user try-restart omarchy-fcitx5.service diff --git a/install/config/region.sh b/install/config/region.sh index b5ddeb99..84e2e0f9 100644 --- a/install/config/region.sh +++ b/install/config/region.sh @@ -16,18 +16,22 @@ global) done ;; china) - mkdir -p /etc/omarchy - echo china >/etc/omarchy/region + # Packages first, so a failed install leaves the machine Global. + omarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer for link in "${china_links[@]}"; do - read -r source target <<<"$link" + read -r _ target <<<"$link" if [[ -e $target && ! -L $target ]]; then echo "Refusing to replace $target, which Omarchy did not create" >&2 exit 1 fi + done + mkdir -p /etc/omarchy + echo china >/etc/omarchy/region + for link in "${china_links[@]}"; do + read -r source target <<<"$link" mkdir -p "${target%/*}" ln -sfn "$OMARCHY_PATH/default/region/china/$source" "$target" done - omarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer sed -i 's/^#\(zh_CN\.UTF-8 UTF-8\)/\1/' /etc/locale.gen locale-gen if grep -q '^LANG=' /etc/locale.conf; then diff --git a/test/shell.d/region-switch-test.sh b/test/shell.d/region-switch-test.sh index 2450a795..fe65ee06 100755 --- a/test/shell.d/region-switch-test.sh +++ b/test/shell.d/region-switch-test.sh @@ -17,6 +17,7 @@ rewrite "$ROOT/bin/omarchy-region" "$sandbox/bin/omarchy-region" for command in omarchy-update-pacman omarchy-pkg-add locale-gen rime-ice-installer omarchy-setup-claude-api systemctl; do printf '#!/bin/bash\necho "%s $*" >>"%s"\n' "$command" "$calls" >"$test_tmp/bin/$command" done +printf '#!/bin/bash\necho "omarchy-pkg-add $*" >>"%s"\n[[ -z ${STUB_PKG_FAIL:-} ]]\n' "$calls" >"$test_tmp/bin/omarchy-pkg-add" printf '#!/bin/bash\n[[ $1 == env ]] && shift\nexec env "$@"\n' >"$test_tmp/bin/sudo" chmod +x "$test_tmp/bin"/* export PATH="$test_tmp/bin:$sandbox/bin:$PATH" OMARCHY_PATH="$sandbox" HOME="$test_tmp/home" @@ -67,6 +68,13 @@ if output=$(omarchy-region mars 2>&1); then fi pass "an unknown region is refused" +if output=$(STUB_PKG_FAIL=1 omarchy-region china 2>&1); then + fail "switching to China fails when its packages do not install" "$output" +fi +[[ $(omarchy-region) == "Global" && $(<"$root/etc/pacman.conf") == "$(<"$ROOT/default/pacman/pacman-stable.conf")" && $(<"$root/etc/pacman.d/mirrorlist") == "$(<"$ROOT/default/pacman/mirrorlist-stable")" ]] || + fail "a failed switch to China leaves the region and the mirrors Global" +pass "a failed switch to China leaves the machine Global" + rc_migration="$test_tmp/1788112314.sh" rewrite "$ROOT/migrations/1788112314.sh" "$rc_migration" cp "$ROOT/default/pacman/mirrorlist-rc" "$root/etc/pacman.d/mirrorlist" diff --git a/test/shell.d/region-test.sh b/test/shell.d/region-test.sh index 1b4f785f..12feb433 100755 --- a/test/shell.d/region-test.sh +++ b/test/shell.d/region-test.sh @@ -61,6 +61,7 @@ mkdir -p "$stub_bin" for command in omarchy-pkg-add rime-ice-installer locale-gen; do printf '#!/bin/bash\necho "%s $*" >>"%s"\n' "$command" "$calls" >"$stub_bin/$command" done +printf '#!/bin/bash\necho "omarchy-pkg-add $*" >>"%s"\n[[ -z ${STUB_PKG_FAIL:-} ]]\n' "$calls" >"$stub_bin/omarchy-pkg-add" printf '#!/bin/bash\necho "$STUB_REGION"\n' >"$stub_bin/omarchy-region" chmod +x "$stub_bin"/* PATH="$stub_bin:$PATH" @@ -115,8 +116,16 @@ if output=$(OMARCHY_REGION=china bash -e "$region_setup" 2>&1); then fi [[ $output == "Refusing to replace $root/etc/gemrc, which Omarchy did not create" && $(<"$root/etc/gemrc") == ":sources: []" ]] || fail "China names the file it refuses to replace and leaves it" "$output" +[[ ! -e $root/etc/omarchy/region ]] || fail "a refused China switch records no region" rm "$root/etc/gemrc" pass "region setup never touches mirror config Omarchy did not create" + +if output=$(STUB_PKG_FAIL=1 OMARCHY_REGION=china bash -e "$region_setup" 2>&1); then + fail "China fails when its packages do not install" "$output" +fi +[[ ! -e $root/etc/omarchy/region && ! -e $root/etc/gemrc && $(<"$root/etc/locale.conf") == "LANG=en_US.UTF-8" ]] || + fail "a failed package install leaves the machine Global" +pass "China installs its packages before it writes any region state" OMARCHY_REGION=china bash -e "$region_setup" env -u OMARCHY_REGION bash -e "$region_setup" [[ ! -e $root/etc/omarchy/region ]] || fail "an installer that passes no region installs Global"