postinst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Emby 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. # ensure jellyfin binary has appropriate permissions
  33. chmod 755 /usr/bin/jellyfin
  34. /usr/bin/mono --aot=full -O=all $JELLYFIN_BIN > /dev/null 2>&1 || true
  35. chmod +x ${JELLYFIN_DIR}/restart.sh > /dev/null 2>&1 || true
  36. ;;
  37. abort-upgrade|abort-remove|abort-deconfigure)
  38. ;;
  39. *)
  40. echo "postinst called with unknown argument \`$1'" >&2
  41. exit 1
  42. ;;
  43. esac
  44. #DEBHELPER
  45. if [[ -x "/usr/bin/deb-systemd-helper" ]]; then
  46. # Manual init script handling
  47. deb-systemd-helper unmask jellyfin.service >/dev/null || true
  48. # was-enabled defaults to true, so new installations run enable.
  49. if deb-systemd-helper --quiet was-enabled jellyfin.service; then
  50. # Enables the unit on first installation, creates new
  51. # symlinks on upgrades if the unit file has changed.
  52. deb-systemd-helper enable jellyfin.service >/dev/null || true
  53. else
  54. # Update the statefile to add new symlinks (if any), which need to be
  55. # cleaned up on purge. Also remove old symlinks.
  56. deb-systemd-helper update-state jellyfin.service >/dev/null || true
  57. fi
  58. fi
  59. # End automatically added section
  60. # Automatically added by dh_installinit
  61. if [[ "$1" == "configure" ]] || [[ "$1" == "abort-upgrade" ]]; then
  62. if [[ -d "/run/systemd/systemd" ]]; then
  63. systemctl --system daemon-reload >/dev/null || true
  64. deb-systemd-invoke start jellyfin >/dev/null || true
  65. elif [[ -x "/etc/init.d/jellyfin" ]] || [[ -e "/etc/init/jellyfin.conf" ]]; then
  66. update-rc.d jellyfin defaults >/dev/null
  67. invoke-rc.d jellyfin start || exit $?
  68. fi
  69. fi
  70. exit 0