postinst.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. chmod 600 "$cachefile" || true
  20. fi
  21. fi
  22. # Restart service
  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. fi