2018-08-19 19:27:47 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2018-08-19 20:09:26 +00:00
|
|
|
# ANSI colour escape sequences
|
|
|
|
RED='\033[0;31m'
|
2018-08-20 10:41:01 +00:00
|
|
|
CYANBOLD='\033[1;36m'
|
2018-08-19 20:09:26 +00:00
|
|
|
RESET='\033[0m'
|
|
|
|
|
2018-08-20 10:41:01 +00:00
|
|
|
CONFIG_DIR="/config"
|
|
|
|
OLD_CONFIG="/config/Plex Media Server"
|
|
|
|
|
|
|
|
if [ -d "$OLD_CONFIG" ] && mountpoint -q "$OLD_CONFIG"; then
|
|
|
|
rm -rf /var/lib/plexmediaserver
|
|
|
|
ln -sf "$CONFIG_DIR" /var/lib/plexmediaserver
|
|
|
|
|
|
|
|
2>&1 echo -e "${RED}####################### NOTICE #######################${RESET}"
|
|
|
|
2>&1 echo
|
|
|
|
2>&1 echo -e "${RED} The config mountpoint has changed!${RESET}"
|
|
|
|
2>&1 echo -e "${RED} Please change the volume as follows:${RESET}"
|
|
|
|
2>&1 echo
|
|
|
|
2>&1 echo -e "${CYANBOLD} '$OLD_CONFIG'${RESET} -> ${CYANBOLD}'$CONFIG_DIR'${RESET}"
|
|
|
|
2>&1 echo
|
|
|
|
2>&1 echo -e "${RED}######################################################${RESET}"
|
|
|
|
2>&1 echo
|
|
|
|
|
|
|
|
CONFIG_DIR="$OLD_CONFIG"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if su-exec -e [ ! -w "$CONFIG_DIR" ]; then
|
2018-08-19 20:09:26 +00:00
|
|
|
2>&1 echo -e "${RED}####################### WARNING #######################${RESET}"
|
|
|
|
2>&1 echo
|
2018-08-20 10:41:01 +00:00
|
|
|
2>&1 echo -e "${RED} No permission to write in '$CONFIG_DIR' directory.${RESET}"
|
2018-08-19 20:09:26 +00:00
|
|
|
2>&1 echo -e "${RED} Correcting permissions to prevent a crash.${RESET}"
|
2018-08-19 19:27:47 +00:00
|
|
|
2>&1 echo
|
2018-08-19 20:09:26 +00:00
|
|
|
2>&1 echo -e "${RED}#######################################################${RESET}"
|
2018-08-20 10:41:01 +00:00
|
|
|
2>&1 echo
|
2018-08-19 20:09:26 +00:00
|
|
|
|
2018-08-20 10:41:01 +00:00
|
|
|
chown $SUID:$SGID "$CONFIG_DIR"
|
|
|
|
chmod o+rw "$CONFIG_DIR"
|
2018-08-19 19:27:47 +00:00
|
|
|
fi
|
|
|
|
|
2018-08-20 10:41:01 +00:00
|
|
|
export CONFIG_DIR
|
|
|
|
export PREF_FILE="$CONFIG_DIR/Preferences.xml"
|
|
|
|
|
2018-08-19 19:27:47 +00:00
|
|
|
exec su-exec -e sh <<EOF
|
2018-08-19 20:09:26 +00:00
|
|
|
|
2018-10-04 11:48:52 +00:00
|
|
|
source plex-util.sh
|
|
|
|
|
2018-08-19 20:09:26 +00:00
|
|
|
# Generate a default configuration on first run, including some user-specified values
|
2018-08-20 10:41:01 +00:00
|
|
|
if [ ! -e "\$PREF_FILE" ]; then
|
|
|
|
source gen-config.sh
|
2018-08-19 19:27:47 +00:00
|
|
|
fi
|
|
|
|
|
2018-11-26 13:30:45 +00:00
|
|
|
# Changes the log verbosity (Environment variable takes precedence on Plex Config)
|
|
|
|
if [ "$LOG_VERBOSE" = "1" ]; then
|
|
|
|
setPref "LogVerbose" "1"
|
|
|
|
elif [ "$LOG_VERBOSE" = "0" ]; then
|
|
|
|
setPref "LogVerbose" "0"
|
|
|
|
elif [ ! -z "$LOG_VERBOSE" ]; then
|
|
|
|
2>&1 echo -e "${RED}LOG_VERBOSE value '$LOG_VERBOSE' is invalid${RESET}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Changes the debug verbosity (Environment variable takes precedence on Plex Config)
|
|
|
|
if [ "$LOG_DEBUG" = "1" ]; then
|
|
|
|
setPref "logDebug" "1"
|
|
|
|
elif [ "$LOG_DEBUG" = "0" ]; then
|
|
|
|
setPref "logDebug" "0"
|
|
|
|
elif [ ! -z "$LOG_DEBUG" ]; then
|
|
|
|
2>&1 echo -e "${RED}LOG_DEBUG value '$LOG_DEBUG' is invalid${RESET}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-10-04 11:48:52 +00:00
|
|
|
# Always attempt to claim an unclaimed server in case it was signed out
|
|
|
|
token="\$(getPref "PlexOnlineToken")"
|
|
|
|
if [ ! -z "\${PLEX_CLAIM}" ] && [ -z "\${token}" ]; then
|
|
|
|
claim-server.sh --load-client-id --save
|
|
|
|
fi
|
|
|
|
|
2018-08-19 19:27:47 +00:00
|
|
|
# Duplicate the Plex logs to stdout (docker logs)
|
2018-08-20 10:41:01 +00:00
|
|
|
tail -Fn 0 "\$CONFIG_DIR/Logs/Plex Media Server.log" 2>/dev/null &
|
2018-08-19 19:27:47 +00:00
|
|
|
|
|
|
|
# Use a random pidfile
|
|
|
|
export PLEX_MEDIA_SERVER_PIDFILE="\$(mktemp -ut pms-pid.XXXXXX)"
|
|
|
|
|
|
|
|
exec "\$PLEX_MEDIA_SERVER_HOME/Plex Media Server"
|
2018-08-19 20:09:26 +00:00
|
|
|
|
2018-08-19 19:27:47 +00:00
|
|
|
EOF
|