From f42e4b4f2247c3489b40ec9b85d59df2be130c26 Mon Sep 17 00:00:00 2001 From: Henric Andersson Date: Wed, 15 Feb 2017 08:37:30 -0800 Subject: [PATCH] Fixed issue where assumptions were made about plex installation Token file isn't necessarily defined by user nor is it installed in user's home directory. This allows us to specify additional locations to find the preference where the token hides. --- plexupdate.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plexupdate.sh b/plexupdate.sh index bbf9e69..2ffeeb6 100755 --- a/plexupdate.sh +++ b/plexupdate.sh @@ -201,13 +201,20 @@ keypair() { } getPlexServerToken() { - [ -f /etc/default/plexmediaserver ] && . /etc/default/plexmediaserver - local pmsApplicationSupportDir="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR:-${HOME}/Library/Application Support}" - local prefFile="${pmsApplicationSupportDir}/Plex Media Server/Preferences.xml" - - if [ -f "${prefFile}" ]; then - sed -n 's/.*PlexOnlineToken="\([[:alnum:]]*\).*".*/\1/p' "${prefFile}" + if [ -f /etc/default/plexmediaserver ]; then + source /etc/default/plexmediaserver fi + + # List possible locations to find Plex Server preference file + local VALIDPATHS=("${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" "/var/lib/plexmediaserver/Library/Application Support/" "${HOME}/Library/Application Support/") + local PREFFILE="/Plex Media Server/Preferences.xml" + + for I in "${VALIDPATHS[@]}" ; do + if [ ! -z "${I}" -a -f "${I}${PREFFILE}" ]; then + sed -n 's/.*PlexOnlineToken="\([[:alnum:]]*\).*".*/\1/p' "${I}${PREFFILE}" 2>/dev/null || error "Do not have permission to read token from Plex Server preference file" + exit 0 + fi + done } # Setup an exit handler so we cleanup