#!/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"