Align the China region to the official cn profile

The region value is cn, the China files live under default/regions/cn/, and
omarchy-apply-pacman renders pacman for every caller: the .cn twins of the
channel servers first, then .org, USTC and ArchLinuxCN. Switching to China
installs and trusts the ArchLinuxCN keyring. A migration renames china to cn
and repoints the drop-in links.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-07 11:33:01 -04:00
1 parent d2e4a95aed
commit 9a57690e7d
20 files changed
+119 -99

No files matched your search

+1 -1
View File
@@ -302,7 +302,7 @@ assert(
regionEntries.map(item => item.label).join('\0') === 'Global\0China'
&& regionEntries.every(item => item.checked.includes(`== \"${item.label}\"`) && !item.when)
&& defaultById['setup.region.global'].action.includes('omarchy-region global')
&& defaultById['setup.region.china'].action.includes('omarchy-region china'),
&& defaultById['setup.region.china'].action.includes('omarchy-region cn'),
'menu offers Global and China under Setup > Region'
)
// Software you already have keeps its place in Install, dimmed rather than
+5 -4
View File
@@ -32,18 +32,19 @@ for channel in stable rc edge; do
edge) host=mirror.omarchy.org ;;
esac
apply "$channel"
expected=$(printf 'Server = https://%s/$repo/os/$arch\nServer = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' "$host")
expected=$(printf 'Server = https://%s/$repo/os/$arch\nServer = https://%s/$repo/os/$arch\nServer = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' "${host%.org}.cn" "$host")
[[ $(<"$TARGET_ROOT/etc/pacman.d/mirrorlist") == "$expected" ]] || fail "$channel mirror order and variables"
{
cat "$ROOT/default/pacman/pacman-$channel.conf"
sed -f "$ROOT/default/regions/cn/pacman/servers.sed" "$ROOT/default/pacman/pacman-$channel.conf"
printf '\n[archlinuxcn]\nServer = https://mirrors.ustc.edu.cn/archlinuxcn/$arch\n'
} > "$scratch/expected.conf"
grep -qx "Server = https://pkgs.omarchy.cn/$channel/\$arch" "$scratch/expected.conf" || fail "$channel lists the .cn Omarchy repository"
cmp "$scratch/expected.conf" "$TARGET_ROOT/etc/pacman.conf"
apply "$channel"
cmp "$TARGET_ROOT/etc/pacman.conf.bak" "$TARGET_ROOT/etc/pacman.conf"
cmp "$TARGET_ROOT/etc/pacman.d/mirrorlist.bak" "$TARGET_ROOT/etc/pacman.d/mirrorlist"
done
pass "China keeps each channel first, appends only CN defaults, and is idempotent"
pass "China puts a .cn twin ahead of each channel server, appends the CN defaults, and is idempotent"
cp "$TARGET_ROOT/etc/pacman.conf" "$scratch/before.conf"
cp "$TARGET_ROOT/etc/pacman.d/mirrorlist" "$scratch/before.mirrors"
@@ -75,7 +76,7 @@ mkdir -p "$scratch/rendered"
"$ROOT/bin/omarchy-apply-pacman" --render rc "$scratch/rendered" "$TARGET_ROOT"
rg -qxF 'Server = https://pkgs.omarchy.org/rc/$arch' "$scratch/rendered/pacman.conf"
rg -qxF '[archlinuxcn]' "$scratch/rendered/pacman.conf"
[[ $(<"$scratch/rendered/mirrorlist") == $'Server = https://rc-mirror.omarchy.org/$repo/os/$arch\nServer = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' ]] ||
[[ $(<"$scratch/rendered/mirrorlist") == $'Server = https://rc-mirror.omarchy.cn/$repo/os/$arch\nServer = https://rc-mirror.omarchy.org/$repo/os/$arch\nServer = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' ]] ||
fail "render keeps the channel mirror first"
cmp "$scratch/before.conf" "$TARGET_ROOT/etc/pacman.conf"
pass "render builds the regional channel files without touching the target"
+29 -38
View File
@@ -8,77 +8,68 @@ test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
root="$test_tmp/root" sandbox="$test_tmp/omarchy" calls="$test_tmp/calls"
mkdir -p "$root/etc/pacman.d" "$sandbox/bin" "$sandbox/install/config" "$sandbox/default/region" "$test_tmp/bin" "$test_tmp/home"
cp -r "$ROOT/default/region/china" "$sandbox/default/region/"
mkdir -p "$root/etc/pacman.d" "$sandbox/bin" "$sandbox/install/config" "$sandbox/default/regions" "$test_tmp/bin" "$test_tmp/home"
cp -r "$ROOT/default/regions/cn" "$sandbox/default/regions/"
rewrite() { sed -e "s|/etc/|$root/etc/|g" -e "s| /\\.cargo/| $root/.cargo/|g" "$1" >"$2"; chmod +x "$2"; }
rewrite "$ROOT/install/config/region.sh" "$sandbox/install/config/region.sh"
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 omarchy-system-logout; do
for command in omarchy-update-pacman omarchy-refresh-pacman locale-gen rime-ice-installer omarchy-setup-claude-api systemctl omarchy-system-logout pacman-key; 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\necho "${STUB_CHANNEL:-stable}"\n' >"$test_tmp/bin/omarchy-version-channel"
printf '#!/bin/bash\n[[ $1 == env ]] && shift\nexec env "$@"\n' >"$test_tmp/bin/sudo"
printf '#!/bin/bash\necho "gum $*" >>"%s"\nexit "${GUM_ANSWER:-1}"\n' "$calls" >"$test_tmp/bin/gum"
chmod +x "$test_tmp/bin"/*
export PATH="$test_tmp/bin:$sandbox/bin:$PATH" OMARCHY_PATH="$sandbox" HOME="$test_tmp/home"
cp "$ROOT/default/pacman/pacman-stable.conf" "$root/etc/pacman.conf"
cp "$ROOT/default/pacman/mirrorlist-stable" "$root/etc/pacman.d/mirrorlist"
printf '#zh_CN.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\n' >"$root/etc/locale.gen"
printf 'LANG=en_US.UTF-8\n' >"$root/etc/locale.conf"
china_conf=$(sed -f "$ROOT/default/region/china/pacman.sed" "$ROOT/default/pacman/pacman-stable.conf")
china_mirrors=$(sed -f "$ROOT/default/region/china/pacman.sed" "$ROOT/default/pacman/mirrorlist-stable")
omarchy-region china >/dev/null
[[ $(<"$root/etc/pacman.conf") == "$china_conf" && $(<"$root/etc/pacman.d/mirrorlist") == "$china_mirrors" ]] ||
fail "switching to China lists the .cn mirrors first"
[[ $(omarchy-region) == "China" && $(<"$root/etc/locale.conf") == "LANG=zh_CN.UTF-8" ]] || fail "switching to China records it and sets the language"
[[ $(<"$calls") == $'omarchy-update-pacman -Syu --noconfirm\nomarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer\nlocale-gen \nsystemctl --user try-restart omarchy-fcitx5.service\nrime-ice-installer --yes' ]] ||
fail "China upgrades in full before installing Rime, then sets Rime Ice up" "$(<"$calls")"
pass "switching to China sets mirrors, language and Rime Ice"
omarchy-region cn >/dev/null
[[ $(omarchy-region) == "China" && $(<"$root/etc/omarchy/region") == "cn" && $(<"$root/etc/locale.conf") == "LANG=zh_CN.UTF-8" ]] ||
fail "switching to China records cn and sets the language"
[[ $(<"$calls") == $'omarchy-update-pacman -Syu --noconfirm\nomarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer\nlocale-gen \nomarchy-refresh-pacman stable\nomarchy-pkg-add archlinuxcn-keyring\npacman-key --populate archlinuxcn\nsystemctl --user try-restart omarchy-fcitx5.service\nrime-ice-installer --yes' ]] ||
fail "China installs Rime against current packages, refreshes pacman into the cn profile, then trusts ArchLinuxCN and sets Rime Ice up" "$(<"$calls")"
pass "switching to China installs Rime, renders the cn profile on the current channel and trusts ArchLinuxCN"
: >"$calls"
mkdir -p "$HOME/.local/share/fcitx5/rime" && touch "$HOME/.local/share/fcitx5/rime/rime_ice.schema.yaml"
omarchy-region china >/dev/null
[[ $(<"$root/etc/pacman.conf") == "$china_conf" && $(<"$root/etc/pacman.d/mirrorlist") == "$china_mirrors" ]] ||
fail "switching to China twice adds no second .cn line"
STUB_CHANNEL=edge omarchy-region cn >/dev/null
grep -qx 'omarchy-refresh-pacman edge' "$calls" || fail "the refresh keeps the machine's channel" "$(<"$calls")"
grep -q '^rime-ice-installer\|^systemctl' "$calls" && fail "an existing Rime Ice setup is not redone"
pass "switching to China again changes nothing it already did"
printf 'Server = https://stable-mirror.omarchy.cn/$repo/os/$arch\nServer = https://stable-mirror.omarchy.org/$repo/os/$arch\nServer = https://mirror.omarchy.org/$repo/os/$arch\n' >"$root/etc/pacman.d/mirrorlist"
omarchy-region china >/dev/null
[[ $(<"$root/etc/pacman.d/mirrorlist") == $'Server = https://stable-mirror.omarchy.cn/$repo/os/$arch\nServer = https://stable-mirror.omarchy.org/$repo/os/$arch\nServer = https://mirror.omarchy.cn/$repo/os/$arch\nServer = https://mirror.omarchy.org/$repo/os/$arch' ]] ||
fail "a partly switched mirrorlist gets every missing .cn twin" "$(<"$root/etc/pacman.d/mirrorlist")"
cp "$ROOT/default/pacman/mirrorlist-stable" "$root/etc/pacman.d/mirrorlist"
sed -i -f "$ROOT/default/region/china/pacman.sed" "$root/etc/pacman.d/mirrorlist"
pass "every .org server ends up with exactly one .cn twin in front"
pass "switching to China again keeps the channel and redoes no Rime Ice setup"
: >"$calls"
omarchy-region global >/dev/null
[[ $(<"$root/etc/pacman.conf") == "$(<"$ROOT/default/pacman/pacman-stable.conf")" && $(<"$root/etc/pacman.d/mirrorlist") == "$(<"$ROOT/default/pacman/mirrorlist-stable")" ]] ||
fail "switching to Global drops exactly the .cn mirrors"
[[ $(omarchy-region) == "Global" && $(<"$root/etc/locale.conf") == "LANG=en_US.UTF-8" ]] || fail "switching to Global records it and restores English"
[[ $(<"$calls") == "omarchy-setup-claude-api --remove" ]] || fail "Global removes the Claude Code third-party API and keeps Rime" "$(<"$calls")"
[[ $(omarchy-region) == "Global" && ! -e $root/etc/omarchy/region && $(<"$root/etc/locale.conf") == "LANG=en_US.UTF-8" ]] ||
fail "switching to Global removes the region and restores English"
[[ $(<"$calls") == $'omarchy-refresh-pacman stable\nomarchy-setup-claude-api --remove' ]] ||
fail "Global refreshes pacman back to the channel defaults and removes the Claude API setup" "$(<"$calls")"
[[ -f $HOME/.local/share/fcitx5/rime/rime_ice.schema.yaml ]] || fail "Global keeps the input method"
pass "switching to Global restores mirrors and language, keeps Rime, removes the Claude API setup"
pass "switching to Global restores the channel's pacman defaults and English, keeps Rime, removes the Claude API setup"
if output=$(omarchy-region mars 2>&1); then
fail "an unknown region is refused" "$output"
fi
pass "an unknown region is refused"
if output=$(STUB_CHANNEL="stable / edge" omarchy-region cn 2>&1); then
fail "a mixed channel is refused" "$output"
fi
[[ $(omarchy-region) == "Global" ]] || fail "a refused switch changes nothing"
pass "an unknown region or an unclear channel is refused"
if output=$(STUB_PKG_FAIL=1 omarchy-region china 2>&1); then
: >"$calls"
if output=$(STUB_PKG_FAIL=1 omarchy-region cn 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"
[[ $(omarchy-region) == "Global" ]] && ! grep -q '^omarchy-refresh-pacman' "$calls" ||
fail "a failed switch to China leaves the region Global and pacman untouched" "$(<"$calls")"
pass "a failed switch to China leaves the machine Global"
grep -q '^gum' "$calls" && fail "a switch without a terminal asks nothing" "$(<"$calls")"
: >"$calls"
output=$(GUM_ANSWER=1 script -qec "omarchy-region china" /dev/null)
output=$(GUM_ANSWER=1 script -qec "omarchy-region cn" /dev/null)
grep -qxF 'gum confirm --affirmative 立即注销 --negative 稍后 立即注销,切换到中文界面和国内镜像?' "$calls" ||
fail "switching to China offers to log out, in Chinese" "$(<"$calls")"
[[ $output == *"区域已设为中国。重新登录后切换到中文界面和国内镜像。"* ]] && ! grep -q '^omarchy-system-logout' "$calls" ||
@@ -93,7 +84,7 @@ rc_migration="$test_tmp/1788112314.sh"
rewrite "$ROOT/migrations/1788112314.sh" "$rc_migration"
cp "$ROOT/default/pacman/mirrorlist-rc" "$root/etc/pacman.d/mirrorlist"
sed -e 's|pkgs.omarchy.org/rc/|pkgs.omarchy.org/edge/|' "$ROOT/default/pacman/pacman-rc.conf" |
sed -f "$ROOT/default/region/china/pacman.sed" >"$root/etc/pacman.conf"
sed -f "$ROOT/default/regions/cn/pacman/servers.sed" >"$root/etc/pacman.conf"
bash -e "$rc_migration" >/dev/null
[[ $(grep '^Server' "$root/etc/pacman.conf") == $'Server = https://pkgs.omarchy.cn/rc/$arch\nServer = https://pkgs.omarchy.org/rc/$arch' ]] ||
fail "the rc repository migration moves the .cn twin with its .org server" "$(grep '^Server' "$root/etc/pacman.conf")"
+10 -10
View File
@@ -7,7 +7,7 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
china_sed="$ROOT/default/region/china/pacman.sed"
china_sed="$ROOT/default/regions/cn/pacman/servers.sed"
expected_stable_omarchy='Server = https://pkgs.omarchy.cn/stable/$arch
Server = https://pkgs.omarchy.org/stable/$arch'
@@ -44,9 +44,9 @@ chmod +x "$region_bin"
[[ $("$region_bin") == "Global" ]] || fail "no region file reads as Global"
pass "no region file reads as Global"
echo china >"$region_file"
[[ $("$region_bin") == "China" ]] || fail "china region file reads as China"
pass "china region file reads as China"
echo cn >"$region_file"
[[ $("$region_bin") == "China" ]] || fail "cn region file reads as China"
pass "cn region file reads as China"
echo mars >"$region_file"
if output=$("$region_bin" 2>&1); then
@@ -75,8 +75,8 @@ printf '#zh_CN.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\n' >"$root/etc/locale.gen"
printf 'LANG=en_US.UTF-8\nLC_TIME=en_DK.UTF-8\n' >"$root/etc/locale.conf"
: >"$calls"
OMARCHY_REGION=china bash -e "$region_setup"
[[ $(<"$root/etc/omarchy/region") == "china" ]] || fail "install records the China region"
OMARCHY_REGION=cn bash -e "$region_setup"
[[ $(<"$root/etc/omarchy/region") == "cn" ]] || fail "install records the China region as cn"
[[ $(<"$calls") == $'omarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer\nlocale-gen ' ]] ||
fail "China installs the Rime input method packages and generates the Chinese locale" "$(<"$calls")"
[[ $(<"$root/etc/locale.gen") == $'zh_CN.UTF-8 UTF-8\nen_US.UTF-8 UTF-8' ]] || fail "China enables zh_CN in locale.gen"
@@ -88,7 +88,7 @@ pass "install records the China region and installs the Rime packages the ISO ca
for link in "environment.conf etc/environment.d/90-omarchy-china.conf" "cargo.toml .cargo/config.toml" "gemrc etc/gemrc"; do
read -r source target <<<"$link"
[[ $(readlink "$root/$target") == "$ROOT/default/region/china/$source" ]] || fail "China links /$target to the shipped $source"
[[ $(readlink "$root/$target") == "$ROOT/default/regions/cn/$source" ]] || fail "China links /$target to the shipped $source"
done
pass "China links the developer mirror drop-ins"
@@ -111,7 +111,7 @@ OMARCHY_REGION=global bash -e "$region_setup"
[[ -L $root/etc/gemrc ]] || fail "Global keeps a gemrc link Omarchy did not create"
rm "$root/etc/gemrc"
echo ":sources: []" >"$root/etc/gemrc"
if output=$(OMARCHY_REGION=china bash -e "$region_setup" 2>&1); then
if output=$(OMARCHY_REGION=cn bash -e "$region_setup" 2>&1); then
fail "China refuses to replace an admin's /etc/gemrc" "$output"
fi
[[ $output == "Refusing to replace $root/etc/gemrc, which Omarchy did not create" && $(<"$root/etc/gemrc") == ":sources: []" ]] ||
@@ -120,13 +120,13 @@ fi
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
if output=$(STUB_PKG_FAIL=1 OMARCHY_REGION=cn 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"
OMARCHY_REGION=cn 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"
pass "Global and an unset region leave no region file"
+5 -5
View File
@@ -130,10 +130,10 @@ pass "the form publishes the 0/1/130 status contract and leads with English (US)
run_prompt omarchy_prompt_region "0:China"
assert_status 0 "region prompt succeeds"
[[ $(field region) == "china" ]] || fail "region prompt stores China as china"
[[ $(field region) == "cn" ]] || fail "region prompt stores China as cn"
[[ $(<"$tmp_dir/stdin.1") == $'Global\nChina' ]] || fail "region prompt offers Global then China"
grep -qxF -- 'choose --selected Global --header Select region' "$GUM_ARGS" || fail "region prompt preselects Global on a fresh form"
REGION=china run_prompt omarchy_prompt_region "0:Global"
REGION=cn run_prompt omarchy_prompt_region "0:Global"
[[ $(field region) == "global" ]] || fail "region prompt stores Global as global"
grep -qxF -- 'choose --selected China --header Select region' "$GUM_ARGS" || fail "region prompt preselects the region chosen on an earlier visit"
pass "region prompt maps Global and China and preselects the current region"
@@ -149,13 +149,13 @@ pass "region prompt propagates Esc and Ctrl+C without dying under set -e"
OMARCHY_CJK_CONSOLE=1 run_prompt omarchy_prompt_region "0:China 中国"
assert_status 0 "region prompt succeeds in a CJK console"
[[ $(field region) == "china" ]] || fail "region prompt stores China 中国 as china"
[[ $(field region) == "cn" ]] || fail "region prompt stores China 中国 as cn"
[[ $(<"$tmp_dir/stdin.1") == $'Global\nChina 中国' ]] || fail "a CJK console offers the Chinese name"
grep -qxF -- 'choose --selected Global --header Select region · 选择区域' "$GUM_ARGS" || fail "a CJK console asks in both languages"
OMARCHY_CJK_CONSOLE=1 REGION=china run_prompt omarchy_prompt_region "0:Global"
OMARCHY_CJK_CONSOLE=1 REGION=cn run_prompt omarchy_prompt_region "0:Global"
[[ $(field region) == "global" ]] || fail "region prompt stores Global as global in a CJK console"
grep -qxF -- 'choose --selected China 中国 --header Select region · 选择区域' "$GUM_ARGS" || fail "a CJK console preselects China by its shown name"
pass "a CJK console names China in Chinese and maps it back to china"
pass "a CJK console names China in Chinese and maps it back to cn"
# Keyboard