jellyfin 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. # vim:set ft=sh sw=2 sts=2 st=2 et:
  3. # Author: HurricaneHernandez <carlos@techbyte.ca>
  4. # Modified for CentOS/Fedora by: FC7 <casasfernando@outlook.com>
  5. DESC=Jellyfin
  6. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  7. NAME=jellyfin
  8. CONF_FILE=/etc/${NAME}.conf
  9. DEFAULT_FILE=/etc/default/${NAME}
  10. SCRIPTNAME=/usr/bin/jellyfin
  11. # Source Jellyfin default configuration
  12. . $DEFAULT_FILE
  13. # Source Jellyfin user configuration overrides
  14. if [[ -f $CONF_FILE ]]; then
  15. . $CONF_FILE
  16. else
  17. echo "${CONF_FILE} not found using default settings.";
  18. fi
  19. # Ensure the runas user has restart privilege to restart the service if not try to add the user to jellyfin group. WARN on failure
  20. if [[ "$JELLYFIN_USER" != "jellyfin" ]]; then
  21. groups $JELLYFIN_USER | grep -q jellyfin
  22. if [[ $? -ne 0 ]]; then
  23. if [[ $EUID -eq 0 ]]; then
  24. usermod -a -G jellyfin $JELLYFIN_USER
  25. else
  26. echo "WARNING: The runas user is not part of jellyfin group and you don't have enough privileges to add it. The restart button in the GUI will probably fail."
  27. echo "To solve this start the jellyfin service using the startup scripts (systemd/sysv) or"
  28. echo "add the runas user ($JELLYFIN_USER) to the jellyfin group manually and restart Emby."
  29. fi
  30. fi
  31. fi
  32. # Data directory where Emby database, cache and logs are stored
  33. PROGRAMDATA=$JELLYFIN_DATA
  34. PROGRAMDATA_OPT="-programdata $PROGRAMDATA"
  35. # Path to store PID file
  36. PIDFILE=$JELLYFIN_PIDFILE
  37. # Full path of Emby binary
  38. JELLYFIN_EXEC=$JELLYFIN_BIN
  39. # Path of jellyfin program files
  40. JELLYFIN_PATH=$JELLYFIN_DIR
  41. # path to mono bin
  42. MONO_EXEC=$MONO_BIN
  43. # umask
  44. UMASK=${UMASK:-002}
  45. # Mono environment variables
  46. MAGICK_HOME_ENV="MAGICK_HOME=${JELLYFIN_PATH}"
  47. JELLYFIN_LIBRARY_PATH=$(find /usr/lib/jellyfin/ -maxdepth 1 -mindepth 1 -type d| grep -v bin | grep -v etc | grep -v -e "/\.")
  48. MAGICK_CODER_FILTER_PATH_ENV="MAGICK_CODER_FILTER_PATH=$(find ${JELLYFIN_LIBRARY_PATH} -type d -name "filters" | grep EmbyMagick)"
  49. MAGICK_CODER_MODULE_PATH_ENV="MAGICK_CODER_MODULE_PATH=$(find ${JELLYFIN_LIBRARY_PATH} -type d -name "coders" | grep EmbyMagick)"
  50. MONO_EXEC_ENV="$MONO_ENV ${JELLYFIN_LIBRARY_PATH:+"LD_LIBRARY_PATH=${JELLYFIN_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"}"
  51. # Mono options
  52. MONO_EXEC_OPTS=$MONO_OPTS
  53. # restart function
  54. RESTART_OPTS="-restartpath ${JELLYFIN_PATH}/restart.sh"
  55. # Emby options
  56. JELLYFIN_OPTS="$PROGRAMDATA_OPT $RESTART_OPTS $JELLYFIN_ADD_OPTS"
  57. PID_PATH=$(dirname $PIDFILE)
  58. # Exit if the mono-sgen not installed
  59. if [[ ! -x $MONO_EXEC ]]; then
  60. if [[ -n "$(command -v mono-sgen)" ]]; then
  61. MONO_EXEC=$(command -v mono-sgen)
  62. else
  63. MONO_EXEC=$(command -v mono)
  64. fi
  65. fi
  66. # Create programdata directory if not exist and ensure the jellyfin user can write to it
  67. if [[ ! -d $PROGRAMDATA ]]; then
  68. if [[ $EUID -eq 0 ]]; then
  69. mkdir -p $PROGRAMDATA
  70. else
  71. echo "WARNING: $JELLYFIN_DATA directory does not exist."
  72. echo "To solve this, if it is an upgrade verify that \"JELLYFIN_DATA\" is set to the correct path in /etc/jellyfin.conf."
  73. echo "You may need to locate the path of your library files and set JELLYFIN_DATA to that path."
  74. echo "If this is an new installation please rerun last command with elevated permissions."
  75. fi
  76. fi
  77. # Set right permission for directories
  78. DATA_CURRENT_USER=$(ls -lad $PROGRAMDATA | awk '{print $3}')
  79. if [[ "$DATA_CURRENT_USER" != "$JELLYFIN_USER" ]]; then
  80. if [[ $EUID -eq 0 ]]; then
  81. chown -R $JELLYFIN_USER.$JELLYFIN_GROUP $PROGRAMDATA
  82. else
  83. echo "WARNING: $JELLYFIN_DATA directory does not have the correct permissions."
  84. echo "Please rerun this script with elevated permissions."
  85. fi
  86. fi
  87. case "$1" in
  88. start)
  89. echo $$ > $PIDFILE
  90. exec su -s /bin/sh -c 'umask $0; exec "$1" "$@"' $JELLYFIN_USER -- \
  91. $UMASK env $MAGICK_HOME_ENV $MAGICK_CODER_FILTER_PATH_ENV $MAGICK_CODER_MODULE_PATH_ENV \
  92. $MONO_EXEC_ENV $MONO_EXEC $MONO_EXEC_OPTS $JELLYFIN_EXEC $JELLYFIN_OPTS
  93. ;;
  94. clear)
  95. [[ -e $PIDFILE ]] && rm -rf $PIDFILE
  96. ;;
  97. *)
  98. echo "Usage: $SCRIPTNAME {start|clear}" >&2
  99. exit 3
  100. ;;
  101. esac