From b52ce9178f9c704ba9bbac45ce1641f9a5e11acf Mon Sep 17 00:00:00 2001 From: Logan Holmes Date: Fri, 13 Jan 2017 16:09:41 -0800 Subject: [PATCH 1/3] Fall back on server token --- plexupdate.sh | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/plexupdate.sh b/plexupdate.sh index 6895e2d..73fdc0d 100755 --- a/plexupdate.sh +++ b/plexupdate.sh @@ -371,15 +371,6 @@ if [ "${AUTOUPDATE}" = "yes" ]; then popd &>/dev/null fi -# Sanity check -if [ -z "${EMAIL}" -o -z "${PASS}" ] && [ "${PUBLIC}" = "no" ]; then - error "Need username & password to download PlexPass version. Otherwise run with -p to download public version." - exit 1 -elif [ ! -z "${EMAIL}" ] && [[ "$EMAIL" == *"@"* ]] && [[ "$EMAIL" != *"@"*"."* ]]; then - error "EMAIL field must contain a valid email address" - exit 1 -fi - if [ "${AUTOINSTALL}" = "yes" -o "${AUTOSTART}" = "yes" ] && [ ${EUID} -ne 0 ]; then error "You need to be root to use AUTOINSTALL/AUTOSTART option." @@ -444,7 +435,13 @@ if [ "${CHECKUPDATE}" = "yes" -a "${AUTOUPDATE}" = "no" ]; then rm "${FILE_REMOTE}" 2>/dev/null >/dev/null fi - +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" + + sed -n 's/.*PlexOnlineToken="\([[:alnum:]]*\).*".*/\1/p' "$prefFile" +} # Fields we need to submit for login to work # @@ -457,10 +454,21 @@ fi # commit Sign in if [ "${PUBLIC}" = "no" ]; then - info "Authenticating with plex.tv" - # Clean old session rm "${FILE_KAKA}" 2>/dev/null + + if [ -z "${EMAIL}" -o -z "${PASS}" ]; then + TOKEN=$(getPlexServerToken) + + if [ -z "${TOKEN}" ]; then + error "Need username & password to download PlexPass version. Otherwise run with -p to download public version." + exit 1 + fi + elif [ ! -z "${EMAIL}" ] && [[ "$EMAIL" == *"@"* ]] && [[ "$EMAIL" != *"@"*"."* ]]; then + error "EMAIL field must contain a valid email address" + exit 1 + + info "Authenticating with plex.tv" # Build post data echo -ne >"${FILE_POSTDATA}" "$(keypair "user[login]" "${EMAIL}" )" @@ -492,6 +500,7 @@ if [ "${PUBLIC}" = "no" ]; then # Remove this, since it contains more information than we should leave hanging around rm "${FILE_FAILCAUSE}" +fi elif [ "$PUBLIC" != "no" ]; then # It's a public version, so change URL and make doubly sure that cookies are empty From 8aaf6b2db7ff798f0472499ba696fb08b3798e56 Mon Sep 17 00:00:00 2001 From: Henric Andersson Date: Wed, 15 Feb 2017 08:10:48 -0800 Subject: [PATCH 2/3] Messed up the IF statements when fixing issue --- plexupdate.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/plexupdate.sh b/plexupdate.sh index 5b32957..bbf9e69 100755 --- a/plexupdate.sh +++ b/plexupdate.sh @@ -510,8 +510,6 @@ if [ "${PUBLIC}" = "no" ]; then else info "Using Plex Server credentials to authenticate" fi -fi - elif [ "$PUBLIC" != "no" ]; then # It's a public version, so change URL and make doubly sure that cookies are empty rm 2>/dev/null >/dev/null "${FILE_KAKA}" From f42e4b4f2247c3489b40ec9b85d59df2be130c26 Mon Sep 17 00:00:00 2001 From: Henric Andersson Date: Wed, 15 Feb 2017 08:37:30 -0800 Subject: [PATCH 3/3] 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