Files
omarchy/bin/omarchy-region
T

51 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# omarchy:summary=Show or switch the region this machine is set up for
# omarchy:args=[global|china]
# omarchy:examples=omarchy region | omarchy region china
# omarchy:requires-sudo=true
set -euo pipefail
region_file=/etc/omarchy/region
if (($# == 0)); then
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
exit 0
fi
if [[ $1 != "global" && $1 != "china" ]]; then
echo "Usage: omarchy-region [global|china]" >&2
exit 1
fi
pacman_files=(/etc/pacman.conf /etc/pacman.d/mirrorlist)
drop_cn_servers='/^Server = https:\/\/[a-z-]*\.omarchy\.cn\//d'
if [[ $1 == "china" ]]; then
# 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
rime-ice-installer --yes
fi
else
sudo sed -i -e "$drop_cn_servers" "${pacman_files[@]}"
echo "Package mirrors -> .org only"
sudo env OMARCHY_REGION=global OMARCHY_PATH="$OMARCHY_PATH" bash -e "$OMARCHY_PATH/install/config/region.sh"
omarchy-setup-claude-api --remove
fi
echo "Region set to ${1^}. Log out and back in to switch the language and developer mirrors."