postinst.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. groupadd -f ntfy
  10. id ntfy >/dev/null 2>&1 || useradd --system --no-create-home -g ntfy ntfy
  11. chown ntfy:ntfy /var/cache/ntfy /var/cache/ntfy/attachments /var/lib/ntfy
  12. chmod 700 /var/cache/ntfy /var/cache/ntfy/attachments /var/lib/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
  41. fi