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
This commit is contained in:
Henric Andersson 2016-07-16 15:17:33 -07:00
parent 4837eded60
commit 67d780d5ae
2 changed files with 27 additions and 10 deletions

View file

@ -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. 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 - AUTOUPDATE
Makes plexupdate.sh automatically update itself using git. Note! This will fail if git isn't available on the command line. Makes plexupdate.sh automatically update itself using git. Note! This will fail if git isn't available on the command line.
- AUTOINSTALL - AUTOINSTALL

View file

@ -17,6 +17,7 @@
# 3 if page layout has changed. # 3 if page layout has changed.
# 4 if download fails # 4 if download fails
# 5 if version already installed # 5 if version already installed
# 6 if update was deferred due to usage
# #
# All other return values not documented. # All other return values not documented.
# #
@ -41,6 +42,7 @@ fi
EMAIL= EMAIL=
PASS= PASS=
DOWNLOADDIR="." DOWNLOADDIR="."
PLEXSERVER=
################################################################# #################################################################
# Don't change anything below this point # Don't change anything below this point
@ -48,7 +50,6 @@ DOWNLOADDIR="."
# Defaults # Defaults
# (aka "Advanced" settings, can be overriden with config file) # (aka "Advanced" settings, can be overriden with config file)
KEEP=no
FORCE=no FORCE=no
PUBLIC=no PUBLIC=no
AUTOINSTALL=no AUTOINSTALL=no
@ -138,7 +139,7 @@ cronexit() {
} }
usage() { usage() {
echo "Usage: $(basename $0) [configfile] [-acfhkopqsSuU]" echo "Usage: $(basename $0) [configfile] [-acfhopqsSuU]"
echo "" echo ""
echo " configfile overrides the default ~/.plexupdate" echo " configfile overrides the default ~/.plexupdate"
echo " If used, it must be the FIRST option or it will be ignored" 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 " -f Force download even if it's the same version or file"
echo " already exists (WILL NOT OVERWRITE)" echo " already exists (WILL NOT OVERWRITE)"
echo " -h This help" echo " -h This help"
echo " -k Reuse last authentication"
echo " -l List available builds and distros" echo " -l List available builds and distros"
echo " -p Public Plex Media Server version" echo " -p Public Plex Media Server version"
echo " -q Quiet mode. No stdout, only stderr and cronexit codes" 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;; (-C) echo "ERROR: CRON option has changed, please review README.md" 1>&2; cronexit 255;;
(-d) AUTODELETE=yes;; (-d) AUTODELETE=yes;;
(-f) FORCE=yes;; (-f) FORCE=yes;;
(-k) KEEP=yes;;
(-l) LISTOPTS=yes;; (-l) LISTOPTS=yes;;
(-p) PUBLIC=yes;; (-p) PUBLIC=yes;;
(-q) QUIET=yes;; (-q) QUIET=yes;;
@ -190,6 +189,11 @@ do
shift shift
done done
if [ "${KEEP}" = "yes" ]; then
echo "ERROR: KEEP is deprecated" >&2
cronexit 1
fi
# send all stdout to /dev/null # send all stdout to /dev/null
if [ "${QUIET}" = "yes" ] || [ "${SILENT}" = "yes" ]; then if [ "${QUIET}" = "yes" ] || [ "${SILENT}" = "yes" ]; then
exec 1> /dev/null exec 1> /dev/null
@ -313,9 +317,7 @@ function cleanup {
rm /tmp/postdata 2>/dev/null >/dev/null rm /tmp/postdata 2>/dev/null >/dev/null
rm /tmp/raw 2>/dev/null >/dev/null rm /tmp/raw 2>/dev/null >/dev/null
rm /tmp/failcause 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
rm /tmp/kaka 2>/dev/null >/dev/null
fi
} }
trap cleanup EXIT trap cleanup EXIT
@ -329,8 +331,13 @@ trap cleanup EXIT
# user[remember_me] 0 # user[remember_me] 0
# commit Sign in # 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 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..." echo -n "Authenticating..."
# Clean old session # Clean old session
@ -356,7 +363,7 @@ if [ "${KEEP}" != "yes" -o ! -f /tmp/kaka ] && [ "${PUBLIC}" == "no" ]; then
cat /tmp/failcause >&2 cat /tmp/failcause >&2
cronexit 1 cronexit 1
fi fi
# If the system got here, it means the login was successfull, so we set the TOKEN variable to the authToken from the response # 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 # I use cut -c 14- to cut off the "authToken":" string from the grepped result, can probably be done in a different way
TOKEN=$(</tmp/failcause grep -ioe '"authToken":"[^"]*' | cut -c 14-) TOKEN=$(</tmp/failcause grep -ioe '"authToken":"[^"]*' | cut -c 14-)
@ -435,7 +442,7 @@ if [[ $FILENAME == *$INSTALLED_VERSION* ]] && [ "${FORCE}" != "yes" ] && [ ! -z
fi fi
if [ -f "${DOWNLOADDIR}/${FILENAME}" -a "${FORCE}" != "yes" ]; then if [ -f "${DOWNLOADDIR}/${FILENAME}" -a "${FORCE}" != "yes" ]; then
echo "File already exists, won't download." echo "File already exists (${FILENAME}), won't download."
if [ "${AUTOINSTALL}" != "yes" ]; then if [ "${AUTOINSTALL}" != "yes" ]; then
cronexit 2 cronexit 2
fi fi
@ -457,6 +464,14 @@ if [ "${SKIP_DOWNLOAD}" == "no" ]; then
echo "OK" echo "OK"
fi fi
if [ ! "${PLEXSERVER}" = "" -a "${AUTOINSTALL}" == "yes" ]; then
# Check if server is in-use before continuing (thanks @AltonV, @hakong and @sufr3ak)...
if ! wget --no-check-certificate -q -O - https://${PLEXSERVER}:32400/status/sessions | grep -q '<MediaContainer size="0">' ; 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 if [ "${AUTOINSTALL}" == "yes" ]; then
sudo ${DISTRO_INSTALL} "${DOWNLOADDIR}/${FILENAME}" sudo ${DISTRO_INSTALL} "${DOWNLOADDIR}/${FILENAME}"
fi fi