A new/revamped bash script to auto-update Plex on the Synology NAS platform

This is a heavily modified fork of Martino’s initial work as outlined here: Script to Auto Update Plex on Synology nas [rev6]


Look at or download the code from the GitHub project page: https://github.com/michealespinola/syno.plexupdate

Description:

This script takes into account many if not all of the issues I have previously read about for automatically updating Plex on the Synology NAS platform. This heavily modifed fork of this script intends to further simplify its use to not require any Bash script variable editing or SSH access to the Synology NAS. Everything should be accomplishable via the most basic DSM web administration by dropping this script onto the NAS and configuring a scheduled Task. This script is specifically for the official Synology package of the Plex Media Server. It utilizes Synology’s built-in tools to self-determine everything it needs to know about where Plex is located, how to update it, and to notify the system of updates or failures to update. If Plex is installed and properly configured, you will not have to edit this script for any details about the installation location of Plex. Public or Beta Update Channel selection follows what you have configured in Plex Media Server general settings.

Although only tested on my DS1019+, this script has been written with the intent to work on any compatible Synology platform. It reads your hardware architecture from the system and matches it against what it compatible with Plex. If its a part of the official Plex public or beta channel, this script will update it.

The default yet modifiable settings are that the script will not install an update unless it is 7 days old. This is a stability safety-catch so that if a release has a bug, it is assumed it will be discovered and fixed within 7 days. Otherwise, it keeps installation packages in its “Updates” directory for 60 days before automatic deletion.

Instructions for installation and use are in the GitHub README. The following are example outputs from running the script:


Not running as root:

admin@SYNOLOGY:~$ bash /var/services/homes/admin/scripts/bash/plex/syno.plexupdate/syno.plexupdate.sh

SYNO.PLEX UPDATER SCRIPT v2.3.0

 This script MUST be run as root - exiting...

Running as root:

admin@SYNOLOGY:~$ sudo -i
Password:
root@SYNOLOGY:~# bash /var/services/homes/admin/scripts/bash/plex/syno.plexupdate/syno.plexupdate.sh

SYNO.PLEX UPDATER SCRIPT v2.3.0

     Synology: DS1019+ (x86_64), DSM 6.2.3-25426 Update 2
   Script Dir: /var/services/homes/admin/scripts/bash/plex/syno.plexupdate
     Plex Dir: /volume1/Plex/Library/Application Support/Plex Media Server
  Running Ver: 1.20.0.3181-0800642ec
   Update Ver: 1.19.5.3112-b23ab3896 (Public Channel)
 Release Date: Mon, 20 Jul 2020 03:40:01 -0700

 No new version found.

Not running with minimum requirement DSM 5.0 or higher:

root@SYNOLOGY:~$ bash /var/services/homes/admin/scripts/bash/plex/syno.plexupdate/syno.plexupdate.sh

SYNO.PLEX UPDATER SCRIPT v2.3.0

 Plex Media Server requires DSM 5.0 minimum to install - exiting...

Processing no new version:

root@SYNOLOGY:~# bash /var/services/homes/admin/scripts/bash/plex/syno.plexupdate/syno.plexupdate.sh

SYNO.PLEX UPDATER SCRIPT v2.3.0

     Synology: DS1019+ (x86_64), DSM 6.2.3-25426 Update 2
   Script Dir: /var/services/homes/admin/scripts/bash/plex/syno.plexupdate
     Plex Dir: /volume1/Plex/Library/Application Support/Plex Media Server
  Running Ver: 1.20.0.3181-0800642ec
   Update Ver: 1.19.5.3112-b23ab3896 (Public Channel)
 Release Date: Mon, 20 Jul 2020 03:40:01 -0700

 No new version found.

Processing a new update that meets minimum age requirement:

root@SYNOLOGY:~# bash /var/services/homes/admin/scripts/bash/plex/syno.plexupdate/syno.plexupdate.sh

SYNO.PLEX UPDATER SCRIPT v2.3.0

     Synology: DS1019+ (x86_64), DSM 6.2.3-25426 Update 2
   Script Dir: /var/services/homes/admin/scripts/bash/plex/syno.plexupdate
     Plex Dir: /volume1/Plex/Library/Application Support/Plex Media Server
  Running Ver: 1.20.0.3133-fede5bdc7
   Update Ver: 1.20.0.3181-0800642ec (Beta Channel)
 Release Date: Tue, 04 Aug 2020 11:40:58 -0700

 Newer version found!

  New Package: PlexMediaServer-1.20.0.3181-0800642ec-x86_64.spk
  Package Age: 9 days (7 required for install)

INSTALLING NEW PACKAGE:
----------------------------------------
package Plex Media Server stop successfully
/volume1/Plex/Library/Application Support/Plex Media Server/Updates/PlexMediaServer-1.20.0.3181-0800642ec-x86_64.spk install successfully
package Plex Media Server start successfully
----------------------------------------

  Update from: 1.20.0.3133-fede5bdc7
           to: 1.20.0.3181-0800642ec succeeded!

Alternate response if the update does not meet minimum age requirement:

 "Update newer than 7 days - skipping..."

