#!/usr/bin/env bash set -eu user="${SUDO_USER:-$USER}" function initialised { grep -q '^Include = /etc/pacman.d/aurto$' /etc/pacman.conf } post_install() { if initialised; then echo 'Already initialised' >&2 exit 0 fi echo "aurto: Initialising for user: $user" echo "$user" > /usr/lib/aurto/user chmod 700 /usr/lib/aurto/user install -d /var/cache/pacman/aurto -o "$user" sudo -u "$user" repo-add /var/cache/pacman/aurto/aurto.db.tar 2>/dev/null echo 'aurto: Adding include /etc/pacman.d/aurto >> pacman.conf' >&2 if ! test -f /etc/pacman.conf.aurto-backup; then cp /etc/pacman.conf /etc/pacman.conf.aurto-backup fi echo -e "# aurto repo\\nInclude = /etc/pacman.d/aurto" >> /etc/pacman.conf echo 'aurto: Adding & enabling systemd timer update tasks' >&2 systemctl enable --now /usr/lib/systemd/system/check-aurto-git-trigger.timer systemctl enable --now /usr/lib/systemd/system/update-aurto.timer echo "aurto: Passwordless usage available for \`wheel\` group" } pre_remove() { if ! initialised; then exit 0 fi echo 'aurto: Removing systemd timer update tasks' >&2 systemctl disable --now check-aurto-git-trigger.timer || true systemctl disable --now update-aurto.timer || true } post_remove() { if ! initialised; then exit 0 fi echo 'aurto: Removing include from pacman.conf' >&2 sed -i '/^Include = \/etc\/pacman.d\/aurto$/d' /etc/pacman.conf sed -i '/^# aurto repo$/d' /etc/pacman.conf echo 'aurto: Removing /var/cache/pacman/aurto' >&2 rm -rf /var/cache/pacman/aurto || true rm -rf /usr/lib/aurto/user || true }