Debian Codegraph @

scripts/postinst.sh

raw
1 #!/bin/sh
2 set -e
3
4 # Restart systemd service if it was already running. Note that "deb-systemd-invoke try-restart" will
5 # only act if the service is already running. If it's not running, it's a no-op.
6 #
7 if [ "$1" = "configure" ] || [ "$1" -ge 1 ]; then
8 if [ -d /run/systemd/system ]; then
9 # Create ntfy user/group
10 groupadd -f ntfy
11 id ntfy >/dev/null 2>&1 || useradd --system --no-create-home -g ntfy ntfy
12 chown ntfy:ntfy /var/cache/ntfy /var/cache/ntfy/attachments /var/lib/ntfy
13 chmod 700 /var/cache/ntfy /var/cache/ntfy/attachments /var/lib/ntfy
14
15 # Hack to change permissions on cache file
16 configfile="/etc/ntfy/server.yml"
17 if [ -f "$configfile" ]; then
18 cachefile="$(cat "$configfile" | perl -n -e'/^\s*cache-file: ["'"'"']?([^"'"'"']+)["'"'"']?/ && print $1')" # Oh my, see #47
19 if [ -n "$cachefile" ]; then
20 chown ntfy:ntfy "$cachefile" || true
21 chmod 600 "$cachefile" || true
22 fi
23 fi
24
25 # Restart services
26 systemctl --system daemon-reload >/dev/null || true
27 if systemctl is-active -q ntfy.service; then
28 echo "Restarting ntfy.service ..."
29 if [ -x /usr/bin/deb-systemd-invoke ]; then
30 deb-systemd-invoke try-restart ntfy.service >/dev/null || true
31 else
32 systemctl restart ntfy.service >/dev/null || true
33 fi
34 fi
35 if systemctl is-active -q ntfy-client.service; then
36 echo "Restarting ntfy-client.service (system) ..."
37 if [ -x /usr/bin/deb-systemd-invoke ]; then
38 deb-systemd-invoke try-restart ntfy-client.service >/dev/null || true
39 else
40 systemctl restart ntfy-client.service >/dev/null || true
41 fi
42 fi
43 fi
44 fi