First version supporting the new format

Intial version supporting JSON endpoints
This commit is contained in:
Henric Andersson 2016-06-24 04:21:16 -07:00
commit 373a147f6d
2 changed files with 35 additions and 44 deletions

View file

@ -42,10 +42,11 @@ There are a few other options for the more enterprising user. Setting any of the
Normally plexupdate.sh will avoid downloading a file it already has or if it's the same as the installed version, but this allows you to override. Normally plexupdate.sh will avoid downloading a file it already has or if it's the same as the installed version, but this allows you to override.
- PRINT_URL - PRINT_URL
Authenticate, fetch the download URL, print it, and then exit. Authenticate, fetch the download URL, print it, and then exit.
- REDHAT_INSTALL - DISTRO_INSTALL
The commandline used to install .rpm packages, only change if you need special options The commandline used to install packages, only change if you need special options. Natively supports Debian and Redhat, so need to set this for these systems.
- DEBIAN_INSTALL NOTE! If you define this, you MUST define DISTRO and BUILD
The commandline used to install .deb packages, only change if you need special options - DISTRO and BUILD
Override which version to download
Most of these options can be specified on the command-line as well, this is just a more convenient way of doing it if you're scripting it. Which brings us to... Most of these options can be specified on the command-line as well, this is just a more convenient way of doing it if you're scripting it. Which brings us to...

View file

@ -48,7 +48,6 @@ DOWNLOADDIR="."
# Defaults # Defaults
# (aka "Advanced" settings, can be overriden with config file) # (aka "Advanced" settings, can be overriden with config file)
RELEASE="64"
KEEP=no KEEP=no
FORCE=no FORCE=no
PUBLIC=no PUBLIC=no
@ -63,6 +62,7 @@ SILENT=no
# Default options for package managers, override if needed # Default options for package managers, override if needed
REDHAT_INSTALL="yum -y install" REDHAT_INSTALL="yum -y install"
DEBIAN_INSTALL="dpkg -i" DEBIAN_INSTALL="dpkg -i"
DISTRO_INSTALL=""
# Sanity, make sure wget is in our path... # Sanity, make sure wget is in our path...
wget >/dev/null 2>/dev/null wget >/dev/null 2>/dev/null
@ -76,21 +76,15 @@ if [ -f ~/.plexupdate ]; then
source ~/.plexupdate source ~/.plexupdate
fi fi
if [ "${RELEASE}" = "64-bit" ]; then if [ ! "${RELEASE}" = "" ]; then
echo "WARNING: RELEASE=64-bit is deprecated, use RELEASE=64 instead" echo "ERROR: RELEASE keyword is deprecated, use DISTRO and BUILD"
RELEASE="64"
elif [ "${RELEASE}" = "32-bit" ]; then
echo "WARNING: RELEASE=32-bit is deprecated, use RELEASE=32 instead"
RELEASE="32"
elif [ "${RELEASE}" != "64" -a "${RELEASE}" != "32" ]; then
echo "ERROR: Use of RELEASE=${RELEASE} will no longer work"
exit 255 exit 255
fi fi
# Current pages we need - Do not change unless Plex.tv changes again # Current pages we need - Do not change unless Plex.tv changes again
URL_LOGIN=https://plex.tv/users/sign_in URL_LOGIN=https://plex.tv/users/sign_in
URL_DOWNLOAD=https://plex.tv/downloads?channel=plexpass URL_DOWNLOAD=https://plex.tv/api/downloads/1.json?channel=plexpass
URL_DOWNLOAD_PUBLIC=https://plex.tv/downloads URL_DOWNLOAD_PUBLIC=https://plex.tv/api/downloads/1.json
usage() { usage() {
echo "Usage: $(basename $0) [-aCfhkopqsSuU]" echo "Usage: $(basename $0) [-aCfhkopqsSuU]"
@ -101,7 +95,6 @@ usage() {
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 " -k Reuse last authentication"
echo " -o 32-bit version (default 64 bit)"
echo " -p Public Plex Media Server version" echo " -p Public Plex Media Server version"
echo " -q Quiet mode. No stdout, only stderr and exit codes" echo " -q Quiet mode. No stdout, only stderr and exit codes"
echo " -r Print download URL and exit" echo " -r Print download URL and exit"
@ -125,7 +118,6 @@ do
(-d) AUTODELETE=yes;; (-d) AUTODELETE=yes;;
(-f) FORCE=yes;; (-f) FORCE=yes;;
(-k) KEEP=yes;; (-k) KEEP=yes;;
(-o) RELEASE="32";;
(-p) PUBLIC=yes;; (-p) PUBLIC=yes;;
(-q) QUIET=yes;; (-q) QUIET=yes;;
(-r) PRINT_URL=yes;; (-r) PRINT_URL=yes;;
@ -189,7 +181,7 @@ fi
# Sanity check # Sanity check
if [ "${EMAIL}" == "" -o "${PASS}" == "" ] && [ "${PUBLIC}" == "no" ] && [ ! -f /tmp/kaka ]; then if [ "${EMAIL}" == "" -o "${PASS}" == "" ] && [ "${PUBLIC}" == "no" ] && [ ! -f /tmp/kaka ]; then
echo "Error: Need username & password or -k option to download PlexPass version. Otherwise run with -p to download public version." >&2 echo "Error: Need username & password to download PlexPass version. Otherwise run with -p to download public version." >&2
exit 1 exit 1
fi fi
@ -209,15 +201,26 @@ if [ -z "${DOWNLOADDIR}" ]; then
exit 1 exit 1
fi fi
if [ "${DISTRO_INSTALL}" == "" ]; then
# Detect if we're running on redhat instead of ubuntu # Detect if we're running on redhat instead of ubuntu
if [ "${DISTRO}" == "" -o "${BUILD}" == "" ]; then
if [ -f /etc/redhat-release ]; then if [ -f /etc/redhat-release ]; then
REDHAT=yes; REDHAT=yes
PKGEXT='.rpm' BUILD='linux-ubuntu-x86_64'
RELEASE="Fedora${RELEASE}" DISTRO="redhat"
DISTRO_INSTALL="${REDHAT_INSTALL}"
else else
REDHAT=no; REDHAT=no
PKGEXT='.deb' BUILD='linux-ubuntu-x86_64'
RELEASE="Ubuntu${RELEASE}" DISTRO="ubuntu"
DISTRO_INSTALL="${DEBIAN_INSTALL}"
fi
fi
else
if [ "${DISTRO}" == "" -o "${BUILD}" == "" ]; then
echo "Using custom DISTRO_INSTALL requires custom DISTRO and BUILD too"
exit 255
fi
fi fi
# Useful functions # Useful functions
@ -272,20 +275,10 @@ if [ "${KEEP}" != "yes" -o ! -f /tmp/kaka ] && [ "${PUBLIC}" == "no" ]; then
# Clean old session # Clean old session
rm /tmp/kaka 2>/dev/null rm /tmp/kaka 2>/dev/null
# Get initial seed we need to authenticate
SEED=$(wget --save-cookies /tmp/kaka --keep-session-cookies ${URL_LOGIN} -O - 2>/dev/null | grep 'name="authenticity_token"' | sed 's/.*value=.\([^"]*\).*/\1/')
if [ $? -ne 0 -o "${SEED}" == "" ]; then
echo "Error: Unable to obtain authentication token, page changed?" >&2
exit 1
fi
# Build post data # Build post data
echo -ne >/tmp/postdata "$(keypair "utf8" "✓" )" echo -ne >/tmp/postdata "&$(keypair "user[login]" "${EMAIL}" )"
echo -ne >>/tmp/postdata "&$(keypair "authenticity_token" "${SEED}" )"
echo -ne >>/tmp/postdata "&$(keypair "user[login]" "${EMAIL}" )"
echo -ne >>/tmp/postdata "&$(keypair "user[password]" "${PASS}" )" echo -ne >>/tmp/postdata "&$(keypair "user[password]" "${PASS}" )"
echo -ne >>/tmp/postdata "&$(keypair "user[remember_me]" "0" )" echo -ne >>/tmp/postdata "&$(keypair "user[remember_me]" "0" )"
echo -ne >>/tmp/postdata "&$(keypair "commit" "Sign in" )"
# Authenticate # Authenticate
wget --load-cookies /tmp/kaka --save-cookies /tmp/kaka --keep-session-cookies "${URL_LOGIN}" --post-file=/tmp/postdata -O /tmp/raw 2>/dev/null wget --load-cookies /tmp/kaka --save-cookies /tmp/kaka --keep-session-cookies "${URL_LOGIN}" --post-file=/tmp/postdata -O /tmp/raw 2>/dev/null
@ -313,9 +306,10 @@ fi
# Extract the URL for our release # Extract the URL for our release
if [ "${CRON}" = "no" ]; then if [ "${CRON}" = "no" ]; then
echo -n "Finding download URL for ${RELEASE}..." echo -n "Finding download URL to download..."
fi fi
DOWNLOAD=$(wget --load-cookies /tmp/kaka --save-cookies /tmp/kaka --keep-session-cookies "${URL_DOWNLOAD}" -O - 2>/dev/null | grep "${PKGEXT}" | grep -m 1 "${RELEASE}" | sed "s/.*href=\"\([^\"]*\\${PKGEXT}\)\"[^>]*>.*/\1/" )
DOWNLOAD=$(wget --load-cookies /tmp/kaka --save-cookies /tmp/kaka --keep-session-cookies "${URL_DOWNLOAD}" -O - 2>/dev/null | grep -ioe '"label"[^}]*' | grep -i "\"distro\":\"${DISTRO}\"" | grep -i "\"build\":\"${BUILD}\"" | grep -m1 -ioe 'https://[^\"]*' )
if [ "${CRON}" = "no" ]; then if [ "${CRON}" = "no" ]; then
echo -e "OK" echo -e "OK"
fi fi
@ -383,11 +377,7 @@ if [ "${SKIP_DOWNLOAD}" == "no" ]; then
fi fi
if [ "${AUTOINSTALL}" == "yes" ]; then if [ "${AUTOINSTALL}" == "yes" ]; then
if [ "${REDHAT}" == "yes" ]; then sudo ${DISTRO_INSTALL} "${DOWNLOADDIR}/${FILENAME}"
sudo ${REDHAT_INSTALL} "${DOWNLOADDIR}/${FILENAME}"
else
sudo ${DEBIAN_INSTALL} "${DOWNLOADDIR}/${FILENAME}"
fi
fi fi
if [ "${AUTODELETE}" == "yes" ]; then if [ "${AUTODELETE}" == "yes" ]; then