preinst 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. set -e
  3. NAME=jellyfin
  4. DEFAULT_FILE=/etc/default/${NAME}
  5. # Source Jellyfin default configuration
  6. if [[ -f $DEFAULT_FILE ]]; then
  7. . $DEFAULT_FILE
  8. fi
  9. # Data directories for program data (cache, db), configs, and logs
  10. PROGRAMDATA=${JELLYFIN_DATA_DIRECTORY-/var/lib/$NAME}
  11. CONFIGDATA=${JELLYFIN_CONFIG_DIRECTORY-/etc/$NAME}
  12. LOGDATA=${JELLYFIN_DATA_DIRECTORY-/var/log/$NAME}
  13. # In case this system is running systemd, we make systemd reload the unit files
  14. # to pick up changes.
  15. if [[ -d /run/systemd/system ]] ; then
  16. systemctl --system daemon-reload >/dev/null || true
  17. fi
  18. case "$1" in
  19. install|upgrade)
  20. # try graceful termination;
  21. if [[ -d /run/systemd/system ]]; then
  22. deb-systemd-invoke stop ${NAME}.service > /dev/null 2>&1 || true
  23. elif [ -x "/etc/init.d/${NAME}" ] || [ -e "/etc/init/${NAME}.conf" ]; then
  24. invoke-rc.d ${NAME} stop > /dev/null 2>&1 || true
  25. fi
  26. # try and figure out if jellyfin is running
  27. PIDFILE=$(find /var/run/ -maxdepth 1 -mindepth 1 -name "jellyfin*.pid" -print -quit)
  28. [[ -n "$PIDFILE" ]] && [[ -s "$PIDFILE" ]] && JELLYFIN_PID=$(cat ${PIDFILE})
  29. # if its running, let's stop it
  30. if [[ -n "$JELLYFIN_PID" ]]; then
  31. echo "Stopping Jellyfin!"
  32. # if jellyfin is still running, kill it
  33. if [[ -n "$(ps -p $JELLYFIN_PID -o pid=)" ]]; then
  34. CPIDS=$(pgrep -P $JELLYFIN_PID)
  35. sleep 2 && kill -KILL $CPIDS
  36. kill -TERM $CPIDS > /dev/null 2>&1
  37. fi
  38. sleep 1
  39. # if it's still running, show error
  40. if [[ -n "$(ps -p $JELLYFIN_PID -o pid=)" ]]; then
  41. echo "Could not successfully stop JellyfinServer, please do so before uninstalling."
  42. exit 1
  43. else
  44. [[ -f $PIDFILE ]] && rm $PIDFILE
  45. fi
  46. fi
  47. # Clean up old Emby cruft that can break the user's system
  48. [[ -f /etc/sudoers.d/emby ]] && rm -f /etc/sudoers.d/emby
  49. # If we have existing config or log dirs in /var/lib/jellyfin, move them into the right place
  50. if [[ -d $PROGRAMDATA/config ]]; then
  51. mv $PROGRAMDATA/config $CONFIGDATA
  52. fi
  53. if [[ -d $PROGRAMDATA/logs ]]; then
  54. mv $PROGRAMDATA/logs $LOGDATA
  55. fi
  56. ;;
  57. abort-upgrade)
  58. ;;
  59. *)
  60. echo "preinst called with unknown argument \`$1'" >&2
  61. exit 1
  62. ;;
  63. esac
  64. #DEBHELPER#
  65. exit 0