postinst 2.6 KB

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