summarylogtreecommitdiffstats
path: root/arbie.install
blob: e7a45b79fed6bfed93208da34662ff90da93cb6a (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
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash

basename="arbie"
mapfile -t users < <(loginctl --no-legend list-users | awk '{ print $2 }' | sed ':a;N;$!ba')

_refresh_daemon() {
  su "$1" -s /bin/sh -c "XDG_RUNTIME_DIR=/run/user/\$UID systemctl --user daemon-reload"
}

_start_service() {
  su "$1" -s /bin/sh -c "XDG_RUNTIME_DIR=/run/user/\$UID systemctl --user start $basename"
}

_stop_service() {
  su "$1" -s /bin/sh -c "XDG_RUNTIME_DIR=/run/user/\$UID systemctl --user stop $basename"
}

_enable_service() {
  su "$1" -s /bin/sh -c "XDG_RUNTIME_DIR=/run/user/\$UID systemctl --user enable $basename"
}

_disable_service() {
  su "$1" -s /bin/sh -c "XDG_RUNTIME_DIR=/run/user/\$UID systemctl --user disable $basename"
}

_is_service_active() {
  if su "$1" -s /bin/sh -c "XDG_RUNTIME_DIR=/run/user/\$UID systemctl --user is-active $basename" &>/dev/null; then
    return 0
  else
    return 1
  fi
}

_is_service_enabled() {
  if su "$1" -s /bin/sh -c "XDG_RUNTIME_DIR=/run/user/\$UID systemctl --user is-enabled $basename" &>/dev/null; then
    return 0
  else
    return 1
  fi
}

pre_install() {
  : # noop
}

post_install() {
  for user in "${users[@]}"; do
    _refresh_daemon "$user"
    _start_service "$user"
    _enable_service "$user"
  done
}

pre_upgrade() {
  for user in "${users[@]}"; do
    if _is_service_active "$user"; then
      _stop_service "$user"
    fi
  done
}

post_upgrade() {
  for user in "${users[@]}"; do
    _refresh_daemon "$user"
    _start_service "$user"
  done
}

pre_remove() {
  for user in "${users[@]}"; do
    if _is_service_active "$user"; then
      _stop_service "$user"
      _disable_service "$user"
    fi
  done
}

post_remove() {
  for user in "${users[@]}"; do
    _refresh_daemon "$user"
  done
}