preinst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # In case this system is running systemd, we make systemd reload the unit files
  17. # to pick up changes.
  18. if [[ -d /run/systemd/system ]] ; then
  19. systemctl --system daemon-reload >/dev/null || true
  20. fi
  21. case "$1" in
  22. install|upgrade)
  23. # try graceful termination;
  24. if [[ -d /run/systemd/system ]]; then
  25. deb-systemd-invoke stop ${NAME}.service > /dev/null 2>&1 || true
  26. elif [ -x "/etc/init.d/${NAME}" ] || [ -e "/etc/init/${NAME}.conf" ]; then
  27. invoke-rc.d ${NAME} stop > /dev/null 2>&1 || true
  28. fi
  29. # try and figure out if jellyfin is running
  30. PIDFILE=$(find /var/run/ -maxdepth 1 -mindepth 1 -name "jellyfin*.pid" -print -quit)
  31. [[ -n "$PIDFILE" ]] && [[ -s "$PIDFILE" ]] && JELLYFIN_PID=$(cat ${PIDFILE})
  32. # if its running, let's stop it
  33. if [[ -n "$JELLYFIN_PID" ]]; then
  34. echo "Stopping Jellyfin!"
  35. # if jellyfin is still running, kill it
  36. if [[ -n "$(ps -p $JELLYFIN_PID -o pid=)" ]]; then
  37. CPIDS=$(pgrep -P $JELLYFIN_PID)
  38. sleep 2 && kill -KILL $CPIDS
  39. kill -TERM $CPIDS > /dev/null 2>&1
  40. fi
  41. sleep 1
  42. # if it's still running, show error
  43. if [[ -n "$(ps -p $JELLYFIN_PID -o pid=)" ]]; then
  44. echo "Could not successfully stop JellyfinServer, please do so before uninstalling."
  45. exit 1
  46. else
  47. [[ -f $PIDFILE ]] && rm $PIDFILE
  48. fi
  49. fi
  50. # Clean up old Emby cruft that can break the user's system
  51. [[ -f /etc/sudoers.d/emby ]] && rm -f /etc/sudoers.d/emby
  52. ;;
  53. abort-upgrade)
  54. ;;
  55. *)
  56. echo "preinst called with unknown argument \`$1'" >&2
  57. exit 1
  58. ;;
  59. esac
  60. #DEBHELPER#
  61. exit 0