summarylogtreecommitdiffstats
path: root/aurto.install
blob: 1969ec98ca800a9136ce7aafc8f385a2d16063b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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
}