Skip to content

Instantly share code, notes, and snippets.

@seanhamlin
Last active May 10, 2023 11:19
Show Gist options
  • Save seanhamlin/dcde16a164377dca87a798a4c2ea051c to your computer and use it in GitHub Desktop.
Save seanhamlin/dcde16a164377dca87a798a4c2ea051c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to Auto Update Plex on Synology NAS
#
# Must be run as root.
#
# @author Martino https://forums.plex.tv/u/Martino
# @see https://forums.plex.tv/t/script-to-auto-update-plex-on-synology-nas-rev4/479748
mkdir -p /tmp/plex/
TOKEN=$(cat /volume1/Plex/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml | grep -oP 'PlexOnlineToken="\K[^"]+')
URL=$(echo "https://plex.tv/api/downloads/5.json?channel=plexpass&X-Plex-Token=${TOKEN}")
JSON=$(curl -s ${URL})
NEW_VERSION=$(echo $JSON | jq -r .nas.Synology.version)
echo "New version: ${NEW_VERSION}"
CURRENT_VERSION=$(synopkg version "Plex Media Server")
echo "Current version: ${CURRENT_VERSION}"
if [ "${NEW_VERSION}" != "${CURRENT_VERSION}" ] ; then
echo "New version available!"
/usr/syno/bin/synonotify PKGHasUpgrade '{"[%HOSTNAME%]": $(hostname), "[%OSNAME%]": "Synology", "[%PKG_HAS_UPDATE%]": "Plex", "[%COMPANY_NAME%]": "Synology"}'
CPU=$(uname -m)
if [ "$CPU" = "x86_64" ] ; then
URL=$(echo $JSON | jq -r ".nas.Synology.releases[1] | .url")
else
URL=$(echo $JSON | jq -r ".nas.Synology.releases[0] | .url")
fi
/bin/wget $URL -P /tmp/plex/
/usr/syno/bin/synopkg install /tmp/plex/*.spk
sleep 30
/usr/syno/bin/synopkg start "Plex Media Server"
rm -rf /tmp/plex
else
echo "Plex is up to date."
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment