diff --git a/bin/omarchy b/bin/omarchy index 35b8094a..0649f0a5 100755 --- a/bin/omarchy +++ b/bin/omarchy @@ -73,6 +73,7 @@ GROUP_DESCRIPTIONS[plymouth]="Plymouth boot theme management" GROUP_DESCRIPTIONS[power]="Power supply detection" GROUP_DESCRIPTIONS[powerprofiles]="Power profile management" GROUP_DESCRIPTIONS[refresh]="Reset config to defaults" +GROUP_DESCRIPTIONS[region]="Region-specific package sources and setup" GROUP_DESCRIPTIONS[reinstall]="Reinstall and reset workflows" GROUP_DESCRIPTIONS[reminder]="Desktop notification reminders" GROUP_DESCRIPTIONS[remove]="Removal workflows" diff --git a/bin/omarchy-refresh-pacman b/bin/omarchy-refresh-pacman index 7406e6ad..80973b65 100755 --- a/bin/omarchy-refresh-pacman +++ b/bin/omarchy-refresh-pacman @@ -35,6 +35,11 @@ sudo cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak echo "Setting channel to $channel" sudo cp -f "$OMARCHY_PATH/default/pacman/pacman-$channel.conf" /etc/pacman.conf sudo cp -f "$OMARCHY_PATH/default/pacman/mirrorlist-$channel" /etc/pacman.d/mirrorlist +region=$(omarchy-region) +if [[ $region == "China" ]]; then + echo "Adding China mirrors" + sudo sed -i -f "$OMARCHY_PATH/default/region/china/pacman.sed" /etc/pacman.conf /etc/pacman.d/mirrorlist +fi # Allow user customization of /etc/pacman.conf before the upgrade runs, so # custom repositories and IgnorePkg entries shape the downgrade-capable diff --git a/bin/omarchy-region b/bin/omarchy-region new file mode 100755 index 00000000..fad6bf33 --- /dev/null +++ b/bin/omarchy-region @@ -0,0 +1,16 @@ +#!/bin/bash + +# omarchy:summary=Show the region this machine is set up for + +set -euo pipefail + +region_file=/etc/omarchy/region + +if [[ ! -e $region_file ]]; then + echo "Global" +elif [[ $(<"$region_file") == "china" ]]; then + echo "China" +else + echo "Unknown region in $region_file: $(<"$region_file")" >&2 + exit 1 +fi diff --git a/default/region/china/pacman.sed b/default/region/china/pacman.sed new file mode 100644 index 00000000..6621071a --- /dev/null +++ b/default/region/china/pacman.sed @@ -0,0 +1 @@ +s|^Server = https://\([a-z-]*\)\.omarchy\.org/\(.*\)$|Server = https://\1.omarchy.cn/\2\n&| diff --git a/install/post-install/pacman.sh b/install/post-install/pacman.sh index da84975b..4be96b28 100644 --- a/install/post-install/pacman.sh +++ b/install/post-install/pacman.sh @@ -2,6 +2,10 @@ # installs use the live ISO's offline pacman.conf until this final restore. cp -f "$OMARCHY_PATH/default/pacman/pacman-${OMARCHY_MIRROR:-stable}.conf" /etc/pacman.conf cp -f "$OMARCHY_PATH/default/pacman/mirrorlist-${OMARCHY_MIRROR:-stable}" /etc/pacman.d/mirrorlist +region=$(omarchy-region) +if [[ $region == "China" ]]; then + sed -i -f "$OMARCHY_PATH/default/region/china/pacman.sed" /etc/pacman.conf /etc/pacman.d/mirrorlist +fi # Wait for CUPS to own the file, the way omarchy-settings does, so pacman does # not turn the override into a .pacnew during ISO package installation. diff --git a/test/shell.d/channel-sudo-boundary-test.sh b/test/shell.d/channel-sudo-boundary-test.sh index f98934c2..29554e4b 100755 --- a/test/shell.d/channel-sudo-boundary-test.sh +++ b/test/shell.d/channel-sudo-boundary-test.sh @@ -6,6 +6,7 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" source "$SHELL_TEST_DIR/fixtures/sudo-boundary-test.sh" copy_boundary_file bin/omarchy-channel-set copy_boundary_file bin/omarchy-refresh-pacman +copy_boundary_file bin/omarchy-region copy_boundary_file bin/omarchy-update export OMARCHY_UPDATE_LOGGED=1 diff --git a/test/shell.d/region-test.sh b/test/shell.d/region-test.sh new file mode 100755 index 00000000..e471e33d --- /dev/null +++ b/test/shell.d/region-test.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +set -euo pipefail + +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" + +expected_stable_omarchy='Server = https://pkgs.omarchy.cn/stable/$arch +Server = https://pkgs.omarchy.org/stable/$arch' +actual=$(sed -f "$china_sed" "$ROOT/default/pacman/pacman-stable.conf" | sed -n '/^\[omarchy\]/,/^$/p' | grep '^Server') +[[ $actual == "$expected_stable_omarchy" ]] || fail "stable [omarchy] lists pkgs.omarchy.cn before pkgs.omarchy.org" "$actual" +pass "stable [omarchy] lists pkgs.omarchy.cn before pkgs.omarchy.org" + +declare -A mirrors=([stable]=stable-mirror [rc]=rc-mirror [edge]=mirror) +for channel in stable rc edge; do + host=${mirrors[$channel]} + expected="Server = https://$host.omarchy.cn/\$repo/os/\$arch +Server = https://$host.omarchy.org/\$repo/os/\$arch" + actual=$(sed -f "$china_sed" "$ROOT/default/pacman/mirrorlist-$channel") + [[ $actual == "$expected" ]] || fail "$channel mirrorlist lists $host.omarchy.cn first" "$actual" + pass "$channel mirrorlist lists $host.omarchy.cn first" + + for file in "pacman-$channel.conf" "mirrorlist-$channel"; do + original=$(<"$ROOT/default/pacman/$file") + stripped=$(sed -f "$china_sed" "$ROOT/default/pacman/$file" | grep -v '^Server = https://[a-z-]*\.omarchy\.cn/') + [[ $stripped == "$original" ]] || fail "$file only gains .cn servers" "$(diff <(echo "$original") <(echo "$stripped"))" + + org_count=$(grep -c '^Server = https://[a-z-]*\.omarchy\.org/' "$ROOT/default/pacman/$file") + cn_count=$(sed -f "$china_sed" "$ROOT/default/pacman/$file" | grep -c '^Server = https://[a-z-]*\.omarchy\.cn/') + ((org_count > 0 && org_count == cn_count)) || fail "$file gets one .cn twin per .org server" "org=$org_count cn=$cn_count" + done + pass "$channel templates only gain one .cn twin per .org server" +done + +region_bin="$test_tmp/omarchy-region" +region_file="$test_tmp/region" +sed "s|/etc/omarchy/region|$region_file|" "$ROOT/bin/omarchy-region" >"$region_bin" +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 mars >"$region_file" +if output=$("$region_bin" 2>&1); then + fail "an unknown region fails" "$output" +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" diff --git a/test/shell.d/update-hook-security-test.sh b/test/shell.d/update-hook-security-test.sh index af7ec70a..3233c925 100755 --- a/test/shell.d/update-hook-security-test.sh +++ b/test/shell.d/update-hook-security-test.sh @@ -6,6 +6,7 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" source "$SHELL_TEST_DIR/fixtures/sudo-boundary-test.sh" copy_boundary_file bin/omarchy-update copy_boundary_file bin/omarchy-refresh-pacman +copy_boundary_file bin/omarchy-region # Replace the step symlink, preserving the real fixture dispatcher. rm "$SUDO_TEST_ROOT/bin/omarchy-update-aur-pkgs" copy_boundary_file bin/omarchy-update-aur-pkgs