- 🐛 refresh used to copy over the existing files, so a customized mode must survive the shared regional applicator too Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
1.7 KiB
Bash
Executable File
55 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Restore channel and regional pacman defaults in an installed target
|
|
# omarchy:args=<stable|rc|edge> [target-root]
|
|
# omarchy:requires-sudo=true
|
|
# omarchy:hidden=true
|
|
|
|
set -euo pipefail
|
|
|
|
if (( $# < 1 || $# > 2 )); then
|
|
echo "Usage: omarchy-apply-pacman <stable|rc|edge> [target-root]" >&2
|
|
exit 1
|
|
fi
|
|
|
|
channel="$1"
|
|
case "$channel" in
|
|
stable|rc|edge) ;;
|
|
*) echo "Invalid pacman channel: $channel" >&2; exit 1 ;;
|
|
esac
|
|
|
|
# The ISO writes this plain-text marker before target finalization. Missing
|
|
# markers keep existing installations global; never source it as shell code.
|
|
etc="${2:-/}/etc"
|
|
region=global
|
|
if [[ -e $etc/omarchy/region ]]; then
|
|
region=$(<"$etc/omarchy/region")
|
|
fi
|
|
case "$region" in
|
|
global|cn) ;;
|
|
*) echo "Unsupported region: $region (expected global or cn)" >&2; exit 1 ;;
|
|
esac
|
|
|
|
# Build both files before replacing either. Explicit refreshes retain backups;
|
|
# ordinary updates do not call this command or enforce regional defaults.
|
|
staging=$(mktemp -d)
|
|
trap 'rm -rf "$staging"' EXIT
|
|
cp "$OMARCHY_PATH/default/pacman/pacman-$channel.conf" "$staging/pacman.conf"
|
|
cp "$OMARCHY_PATH/default/pacman/mirrorlist-$channel" "$staging/mirrorlist"
|
|
if [[ $region != "global" ]]; then
|
|
profile="$OMARCHY_PATH/default/regions/$region/pacman"
|
|
printf '\n' >> "$staging/pacman.conf"
|
|
cat "$profile/pacman.conf.append" >> "$staging/pacman.conf"
|
|
cat "$profile/mirrorlist.append" >> "$staging/mirrorlist"
|
|
fi
|
|
|
|
mkdir -p "$etc/pacman.d"
|
|
for file in pacman.conf pacman.d/mirrorlist; do
|
|
if [[ -e $etc/$file ]]; then
|
|
cp -f "$etc/$file" "$etc/$file.bak"
|
|
fi
|
|
done
|
|
# Copying over an existing file keeps its owner and mode, as refresh always has.
|
|
cp -f "$staging/pacman.conf" "$etc/pacman.conf"
|
|
cp -f "$staging/mirrorlist" "$etc/pacman.d/mirrorlist"
|