#!/usr/bin/env bash # Installs system-level config that stow can't manage (needs root). set -euo pipefail repo="$(cd "$(dirname "$0")" && pwd)" # pacman: shared [options] snippet if cmp -s "$repo/pacman/options.conf" /etc/pacman.d/options.conf; then echo "pacman: /etc/pacman.d/options.conf already up to date" else sudo install -m644 "$repo/pacman/options.conf" /etc/pacman.d/options.conf echo "pacman: installed /etc/pacman.d/options.conf" fi # The Include goes at the end of [options] (just before the first repo section, # commented or not), so later-wins options like ParallelDownloads override # pacman.conf's own defaults. Any old copy (e.g. straight after [options]) is # removed first, along with the blank line written after it, so re-running this # moves it into place without piling up blank lines. include='Include = /etc/pacman.d/options.conf' tmp="$(mktemp)" awk -v inc="$include" ' $0 == inc { drop_blank = 1; next } drop_blank && $0 == "" { drop_blank = 0; next } { drop_blank = 0 } seen && !done && /^#?\[/ { print inc; print ""; done = 1 } /^\[options\]/ { seen = 1 } { print } ' /etc/pacman.conf >"$tmp" if cmp -s "$tmp" /etc/pacman.conf; then echo "pacman: /etc/pacman.conf already includes it at the end of [options]" else sudo install -m644 "$tmp" /etc/pacman.conf echo "pacman: added the Include to the end of [options] in /etc/pacman.conf" fi rm -f "$tmp" # What pacman actually ends up using echo "pacman: now using: $(pacman-conf Color ILoveCandy VerbosePkgLists ParallelDownloads | paste -sd, - | sed 's/,/, /g')"