postinst.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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/config.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. fi
  20. fi
  21. # Restart service
  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. fi