postinst.sh 1.6 KB

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