postinstall.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. set -e
  3. if [ "$1" = "configure" ]; then
  4. # Add user and group
  5. if ! getent group sftpgo >/dev/null; then
  6. groupadd --system sftpgo
  7. fi
  8. if ! getent passwd sftpgo >/dev/null; then
  9. useradd --system \
  10. --gid sftpgo \
  11. --no-create-home \
  12. --home-dir /var/lib/sftpgo \
  13. --shell /usr/sbin/nologin \
  14. --comment "SFTPGo user" \
  15. sftpgo
  16. fi
  17. if [ -z "$2" ]; then
  18. # initialize data provider
  19. sftpgo initprovider -c /etc/sftpgo
  20. # ensure files and folders have the appropriate permissions
  21. chown -R sftpgo:sftpgo /etc/sftpgo /var/lib/sftpgo
  22. chmod 750 /etc/sftpgo /var/lib/sftpgo
  23. chmod 640 /etc/sftpgo/sftpgo.json
  24. echo "Please be sure to have the python3-requests package installed if you want to use the REST API CLI"
  25. fi
  26. fi
  27. if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
  28. # This will only remove masks created by d-s-h on package removal.
  29. deb-systemd-helper unmask sftpgo.service >/dev/null || true
  30. # was-enabled defaults to true, so new installations run enable.
  31. if deb-systemd-helper --quiet was-enabled sftpgo.service; then
  32. # Enables the unit on first installation, creates new
  33. # symlinks on upgrades if the unit file has changed.
  34. deb-systemd-helper enable sftpgo.service >/dev/null || true
  35. deb-systemd-invoke start sftpgo.service >/dev/null || true
  36. else
  37. # Update the statefile to add new symlinks (if any), which need to be
  38. # cleaned up on purge. Also remove old symlinks.
  39. deb-systemd-helper update-state sftpgo.service >/dev/null || true
  40. fi
  41. # Restart only if it was already started
  42. if [ -d /run/systemd/system ]; then
  43. systemctl --system daemon-reload >/dev/null || true
  44. if [ -n "$2" ]; then
  45. deb-systemd-invoke try-restart sftpgo.service >/dev/null || true
  46. fi
  47. fi
  48. fi