summarylogtreecommitdiffstats
path: root/aurto.install
blob: ea3c4bc6e141aec3ae9faa6541901cbe0fd4be24 (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
60
61
62
63
64
65
66
67
68
69
70
#!/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

  echo 'aurto: Adding include /etc/pacman.d/aurto to 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

  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 passwordless use of arch-nspawn, mkarchroot, makechrootpkg, aurbuild_chroot' >&2
  if ! test -f /etc/sudoers.aurto-backup; then
    cp /etc/sudoers /etc/sudoers.aurto-backup
  fi
  echo "## aurto rules
%$user ALL=(ALL) NOPASSWD: /usr/bin/arch-nspawn
%$user ALL=(ALL) NOPASSWD:SETENV: /usr/bin/makechrootpkg
%$user ALL=(ALL) NOPASSWD:SETENV: /usr/bin/aurbuild_chroot
## /aurto rules" >> /etc/sudoers

  echo 'aurto: Adding 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
}

pre_remove() {
  if ! initialised; then
    exit 0
  fi

  echo 'aurto: Removing systemd timer update tasks' >&2
  systemctl disable --now check-aurto-git-trigger.timer
  systemctl disable --now update-aurto.timer
}

post_remove() {
  if ! initialised; then
    exit 0
  fi

  echo 'aurto: Removing aurto rules from /etc/sudoers' >&2
  sed -i '/^## aurto rules$/,/^## \/aurto rules$/d' /etc/sudoers

  echo 'aurto: Removing /var/cache/pacman/aurto' >&2
  rm -rf /var/cache/pacman/aurto || true

  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

  rm -rf /usr/lib/aurto/user || true
}