Skip to content

Instantly share code, notes, and snippets.

@davenicoll
Last active May 6, 2021 00:21
Show Gist options
  • Save davenicoll/06048fd709234f738f723fe884fb2379 to your computer and use it in GitHub Desktop.
Save davenicoll/06048fd709234f738f723fe884fb2379 to your computer and use it in GitHub Desktop.
Automatically update plex on synology NAS
#!/bin/bash
mkdir -p /tmp/plex/ > /dev/null 2>&1
rm -rf /tmp/plex/* > /dev/null 2>&1
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")
jq=$(curl -s ${url})
newversion=$(echo $jq | jq -r .nas.Synology.version)
echo New Ver: $newversion
curversion=$(synopkg version "Plex Media Server")
echo Cur Ver: $curversion
if [ "$newversion" != "$curversion" ]
then
echo New Version Available
/usr/syno/bin/synonotify PKGHasUpgrade '{"%PKG_HAS_UPDATE%": "Plex"}'
CPU=$(uname -m)
url=$(echo "${jq}" | jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${CPU}"'") | .url')
/bin/wget $url -P /tmp/plex/
/usr/syno/bin/synopkg install /tmp/plex/*.spk && /usr/syno/bin/synopkg start "Plex Media Server" && rm -rf /tmp/plex/*
else
echo No New Version
fi
exit
@davenicoll
Copy link
Author

davenicoll commented Jan 15, 2021

crontab:

cat /etc/crontab
0 3 * * * root /volume1/Script/plexupdate.sh 2>&1 &

rev1 fix
rev2 notification
rev3 cpu based url (x86 or x32)
rev4 extract token in better way
rev5 compatible with all CPU
rev6 typo

IMPORTANT:
Change the Trust Level to Any publisher in Package Center > Settings
and
Add Plex key https://support.plex.tv/articles/205165858-how-to-add-plex-s-package-signing-public-key-to-synology-nas-package-center/?_ga=2.162387836.1194402430.1571755454-1617362326.1543598076

Source: https://forums.plex.tv/t/script-to-auto-update-plex-on-synology-nas-rev6/479748

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment