diff --git a/default/region/china/cargo.toml b/default/region/china/cargo.toml new file mode 100644 index 00000000..5b56b114 --- /dev/null +++ b/default/region/china/cargo.toml @@ -0,0 +1,5 @@ +[source.crates-io] +replace-with = "aliyun" + +[source.aliyun] +registry = "sparse+https://mirrors.aliyun.com/crates.io-index/" diff --git a/default/region/china/environment.conf b/default/region/china/environment.conf new file mode 100644 index 00000000..2bb3dd16 --- /dev/null +++ b/default/region/china/environment.conf @@ -0,0 +1,8 @@ +NPM_CONFIG_REGISTRY=https://registry.npmmirror.com +PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ +UV_DEFAULT_INDEX=https://mirrors.aliyun.com/pypi/simple/ +GOPROXY=https://mirrors.aliyun.com/goproxy/,direct +RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup +RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup +BUNDLE_MIRROR__ALL=https://mirrors.aliyun.com/rubygems/ +MAVEN_ARGS=--global-settings /usr/share/omarchy/default/region/china/maven-settings.xml diff --git a/default/region/china/gemrc b/default/region/china/gemrc new file mode 100644 index 00000000..145984f2 --- /dev/null +++ b/default/region/china/gemrc @@ -0,0 +1,3 @@ +--- +:sources: +- https://mirrors.aliyun.com/rubygems/ diff --git a/default/region/china/maven-settings.xml b/default/region/china/maven-settings.xml new file mode 100644 index 00000000..5066b6bd --- /dev/null +++ b/default/region/china/maven-settings.xml @@ -0,0 +1,9 @@ + + + + aliyun + central + https://maven.aliyun.com/repository/public + + + diff --git a/install/config/region.sh b/install/config/region.sh index 4ed4bc62..65bfefec 100644 --- a/install/config/region.sh +++ b/install/config/region.sh @@ -1,10 +1,31 @@ +china_links=( + "environment.conf /etc/environment.d/90-omarchy-china.conf" + "cargo.toml /.cargo/config.toml" + "gemrc /etc/gemrc" +) + case ${OMARCHY_REGION:-global} in global) rm -f /etc/omarchy/region + for link in "${china_links[@]}"; do + read -r _ target <<<"$link" + if [[ -L $target && $(readlink "$target") == */default/region/china/* ]]; then + rm "$target" + fi + done ;; china) mkdir -p /etc/omarchy echo china >/etc/omarchy/region + for link in "${china_links[@]}"; do + read -r source target <<<"$link" + if [[ -e $target && ! -L $target ]]; then + echo "Refusing to replace $target, which Omarchy did not create" >&2 + exit 1 + fi + 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 ;; *) diff --git a/plans/omarchycn.md b/plans/omarchycn.md index 11594ca2..c26fc834 100644 --- a/plans/omarchycn.md +++ b/plans/omarchycn.md @@ -18,7 +18,7 @@ Progress source of truth for the `omarchycn` branches of `omarchy`, `omarchy-iso - [x] T2 Region choice in the installer (PRD 2): `omarchy_prompt_region` in `setup-form.sh`, ISO configurator screen, orchestrator passes `OMARCHY_REGION`, `install/config/region.sh` records it - [x] T3 Input method (PRD 3): rime-ice-installer patch and PKGBUILD in omarchy-pkgs, IME packages in `omarchy-other.packages`, install-time package add, user step runs the installer from bundled assets, ISO build bundles assets and the package - [x] T4 CJK fontconfig fix (PRD 4): rebuild PR 9693 on the current base -- [ ] T5 AI (PRD 5): Dim and Kimi Code for every region (rebuild PR 9694), Claude Code third-party provider setup shown only in China +- [x] T5 AI (PRD 5): Dim and Kimi Code for every region (rebuild PR 9694), Claude Code third-party provider setup shown only in China - [ ] T6 Developer mirrors (PRD 6): npm, PyPI/uv, Go, rustup, crates.io, RubyGems, Maven via system drop-ins under `default/region/china/` - [ ] T7 China software (PRD 7): Install menu entry shown only in China - [ ] T8 Region switching and Chinese UI (PRD 8): `omarchy-region china|global`, Setup > Region, locale, Chinese menu overlay chosen by `LANG` diff --git a/test/shell.d/region-test.sh b/test/shell.d/region-test.sh index ed6e58e3..e251ae94 100755 --- a/test/shell.d/region-test.sh +++ b/test/shell.d/region-test.sh @@ -66,11 +66,13 @@ chmod +x "$stub_bin"/* PATH="$stub_bin:$PATH" region_setup="$test_tmp/region.sh" -sed "s|/etc/omarchy|$test_tmp/etc-omarchy|g" "$ROOT/install/config/region.sh" >"$region_setup" +root="$test_tmp/root" +sed -e "s|/etc/|$root/etc/|g" -e "s| /\.cargo/| $root/.cargo/|g" "$ROOT/install/config/region.sh" >"$region_setup" +export OMARCHY_PATH="$ROOT" : >"$calls" OMARCHY_REGION=china bash -e "$region_setup" -[[ $(<"$test_tmp/etc-omarchy/region") == "china" ]] || fail "install records the China region" +[[ $(<"$root/etc/omarchy/region") == "china" ]] || fail "install records the China region" [[ $(<"$calls") == "omarchy-pkg-add fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer" ]] || fail "China installs the Rime input method packages" "$(<"$calls")" for package in fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer; do @@ -78,13 +80,35 @@ for package in fcitx5-configtool fcitx5-rime librime opencc rime-ice-installer; done pass "install records the China region and installs the Rime packages the ISO carries" +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" +done +pass "China links the developer mirror drop-ins" + : >"$calls" OMARCHY_REGION=global bash -e "$region_setup" -[[ ! -e $test_tmp/etc-omarchy/region ]] || fail "install records Global by leaving no region file" +[[ ! -e $root/etc/omarchy/region ]] || fail "install records Global by leaving no region file" [[ ! -s $calls ]] || fail "Global installs no input method packages" "$(<"$calls")" +[[ ! -e $root/etc/environment.d/90-omarchy-china.conf && ! -e $root/.cargo/config.toml && ! -e $root/etc/gemrc ]] || + fail "Global removes the developer mirror drop-ins" +pass "Global removes the developer mirror drop-ins" + +ln -s /usr/share/somewhere/gemrc "$root/etc/gemrc" +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 + 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: []" ]] || + fail "China names the file it refuses to replace and leaves it" "$output" +rm "$root/etc/gemrc" +pass "region setup never touches mirror config Omarchy did not create" OMARCHY_REGION=china bash -e "$region_setup" env -u OMARCHY_REGION bash -e "$region_setup" -[[ ! -e $test_tmp/etc-omarchy/region ]] || fail "an installer that passes no region installs Global" +[[ ! -e $root/etc/omarchy/region ]] || fail "an installer that passes no region installs Global" pass "Global and an unset region leave no region file" if output=$(OMARCHY_REGION=mars bash -e "$region_setup" 2>&1); then