Script to Auto Update Plex on Synology nas [rev6]

I found this script, while checking to see how to get my Plex to Auto-Update. Made some small changes, so that it checks the version to make sure it is higher & not just different. Also did some formatting & removed the sleep function as it is a hack, imo.

Here is the updated version - https://github.com/nitantsoni/plexupdate -

3 Likes

Thanks for the advice! The part that gets the Plex Token still wasn’t working for me, so I just found it manually and pasted it in (I guess it doesn’t change?) The script seems to run through happily now without errors, finding the correct current and new versions numbers - so I just need to wait for Plex to release an update to see if the downloading / updating part works 
 !

1 Like

Brekus,

Quick question: How did the variable “$token”, get set, in your example?

To clarify, the following link describes the process for determining your own plex-pass-token, however, I was just wondering if you declared $token as an absolute earlier in your script, and didn’t include that declaraion (for obvious reasons), or if you had a programatic mechanism for dynamically retrieving your token, in the script (which now that I say it
seems unlikely).

Thanks.

-M

Sorry @monkeyhat, I edited my comment to fix the method for finding your PMS directory and extracting the token.

$token was set by using this line from the original post. I haven’t had to change it as it has been working for me without issue. I see others are having issues not sure why though.

token=$(cat /volume1/Plex/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml | grep -oP ‘PlexOnlineToken="\K[^"]+’)

I did however have to change my volume since I have plex installed on another one.

I try the script with the last update and get 289 error code when install

I use the last version of https://github.com/martinorob/plexupdate

Some one has the same error?

Log:

New Ver: 1.18.2.2015-5a99a9a46
Cur Ver: 1.18.1.1973-0f4abfbcc
New Vers Available
--2019-11-08 09:43:37--  https://downloads.plex.tv/plex-media-server-new/1.18.2.2015-5a99a9a46/synology/PlexMediaServer-1.18.2.2015-5a99a9a46-x86_64.spk
Resolving downloads.plex.tv... 104.18.157.41, 104.18.156.41, 2606:4700::6812:9c29, ...
Connecting to downloads.plex.tv|104.18.157.41|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 124958720 (119M) [binary/octet-stream]
Saving to: '/volume1/tmp/plex/PlexMediaServer-1.18.2.2015-5a99a9a46-x86_64.spk'

PlexMediaServer-1.1 100%[===================>] 119.17M  60.8MB/s    in 2.0s    

2019-11-08 09:43:39 (60.8 MB/s) - '/volume1/tmp/plex/PlexMediaServer-1.18.2.2015-5a99a9a46-x86_64.spk' saved [124958720/124958720]

Failed to install package /volume1/tmp/plex/PlexMediaServer-1.18.2.2015-5a99a9a46-x86_64.spk, error = [289]
package Plex Media Server start successfully

Try this:

Thank you. That worked.

Hey @euphnutz - just wanted to say, there was a Plex server update today for the first time since I added this script, ant it worked perfectly. So thanks for your help!

2 Likes

I gave up on the script since it’s not exactly built for aarch.

EDIT: Looks like yours isn’t doing plex-pass versions, the original is, makes sense. Carry on, ha. I do like how yours is written to help weed out any bugs, very clean. Much appreciated!

I added the token line and updated the URL, now its appearing and working as expected:

token=$(cat /volume1/Plex/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml | grep -oP ‘PlexOnlineToken=“\K[^”]+’)
url=“https://plex.tv/api/downloads/5.json?channel=plexpass&X-Plex-Token=$token”

I tried yours, but with the recent update it outputs the following:

root@NAS01:/volume1/Scripts# bash plexupdate-new.sh
Latest version: 1.18.1.2019
Current version: 1.18.2.2029
No new version available

Not sure why yours shows an old version?

Martino’s original script outputs:

root@NAS01:/volume1/Scripts# bash plexupdate.sh
New Ver: 1.18.2.2029-36236cc4c
Cur Ver: 1.18.2.2029-36236cc4c
No New Ver

Hey there, once included all of the modifications above @mpalensh , today there is an update, however I can see the following error.

New version: 1.18.2.2029-36236cc4c
Current version: 1.18.2.2015-5a99a9a46
New version available!
parse error: Invalid numeric literal at line 1, column 4
http://: Invalid host name.
Failed to install package /tmp/plex/*.spk, error = [150]

I can see the script has an https:// to be honest, not sure why you would see that http:// to be honest


To be clear, my full, modifications included, script, follows.

#!/bin/bash

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)
	URL=$(echo “${JSON}” | 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 "Plex is up to date."
fi
exit 0

Any idea :slight_smile: ?

[edit]
Changing

	URL=$(echo “${JSON}” | jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${CPU}"'") | .url')

to

	URL=$(echo "${JSON}" | jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${CPU}"'") | .url')

did remove the parsing error, however wget is still lamenting an invalid http:// host name.

@ErMeglio you need to be sure that when you reference your variables (cpu and CPU below) that they are the same case as when they are declared:

cpu=$(uname -m)
URL=$(echo "${JSON}" | jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${CPU}"'") | .url')

Also, you should change this line:

TOKEN=$(cat /volume1/Plex/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml | grep -oP 'PlexOnlineToken="\K[^"]+')

To this so that it intelligently finds your PMS install dir:

PMS_PATH=$(find / -path '*/Plex Media Server' -print -quit 2>/dev/null)
TOKEN=$(grep -Po 'PlexOnlineToken="\K[^"]+' "${PMS_PATH}"/Preferences.xml)

Thanks a lot for the help @euphnutz !
Unfortunately this line still doesn’t work:

URL=$(echo “${JSON}” | jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${CPU}"'") | .url')

as it returns the following:

New version: 1.18.2.2029-36236cc4c
Current version: 1.18.2.2015-5a99a9a46
New version available!
+1
CPU is: x86_64
+2
parse error: Invalid numeric literal at line 1, column 4
URL is:
+3
http://: Invalid host name.
+4
Failed to install package /tmp/plex/*.spk, error = [150]

The tip re. the case has still helped me resolve by swapping to the standard double quotes around ${JSON}:

URL=$(echo "${JSON}" | jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${CPU}"'") | .url')

The update has gone through - happy days :slight_smile:

@ErMeglio did you change this line?

cpu=$(uname -m)

To this?:

CPU=$(uname -m)

The quoting in the jq statement is not the issue. Your variable needs to be all caps since you reference it in all caps in the jq statement.

Hey, thanks for the follow-up! I had changed CPU to capitals after learning capitals do matter, yes :slight_smile:
However nope, the line

URL=$(echo “${JSON}” | jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${CPU}"'") | .url')

was throwing the error:

parse error: Invalid numeric literal at line 1, column 4

so I have simply changed it to:

URL=$(echo "${JSON}" | jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${CPU}"'") | .url')

and it all works well now!

Weird. The 2 lines look exactly the same to me. :joy: Glad it’s working for you now.

Edit: Ohhh, I see now. There are some weird quotes surrounding ${JSON} in the non-working example.

Edit 2: I fixed it in my previous comments.

1 Like

Worked like a charm
THANK YOU Nitantsoni and Martino!