For anyone else who would like to automate updating their Debian (Ubuntu) servers to the latest Plex Pass version, here’s my automation script (works great with cron, uses curl, jq, and dpkg):
#!/bin/bash
set -e
USERNAME="username"
PASSWORD="password"
DISTRO="ubuntu"
BUILD="linux-ubuntu-x86_64"
CLIENT_ID="$USERNAME-plex-updater-v1"
PRODUCT="Plex Updater"
VERSION="v1"
SIGNIN_URL="https://plex.tv/users/sign_in.json"
RELEASES_URL="https://plex.tv/api/downloads/1.json?channel=plexpass"
DOWNLOAD_DIR="/tmp"
echo "Signing in to plex.tv..."
SIGNIN_RESPONSE=$(curl -s \
-H "X-Plex-Client-Identifier: $CLIENT_ID" \
-H "X-Plex-Product: $PRODUCT" \
-H "X-Plex-Version: $VERSION" \
-d "user%5Blogin%5D=$USERNAME" \
-d "user%5Bpassword%5D=$PASSWORD" \
$SIGNIN_URL)
TOKEN=$(jq -r ".user.authentication_token" <<< $SIGNIN_RESPONSE)
echo "Getting releases..."
RELEASES_RESPONSE=$(curl -s \
-H "X-Plex-Client-Identifier: $CLIENT_ID" \
-H "X-Plex-Product: $PRODUCT" \
-H "X-Plex-Version: $VERSION" \
-H "X-Plex-Token: $TOKEN" \
$RELEASES_URL)
CURRENT_VERSION=$(jq -r ".computer.Linux.version" <<< $RELEASES_RESPONSE)
INSTALLED_VERSION=$(dpkg-query --showformat='${Version}' --show plexmediaserver)
echo "Current version: $CURRENT_VERSION"
echo "Installed version: $INSTALLED_VERSION"
if [ "$CURRENT_VERSION" == "$INSTALLED_VERSION" ]
then
echo "Plex is up-to-date."
exit 0
fi
echo "Updating Plex..."
PACKAGE_URL=$(jq -r ".computer.Linux.releases[] | select(.distro == \"$DISTRO\") | select(.build == \"$BUILD\").url" <<< $RELEASES_RESPONSE)
PACKAGE_NAME=$(basename $PACKAGE_URL)
PACKAGE_PATH="$DOWNLOAD_DIR/$PACKAGE_NAME"
curl \
-H "X-Plex-Client-Identifier: $CLIENT_ID" \
-H "X-Plex-Product: $PRODUCT" \
-H "X-Plex-Version: $VERSION" \
-H "X-Plex-Token: $TOKEN" \
-o $PACKAGE_PATH $PACKAGE_URL
dpkg -i $PACKAGE_PATH
echo "Plex successfully updated."
Maybe there’s a better version of this floating around somewhere else, however I figured it couldn’t hurt to post.