postinst.sh 1.5 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. # TODO: This is only tested on Debian.
  7. #
  8. if [ "$1" = "configure" ] && [ -d /run/systemd/system ]; then
  9. # Create ntfy user/group
  10. id ntfy >/dev/null 2>&1 || useradd --system --no-create-home ntfy
  11. chown ntfy.ntfy /var/cache/ntfy
  12. chmod 700 /var/cache/ntfy
  13. # Hack to change permissions on cache file
  14. configfile="/etc/ntfy/server.yml"
  15. if [ -f "$configfile" ]; then
  16. cachefile="$(cat "$configfile" | perl -n -e'/^\s*cache-file: ["'"'"']?([^"'"'"']+)["'"'"']?/ && print $1')" # Oh my, see #47
  17. if [ -n "$cachefile" ]; then
  18. chown ntfy.ntfy "$cachefile" || true
  19. chmod 600 "$cachefile" || true
  20. fi
  21. fi
  22. # Restart services
  23. systemctl --system daemon-reload >/dev/null || true
  24. if systemctl is-active -q ntfy.service; then
  25. echo "Restarting ntfy.service ..."
  26. if [ -x /usr/bin/deb-systemd-invoke ]; then
  27. deb-systemd-invoke try-restart ntfy.service >/dev/null || true
  28. else
  29. systemctl restart ntfy.service >/dev/null || true
  30. fi
  31. fi
  32. if systemctl is-active -q ntfy-client.service; then
  33. echo "Restarting ntfy-client.service ..."
  34. if [ -x /usr/bin/deb-systemd-invoke ]; then
  35. deb-systemd-invoke try-restart ntfy-client.service >/dev/null || true
  36. else
  37. systemctl restart ntfy-client.service >/dev/null || true
  38. fi
  39. fi
  40. fi