postinst 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. set -e
  3. NAME=jellyfin
  4. CONF_FILE=/etc/${NAME}.conf
  5. DEFAULT_FILE=/etc/default/${NAME}
  6. # Source Jellyfin default configuration
  7. if [[ -f $DEFAULT_FILE ]]; then
  8. . $DEFAULT_FILE
  9. fi
  10. # Source Jellyfin user configuration overrides
  11. if [[ -f $CONF_FILE ]]; then
  12. . $CONF_FILE
  13. fi
  14. # Data directory where Jellyfin database, cache and logs are stored
  15. PROGRAMDATA=${JELLYFIN_DATA-/var/lib/$NAME}
  16. case "$1" in
  17. configure)
  18. # create jellyfin group if it does not exist
  19. if [[ -z "$(getent group jellyfin)" ]]; then
  20. addgroup --quiet --system jellyfin > /dev/null 2>&1
  21. fi
  22. # create jellyfin user if it does not exist
  23. if [[ -z "$(getent passwd jellyfin)" ]]; then
  24. adduser --system --ingroup jellyfin --shell /bin/false jellyfin --no-create-home --home ${PROGRAMDATA} \
  25. --gecos "Jellyfin default user" > /dev/null 2>&1
  26. fi
  27. # ensure $PROGRAMDATA has appropriate permissions
  28. if [[ ! -d $PROGRAMDATA ]]; then
  29. mkdir $PROGRAMDATA
  30. chown -R jellyfin:jellyfin $PROGRAMDATA
  31. fi
  32. chmod +x ${JELLYFIN_DIR}/restart.sh > /dev/null 2>&1 || true
  33. # Install jellyfin symlink into /usr/bin
  34. ln -sf /usr/lib/jellyfin/bin/jellyfin /usr/bin/jellyfin
  35. ;;
  36. abort-upgrade|abort-remove|abort-deconfigure)
  37. ;;
  38. *)
  39. echo "postinst called with unknown argument \`$1'" >&2
  40. exit 1
  41. ;;
  42. esac
  43. #DEBHELPER
  44. if [[ -x "/usr/bin/deb-systemd-helper" ]]; then
  45. # Manual init script handling
  46. deb-systemd-helper unmask jellyfin.service >/dev/null || true
  47. # was-enabled defaults to true, so new installations run enable.
  48. if deb-systemd-helper --quiet was-enabled jellyfin.service; then
  49. # Enables the unit on first installation, creates new
  50. # symlinks on upgrades if the unit file has changed.
  51. deb-systemd-helper enable jellyfin.service >/dev/null || true
  52. else
  53. # Update the statefile to add new symlinks (if any), which need to be
  54. # cleaned up on purge. Also remove old symlinks.
  55. deb-systemd-helper update-state jellyfin.service >/dev/null || true
  56. fi
  57. fi
  58. # End automatically added section
  59. # Automatically added by dh_installinit
  60. if [[ "$1" == "configure" ]] || [[ "$1" == "abort-upgrade" ]]; then
  61. if [[ -d "/run/systemd/systemd" ]]; then
  62. systemctl --system daemon-reload >/dev/null || true
  63. deb-systemd-invoke start jellyfin >/dev/null || true
  64. elif [[ -x "/etc/init.d/jellyfin" ]] || [[ -e "/etc/init/jellyfin.conf" ]]; then
  65. update-rc.d jellyfin defaults >/dev/null
  66. invoke-rc.d jellyfin start || exit $?
  67. fi
  68. fi
  69. exit 0