diff --git a/install/config/all.sh b/install/config/all.sh index a221a398..3b5655a9 100644 --- a/install/config/all.sh +++ b/install/config/all.sh @@ -1,3 +1,4 @@ +run_logged "$OMARCHY_INSTALL/config/region.sh" run_logged "$OMARCHY_INSTALL/config/theme-system.sh" run_logged "$OMARCHY_INSTALL/config/browser-policy.sh" run_logged "$OMARCHY_INSTALL/config/increase-lockout-limit.sh" diff --git a/install/config/region.sh b/install/config/region.sh new file mode 100644 index 00000000..deec32e9 --- /dev/null +++ b/install/config/region.sh @@ -0,0 +1,13 @@ +case ${OMARCHY_REGION:-global} in +global) + rm -f /etc/omarchy/region + ;; +china) + mkdir -p /etc/omarchy + echo china >/etc/omarchy/region + ;; +*) + echo "Unknown OMARCHY_REGION: $OMARCHY_REGION" >&2 + exit 1 + ;; +esac diff --git a/install/provisioning/setup-form.sh b/install/provisioning/setup-form.sh index f4265d1d..9d8bd0d2 100644 --- a/install/provisioning/setup-form.sh +++ b/install/provisioning/setup-form.sh @@ -18,8 +18,9 @@ # so it never reaches the shell as SIGINT. Act on the status, never on a trap. # # Callers supply `notice ` for validation feedback, and set -# the variables these prompts write: keyboard, keyboard_label, username, -# password, password_confirmation, full_name, email_address, hostname, timezone. +# the variables these prompts write: region, keyboard, keyboard_label, +# username, password, password_confirmation, full_name, email_address, +# hostname, timezone. OMARCHY_FORM_BACK=1 OMARCHY_FORM_SIGNAL=130 @@ -91,6 +92,15 @@ omarchy_username_taken() { return 1; } # by `status=$?`: one caller runs under `set -e`, where a cancelled prompt is a # failing assignment that would kill the script before the status is read. +# China lists the .cn package mirrors first and sets up Chinese input. +omarchy_prompt_region() { + local choice status + choice=$(gum choose --selected "Global" --header "Select region" Global China) && status=0 || status=$? + ((status == 0)) || return $status + + region=${choice,,} +} + omarchy_prompt_keyboard() { local choice status choice=$(printf '%s\n' "$OMARCHY_KEYBOARD_LAYOUTS" | cut -d'|' -f1 | diff --git a/plans/omarchycn.md b/plans/omarchycn.md index b455c20e..cbdfe7ed 100644 --- a/plans/omarchycn.md +++ b/plans/omarchycn.md @@ -13,8 +13,8 @@ Progress source of truth for the `omarchycn` branches of `omarchy`, `omarchy-iso ## Tasks -- [ ] T0 Branches and this list -- [ ] T1 China package sources (PRD 1): region state, `omarchy-region` reader, `default/region/china/pacman.sed`, applied by `omarchy-refresh-pacman` and `install/post-install/pacman.sh`; tests +- [x] T0 Branches and this list +- [x] T1 China package sources (PRD 1): region state, `omarchy-region` reader, `default/region/china/pacman.sed`, applied by `omarchy-refresh-pacman` and `install/post-install/pacman.sh`; tests - [ ] 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 - [ ] 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 - [ ] T4 CJK fontconfig fix (PRD 4): rebuild PR 9693 on the current base diff --git a/test/shell.d/region-test.sh b/test/shell.d/region-test.sh index e471e33d..49399014 100755 --- a/test/shell.d/region-test.sh +++ b/test/shell.d/region-test.sh @@ -54,3 +54,23 @@ if output=$("$region_bin" 2>&1); then fi [[ $output == "Unknown region in $region_file: mars" ]] || fail "an unknown region names the file and value" "$output" pass "an unknown region fails and names the file and value" + +region_setup="$test_tmp/region.sh" +sed "s|/etc/omarchy|$test_tmp/etc-omarchy|g" "$ROOT/install/config/region.sh" >"$region_setup" + +OMARCHY_REGION=china bash -e "$region_setup" +[[ $(<"$test_tmp/etc-omarchy/region") == "china" ]] || fail "install records the China region" +pass "install records the China region" + +OMARCHY_REGION=global bash -e "$region_setup" +[[ ! -e $test_tmp/etc-omarchy/region ]] || fail "install records Global by leaving no region file" +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" +pass "Global and an unset region leave no region file" + +if output=$(OMARCHY_REGION=mars bash -e "$region_setup" 2>&1); then + fail "install rejects an unknown region" "$output" +fi +[[ $output == "Unknown OMARCHY_REGION: mars" ]] || fail "install names the unknown region" "$output" +pass "install rejects an unknown region" diff --git a/test/shell.d/setup-form-test.sh b/test/shell.d/setup-form-test.sh index 2b9878eb..3e5ff777 100755 --- a/test/shell.d/setup-form-test.sh +++ b/test/shell.d/setup-form-test.sh @@ -61,6 +61,7 @@ trap 'if [[ ${FUNCNAME[0]:-} == "$PROMPT_FN" ]]; then printf "returned\n" >>"$MA "$PROMPT_FN" +printf 'region=%s\n' "${region:-}" printf 'keyboard=%s\n' "${keyboard:-}" printf 'keyboard_label=%s\n' "${keyboard_label:-}" printf 'username=%s\n' "${username:-}" @@ -123,6 +124,25 @@ source "$ROOT/install/provisioning/setup-form.sh" fail "English (US) leads the keyboard layouts so gum choose opens on the default" pass "the form publishes the 0/1/130 status contract and leads with English (US)" +# Region + +run_prompt omarchy_prompt_region "0:China" +assert_status 0 "region prompt succeeds" +[[ $(field region) == "china" ]] || fail "region prompt stores China as china" +grep -qxF -- 'choose --selected Global --header Select region Global China' "$GUM_ARGS" || fail "region prompt offers Global then China and preselects Global" +run_prompt omarchy_prompt_region "0:Global" +[[ $(field region) == "global" ]] || fail "region prompt stores Global as global" +pass "region prompt maps Global and China to the stored region" + +run_prompt omarchy_prompt_region "1:" +assert_status "$OMARCHY_FORM_BACK" "region prompt reports Esc as back" +assert_returned "region prompt survives Esc under set -e" + +run_prompt omarchy_prompt_region "130:" +assert_status "$OMARCHY_FORM_SIGNAL" "region prompt reports Ctrl+C as the caller's signal" +assert_returned "region prompt survives Ctrl+C under set -e" +pass "region prompt propagates Esc and Ctrl+C without dying under set -e" + # Keyboard run_prompt omarchy_prompt_keyboard "0:German"