diff --git a/bin/omarchy-apply-pacman b/bin/omarchy-apply-pacman new file mode 100755 index 00000000..d5a92234 --- /dev/null +++ b/bin/omarchy-apply-pacman @@ -0,0 +1,53 @@ +#!/bin/bash + +# omarchy:summary=Restore channel and regional pacman defaults in an installed target +# omarchy:args= [target-root] +# omarchy:requires-sudo=true +# omarchy:hidden=true + +set -euo pipefail + +if (( $# < 1 || $# > 2 )); then + echo "Usage: omarchy-apply-pacman [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 +install -m 644 "$staging/pacman.conf" "$etc/pacman.conf" +install -m 644 "$staging/mirrorlist" "$etc/pacman.d/mirrorlist" diff --git a/bin/omarchy-refresh-pacman b/bin/omarchy-refresh-pacman index 7406e6ad..be2a256d 100755 --- a/bin/omarchy-refresh-pacman +++ b/bin/omarchy-refresh-pacman @@ -30,11 +30,10 @@ if [[ $channel != "stable" && $channel != "rc" && $channel != "edge" ]]; then exit 2 fi -sudo cp -f /etc/pacman.conf /etc/pacman.conf.bak -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 +# Restores the channel templates plus this machine's regional additions, and +# backs up both files first. OMARCHY_PATH was verified as this command's root. +sudo env "OMARCHY_PATH=$OMARCHY_PATH" "$OMARCHY_PATH/bin/omarchy-apply-pacman" "$channel" # Allow user customization of /etc/pacman.conf before the upgrade runs, so # custom repositories and IgnorePkg entries shape the downgrade-capable diff --git a/install/post-install/pacman.sh b/install/post-install/pacman.sh index da84975b..bb673353 100644 --- a/install/post-install/pacman.sh +++ b/install/post-install/pacman.sh @@ -1,7 +1,6 @@ # Configure pacman after package installation completes. Offline target package # 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 +"$OMARCHY_PATH/bin/omarchy-apply-pacman" "${OMARCHY_MIRROR:-stable}" # 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.