A new user interface for you! Read more...

File redhat.emby-server.sh of Package emby-server

#!/bin/sh
# Author: HurricaneHernandez <carlos@techbyte.ca>
# Modified for CentOS/Fedora by: FC7 <casasfernando@hotmail.com>

DESC=EmbyServer
PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME=emby-server
PKG_NAME=emby-server
CONF_FILE=/etc/${NAME}.conf
DEFAULT_FILE=/etc/default/${NAME}
SCRIPTNAME=/usr/lib/emby-server/emby-server.sh
LOG_FILE=/var/log/${NAME}.log

# Source Emby server default configuration
. $DEFAULT_FILE

# Source Emby server user configuration overrides
if [ -f $CONF_FILE ]; then
  . $CONF_FILE
else
  echo "${CONF_FILE} not found using default settings.";
fi

# Ensure the runas user has restart privilege to restart the service if not try to add the user to emby group. WARN on failure
if [ "$EMBY_USER" != "emby" ]; then
	groups $EMBY_USER | grep -q emby
	if [ $? -ne 0 ]; then
		if [[ $EUID -eq 0 ]]; then
    		usermod -a -G emby $EMBY_USER
		else
			echo "WARNING: The runas user is not part of emby group and you don't have enough privileges to add it. The restart button in the GUI will probably fail."
			echo "To solve this start the emby-server service using the startup scripts (systemd/sysv) or"
			echo "add the runas user ($EMBY_USER) to the emby group manually and restart Emby."
		fi
	fi
fi

# Data directory where Emby database, cache and logs are stored
PROGRAMDATA=$EMBY_DATA
PROGRAMDATA_OPT="-programdata $PROGRAMDATA"

# Path to store PID file
PIDFILE=$EMBY_PIDFILE

# Full path of Emby binary
EMBY_EXEC=$EMBY_BIN

# Path of emby program files
EMBY_PATH=$EMBY_DIR

# path to mono bin
MONO_EXEC=$MONO_BIN

# Mono environment variables
MAGICK_LIBRARY_PATH=$(find /usr/lib/emby-server/ -maxdepth 1 -mindepth 1 -type d| grep -v bin)
MONO_EXEC_ENV="$MONO_ENV LD_LIBRARY_PATH=${MAGICK_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"

# Mono options
MONO_EXEC_OPTS=$MONO_OPTS

# ffmpeg
FFMPEG_BIN=$(command -v ffmpeg)
[ -n "$FFMPEG_BIN" ] && FFMPEG_OPTS="-ffmpeg $FFMPEG_BIN"

# ffprobe
FFPROBE_BIN=$(command -v ffprobe)
[ -n "$FFPROBE_BIN" ] && FFPROBE_OPTS="-ffprobe $FFPROBE_BIN"

# restart function
RESTART_OPTS="-restartpath ${EMBY_PATH}/restart.sh"

# Emby options
EMBY_OPTS="$PROGRAMDATA_OPT $FFMPEG_OPTS $FFPROBE_OPTS $RESTART_OPTS $EMBY_ADD_OPTS"

PID_PATH=`dirname $PIDFILE`

# Exit if the mono-sgen not installed
[ -x $MONO_EXEC ] || exit 0

# Create programdata  directory if not exist and ensure the emby user can write to it
if [ ! -d $PROGRAMDATA ]; then
	if [[ $EUID -eq 0 ]]; then
		mkdir -p $PROGRAMDATA
	else
		echo "WARNING: $EMBY_DATA directory does not exist."
		echo "To solve this, if it is an upgrade verify that EMBY_DATA is set to the correct path in /etc/emby-server.conf."
		echo "You may need to locate the path of your library files and set EMBY_DATA to that path."
		echo "If this is an new installation please rerun last command with elevated permissions."
	fi
fi

# Set right permission for directories
DATA_CURRENT_USER=`ls -lad $PROGRAMDATA | awk '{print $3}'`

if [ "$DATA_CURRENT_USER" != "$EMBY_USER" ]; then
	if [[ $EUID -eq 0 ]]; then
		chown -R $EMBY_USER.$EMBY_GROUP $PROGRAMDATA
	else
		echo "WARNING: $EMBY_DATA directory does not have the correct permissions."
		echo "Please rerun this script with elevated permissions."
	fi
fi

case "$1" in
	start)
		echo $$ > $PIDFILE
		exec su -s /bin/sh -c 'exec "$0" "$@"' $EMBY_USER -- \
		env $MONO_EXEC_ENV $MONO_EXEC $MONO_EXEC_OPTS $EMBY_EXEC $EMBY_OPTS > $LOG_FILE 2>&1
		;;
	clear)
		[ -e $PIDFILE ] && rm -rf $PIDFILE
		;;
	*)
		echo "Usage: $SCRIPTNAME {start|clear}" >&2
		exit 3
	;;
esac