Set up China before moving the mirrors so a failed switch leaves the machine Global

This commit is contained in:
ZacharyZhang-NY committed 2026-10-06 21:13:37 -04:00
1 parent 09da70c303
commit a3e40cb8b0
4 files changed
+28 -6

No files matched your search

+3 -2
View File
@@ -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
+8 -4
View File
@@ -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
+8
View File
@@ -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"
+9
View File
@@ -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"