Any and all constructive feedback is greatly appreciated. It’s been a long time since I’ve worked with bash, so this has been a fun project.

4 Likes

Hi there, and thanks for working on this :slight_smile:
Having a little trouble with the script, wondering if any clue!
DS918+ latest DSM.
The script fails this way:

root@DISKSTATION:/var/services/homes/myusername/scripts/bash/plex/plexupdate# bash plexupdate.sh

SYNO.PLEX UPDATER SCRIPT v2.3.0

plexupdate.sh: line 67: [: -eq: unary operator expected
plexupdate.sh: line 71: [: -eq: unary operator expected
 Unable to indentify Server Update Channel (Public, Beta, etc) - exiting...

Thanks!

— Edit —
Resolved: setting up the Beta channel via the interface resolved it as it saved ButlerUpdateChannel=“8” into Preferences.xml .
Can I suggest the Public channel is assumed if no string is found :wink: ?

Yay, my first bug? :sweat_smile: I had thought I adequately trapped for an unrecognized channel value, but I guess I have to rethink what I did. You make a good point about defaulting to Public channel - there really is no reason not to do that. It is the actual default after all.

I’m glad you were able to work it out! (I never like the idea of someone being stuck). I’ll do some testing and tweaking this evening and post an updated fix shortly.

Thanks again for bringing this issue to my attention! The code (published on GitHub) now traps for a NULL value (if never tweaked in the website, it apparently never gets set in Preferences.xml). The default for a NULL value is now the Public Channel, as it would behave via the web interface as well.

This script has been moved to its own repository here:

nice script

Point of order if I may?

  1. DSM 5.2 is absolute minimum for two, soon to be discontinued completely, models.
  2. DSM 6.0+ is required for all others.
  3. These limitations are Synology imposed.
  printf " %s\n" "Plex Media Server requires DSM 5.0 minimum to install - exiting..."

Specifically, all Intel x86_64 platforms require the 64 bit download.
DSM 6.0+ is required for hardware transcoding support.

Ahh, thank you for that information! My criteria for DSM 5.0 is based off of the Plex for Synology download page as listed via here: https://www.plex.tv/media-server-downloads/

Screenshot of Plex for Synology selection where this is listed: https://i.imgur.com/2RZFcGi.png

So, do you recommend I should bump this requirement to 5.2 or go right for 6.0?

5.2 for 32 bit for specific models (DS214play and DS415play)
Every CPU which is 64 bit has been forced by Syno to 64 bit & DSM 6.0+

My recommendation is to only select the 32 bit upgrades if either of those 2 models.
All others have the DSM 6 / 64 bit requirement.

I would think a

MinVersion="6.0"

if [ "$Model" == "DS214Play" ] || [ "$Model" == "DS415Play" ]; then
  MinVersion="5.2"
fi

# Now continue with tests and selection.

Thank you for the reply and sample code! Just so I understand completely, these are minimum DSM version requirements for the hardware platforms, and not in direct relation to Plex?

I’m a bit leery about the constantly evolving platform requirements (hardware & DSM) outside of the basic Plex Media Server requirements. Supportability wise, there is less necessary upkeep for the updater code and more onus where I think it should be on the user/admin of the Synology.

I fear that if I start enforcing platform-specific DSM requirements, then I open myself to DSM support issues when things don’t go as expected for someone using the script.

It also sounds like, if I’m understanding your previous statement, that Synology is forcing 64-bit platforms to be at a certain DSM as well? They are all higher than Plex’s 5.0 minimum requirement, so I’m not sure I see the benefit of getting involved in DSM version enforcement.

Again, my apologies if I am mixing things up here between Plex and Synology platform requirements.

The fundamental requirement for every Plex Linux package is glibc > 2.14.1.
There are a number of 32 bit platforms which never upgraded above that in spite of how old 2.14.1 is.

Technically, our web page should change but some systems are still functional in spite of being revision locked.

What I package for is

[chuck@lizum files.342]$ cat INFO.in 
package="Plex Media Server"
description="Plex organizes all of your personal media so you can easily access and enjoy it."
maintainer="Plex Inc"
adminport=32400
adminurl=web
firmware=6.0-7321
helpurl="https://plex.tv/"
[chuck@lizum files.343]$ 

If you want to code to that standard (firmware version), I would greatly appreciate it.
It would save the user the trouble of downloading the SPK only to learn DSM is going to spit it out later anyway

Synology’s DSM 6.0 gave us udev. I leverage udev for access to HW transcoding (/dev/dri/renderD128)

DSM 5.2 requires running in the administrators group (which is awkward and undesirable for many). I’ve lowered plex down to that of a non-privileged user account – using udev to set the access rules for USB tuners and Transcoding.

Got it, and thank you very much for the detail. I would be more than happy to adhere to a standard firmware version per your recommendation.

The INFO file will always have the firmware= requirement info (per Syno SDK)

I’m using script v2.3.2 and am getting the same error:

bash syno.plexupdate.sh

SYNO.PLEX UPDATER SCRIPT v2.3.2

syno.plexupdate.sh: line 74: [: : integer expression expected

syno.plexupdate.sh: line 78: [: : integer expression expected

Unable to indentify Server Update Channel (Public, Beta, etc) - exiting...

I do not wish to use the Beta versions, just the public releases.

This should now be fixed in v2.3.3. The NUL value problem came back when I changed the channel comparison to strings.

Fantastic, that works now with version 2.3.3. Thanks for the quick fix.

Is there any way to autoupdate the script itself in line with your github releases?

Not at the moment. I plan on incorporating some command line options, and an “–update” type feature would be something nice to have. I’ll keep it in mind if I can figure it out how it would work.

1 Like

Your question intrigued me (and I’m bored on a very hot day :sweat_smile:) so I’ve started working on how to similarly check GitHub for updates following the same logic I am using to check for Plex updates. So far so good!

I’m considering following the same 7-days rule; that the script won’t self-update unless 7 days since the latest official release (not code updates) have passed. Does this sound reasonable from your perspective? I’m trying to not be inside my own head about this and not do goofy things that would actually be impractical or counter-intuitive for most people.

I anticipate it will be an option that can be toggled via a command-line flag for those that do or do not want a self-updating update script. The default would be to not.

Might want to update your first post with the link to the non-discontinued Github page.

I assume I can run the scheduled script with no --plex pass flag, right?

As for the seven-day rule, for the script, what would happen if Plex released a new update every six days for a month? Would they be skipped until it had been seven days since the last update?

As for the script, keeping it to a similar rule is a good idea: seven days gives you ample time to fix any issues. Adding a flag for users to put in their scheduled bash script would make it easy to choose if they want auto-update or not.
What sort of flow would you consider for this auto-update of your script, to avoid having a million files piling up in the folder? Is there a way to clean up the old script and rename the updated script?

Thank you, yes I guess I should update the top of the post - I forgot I could do that!

Anything involving a Plex Pass is automatic and follows however you have configured your Plex Media Server under the General settings section. The default there is the “Public” update channel, which you can change to “Beta” (which is what would require a Plex Pass). If you have that set to Beta, the update script will automatically detect that and use your Plex Pass as configured in your account settings. It’s fully automated in that respect.

Yes, if Plex updated every (6) days for a month, then the script would not update at all that month based on the (7) day default setting. Currently, you would have to edit a variable at the top of the script to change that - but it’s going to soon be more easily manipulated with a flag option. I don’t see that as an issue if you want a stable Plex server, but I’m open to conversation about it.

The script automatically deletes older saved Plex Media Server update files. The current default is based on an age of (60) days, which is another editable variable at the top of the script. I see this as a less and less useful cache. You cannot force the install of an older package on a Synology (as far as I know or have tried), so keeping (60) days worth of older files is actually pointless. I will likely modify this in the upcoming weeks once other aspects of the script are completed.

Anything with the old script name currently has to be performed manually. I am unaware of how to edit DSM tasks from the terminal with Bash, so the update Task has to be manually edited. Or, you could save the new script as the old name. If the script self-update works the way I would like it to, it will honor whatever name you save it as.

Next version highlights:

  1. The script will conform more strictly to DSM version requirements (thanks @ChuckPa!)
  2. The script will report new features and bugfix descriptions associated with the update taken from JSON object info. This info will be seen in the update email if configured for the Task.
  3. The script will check and report its own version status against GitHub releases (thanks @Kynch!), although full self-updating might not be available yet
  4. The Updates cache dir has been moved under the Script dir for direct visibility to the admin

Sample debug output:

SYNO.PLEX UPDATER SCRIPT v3.0.0

       Script: syno.plexupdate.sh v3.0.0
   Script Dir: /volume1/homes/admin/scripts/bash/plex/syno.plexupdate
  Running Ver: 3.0.0
   Online Ver: 2.3.3
  Online Date: 2020-09-06 06:34:14-07:00 (2+ days old)

     Synology: DS1019+ (x86_64), DSM 6.2.3-25426 Update 2
     Plex Dir: /volume1/Plex/Library/Application Support/Plex Media Server
   Plex Token: ###################
  Running Ver: 1.20.1.3252-a78fef9a9
   Online Ver: 1.20.1.3252-a78fef9a9 (Public Channel)
  Online Date: 2020-08-27 06:58:26-07:00 (12+ days old)

 No new version found.

Sample output of new update-related info:

  Update from: 1.##.#.####-#########
           to: 1.20.1.3252-a78fef9a9 succeeded!

NEW FEATURES:
----------------------------------------
(Filters) Add 'trash' filter to 'custom filters' (#11103)
(Library) Store external ids for items in new Plex Movie libraries.
----------------------------------------

FIXED FEATURES:
----------------------------------------
(Analysis) Chapter and index thumbnails would not get re-generated after replacing a file with another with the same filename (#8922)
(Collections) Setting a collection title or summary to a blank value would make it inaccessible.
(DVR) Corrected typo in Detect Commercials settings description (#11804).
(DVR) Fixed an issue where Plex Commercial Skipper would unexpectedly exit with an error code (#11259) (#11151)
[...snipped...]
----------------------------------------

I anticipate the update will be released in about a week.