From 67d780d5aec6e811a9a18bd946ff06d11ff05ac7 Mon Sep 17 00:00:00 2001 From: Henric Andersson Date: Sat, 16 Jul 2016 15:17:33 -0700 Subject: [PATCH] PlexPass download now work again + bonus KEEP option is deprecated because of the new TOKEN scheme used by plex.tv If you used KEEP=yes in the past, you would never get PlexPass unless the cookie file was lost. Since I don't track validity of token, it's better to remove keep completely. Also added support to avoid auto install if server is in-use (thanks @AltonV, @hakong and @sufr3ak for the tip) To enable the new feature, please set PLEXSERVER to the IP or DNS of your Plex Media Server (typically 127.0.0.1) The fixes #59 --- README.md | 2 ++ plexupdate.sh | 35 +++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a1d048d..a11678e 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ You can point out a different file than ```.plexupdate``` by providing it as the There are also a few additional options for the more enterprising user. Setting any of these to `yes` will enable the function. +- PLEXSERVER + If set, and combined with AUTOINSTALL, the script will automatically check if server is in-use and deferr the update. Great for crontab users. PLEXSERVER should be set to the IP/DNS of your Plex Media Server, which typically is 127.0.0.1 - AUTOUPDATE Makes plexupdate.sh automatically update itself using git. Note! This will fail if git isn't available on the command line. - AUTOINSTALL diff --git a/plexupdate.sh b/plexupdate.sh index a42cc2f..809363d 100755 --- a/plexupdate.sh +++ b/plexupdate.sh @@ -17,6 +17,7 @@ # 3 if page layout has changed. # 4 if download fails # 5 if version already installed +# 6 if update was deferred due to usage # # All other return values not documented. # @@ -41,6 +42,7 @@ fi EMAIL= PASS= DOWNLOADDIR="." +PLEXSERVER= ################################################################# # Don't change anything below this point @@ -48,7 +50,6 @@ DOWNLOADDIR="." # Defaults # (aka "Advanced" settings, can be overriden with config file) -KEEP=no FORCE=no PUBLIC=no AUTOINSTALL=no @@ -138,7 +139,7 @@ cronexit() { } usage() { - echo "Usage: $(basename $0) [configfile] [-acfhkopqsSuU]" + echo "Usage: $(basename $0) [configfile] [-acfhopqsSuU]" echo "" echo " configfile overrides the default ~/.plexupdate" echo " If used, it must be the FIRST option or it will be ignored" @@ -149,7 +150,6 @@ usage() { echo " -f Force download even if it's the same version or file" echo " already exists (WILL NOT OVERWRITE)" echo " -h This help" - echo " -k Reuse last authentication" echo " -l List available builds and distros" echo " -p Public Plex Media Server version" echo " -q Quiet mode. No stdout, only stderr and cronexit codes" @@ -174,7 +174,6 @@ do (-C) echo "ERROR: CRON option has changed, please review README.md" 1>&2; cronexit 255;; (-d) AUTODELETE=yes;; (-f) FORCE=yes;; - (-k) KEEP=yes;; (-l) LISTOPTS=yes;; (-p) PUBLIC=yes;; (-q) QUIET=yes;; @@ -190,6 +189,11 @@ do shift done +if [ "${KEEP}" = "yes" ]; then + echo "ERROR: KEEP is deprecated" >&2 + cronexit 1 +fi + # send all stdout to /dev/null if [ "${QUIET}" = "yes" ] || [ "${SILENT}" = "yes" ]; then exec 1> /dev/null @@ -313,9 +317,7 @@ function cleanup { rm /tmp/postdata 2>/dev/null >/dev/null rm /tmp/raw 2>/dev/null >/dev/null rm /tmp/failcause 2>/dev/null >/dev/null - if [ "${KEEP}" != "yes" ]; then - rm /tmp/kaka 2>/dev/null >/dev/null - fi + rm /tmp/kaka 2>/dev/null >/dev/null } trap cleanup EXIT @@ -329,8 +331,13 @@ trap cleanup EXIT # user[remember_me] 0 # commit Sign in +# Load previous token if stored +if [ -f /tmp/kaka_token ]; then + TOKEN=$(cat /tmp/kaka_token) +fi + # If user wants, we skip authentication, but only if previous auth exists -if [ "${KEEP}" != "yes" -o ! -f /tmp/kaka ] && [ "${PUBLIC}" == "no" ]; then +if [ "${PUBLIC}" == "no" ]; then echo -n "Authenticating..." # Clean old session @@ -356,7 +363,7 @@ if [ "${KEEP}" != "yes" -o ! -f /tmp/kaka ] && [ "${PUBLIC}" == "no" ]; then cat /tmp/failcause >&2 cronexit 1 fi - + # If the system got here, it means the login was successfull, so we set the TOKEN variable to the authToken from the response # I use cut -c 14- to cut off the "authToken":" string from the grepped result, can probably be done in a different way TOKEN=$(' ; then + echo "Server ${PLEXSERVER} is currently being used by one or more users, skipping installation. Please run again later" + cronexit 6 + fi +fi +exit 255 if [ "${AUTOINSTALL}" == "yes" ]; then sudo ${DISTRO_INSTALL} "${DOWNLOADDIR}/${FILENAME}" fi