postinst.sh 1.6 KB

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