Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update while the version is the same #28

Closed
Cadkey opened this issue Apr 8, 2021 · 21 comments
Closed

Update while the version is the same #28

Cadkey opened this issue Apr 8, 2021 · 21 comments

Comments

@Cadkey
Copy link

Cadkey commented Apr 8, 2021

I run the bash to test

`Checking for a Plex Media Server update...

[ Initializing notification system ]
Notifications installed

[ Enabling Plex Pass releases ]
Found Plex Token

[ Retrieving version data ]
Available version: 1.22.2.4282-a97b03fad
Installed version: 1.22.2.4282-6000

New version available!

[ Finding release ]
{
"label": "Intel 64-bit (DSM 6.0 and newer)",
"build": "linux-x86_64",
"distro": "synology",
"url": "https://downloads.plex.tv/plex-media-server-new/1.22.2.4282-a97b03fad/synology/PlexMediaServer-1.22.2.4282-a97b03fad-x86_64_DSM6.spk",
"checksum": "3538303aae00573167770d018b668654406d4233"
}

[ Downloading release package ]

[ Verifying checksum ]
Checksum valid!

[ Installing package ]
/tmp/plex.i9qQb5/PlexMediaServer-1.22.2.4282-a97b03fad-x86_64_DSM6.spk install successfully

[ Restarting Plex Media Server ]
package Plex Media Server start successfully

[ Cleaning up ]
Removing /tmp/plex.i9qQb5

Done!`

I restart the bash to test, and the update starts again ...

`Checking for a Plex Media Server update...

[ Enabling Plex Pass releases ]
Found Plex Token

[ Retrieving version data ]
Available version: 1.22.2.4282-a97b03fad
Installed version: 1.22.2.4282-6000

New version available!

[ Finding release ]
{
"label": "Intel 64-bit (DSM 6.0 and newer)",
"build": "linux-x86_64",
"distro": "synology",
"url": "https://downloads.plex.tv/plex-media-server-new/1.22.2.4282-a97b03fad/synology/PlexMediaServer-1.22.2.4282-a97b03fad-x86_64_DSM6.spk",
"checksum": "3538303aae00573167770d018b668654406d4233"
}

[ Downloading release package ]

[ Verifying checksum ]
Checksum valid!

[ Installing package ]
/tmp/plex.q6sXaj/PlexMediaServer-1.22.2.4282-a97b03fad-x86_64_DSM6.spk install successfully

[ Restarting Plex Media Server ]
package Plex Media Server start successfully

[ Cleaning up ]
Removing /tmp/plex.q6sXaj

Done!`

The bash does not detect that the version is the same.
DS920+
DSM 6.2.4-25556

@notlebowski
Copy link

notlebowski commented Apr 11, 2021

I investegated this issue before I noticed this ticket.
My brother was having this issue

My brother installed your script on his Synology and turned to me because I "speak bash".
Even though there is no newer version it downloads it again and again

Checking for a Plex Media Server update...

[ Initializing notification system ]
Notifications installed

[ Enabling Plex Pass releases ]
Found Plex Token

[ Retrieving version data ]
Available version: 1.22.2.4282-a97b03fad
Installed version: 1.22.2.4282-6000

New version available!

The script correctly identifies the available version at plex.tv being 1.22.2.4282-a97b03fad

jq -r .nas.Synology.version <<< "$downloads_json" 
1.22.2.4282-a97b03fad

It then checks the already Installed version and that is indeed 1.22.2.4282-6000
Even if I use "strings" to look inside the spk-file

strings PlexMediaServer-1.22.2.4282-a97b03fad-armv7hf_DSM6.spk | grep '1\.22'
version="1.22.2.4282-6000"

I have found out that it then downloads "PlexMediaServer-1.22.2.4282-a97b03fad-armv7hf_DSM6.spk"
If I look into that file there is 1.22.2.4282-6000

I haven't looked that hard into Plex's versioning conventions to know this is a Plex screw-up or not, but I think it's safe to just ignore everything behind the dash
I proposed him this change to the script and now it's working properly.

EDITED

function set_available_version() {
  available_version=$(jq -r .nas.Synology.version <<< "$downloads_json")
  available_version=${available_version%-*}
  echo "Available version: $available_version"
}

function set_installed_version() {
  installed_version=$(synopkg version 'Plex Media Server')
  installed_version=${installed_version%-*}
  echo "Installed version: $installed_version"
}

It now does this:

[ Enabling Plex Pass releases ]
Found Plex Token

[ Retrieving version data ]
Available version: 1.22.2.4282
Installed version: 1.22.2.4282

Plex is up-to-date.

Done!

@Cadkey
Copy link
Author

Cadkey commented Apr 11, 2021

This does not work for me
available_version=${available_version-% *}
installed_version=${installed_version-% *}
But this yes
available_version=${available_version %%- *}
installed_version=${installed_version%%- *}
You have shown me the way to make everything work again perfectly.
Thank you
Edit: I have removed the bold text that interferes with the * (and no space in front *)

@notlebowski
Copy link

notlebowski commented Apr 11, 2021

This does not work for me:
available_version=${available_version-%}
installed_version=${installed_version-%}

No, because I wrote ${available_version-%*}

EDIT
I indeed wrote that, but it has to be %-*
Yours is incorrect as well

available_version=1.22.2.4282-6000
root@ns3:/usr/local/sbin# echo ${available_version%-*}
1.22.2.4282
echo ${available_version%%-}
1.22.2.4282-6000


I copy/pasted the wrong part out of the whatsapp chat I sent to my brother

@Cadkey
Copy link
Author

Cadkey commented Apr 11, 2021

Weird I wrote
available_version=${available_version%%-*}
And all the * have disappeared in my copy / paste
Mine works. I tried it before posting :-)

@notlebowski
Copy link

notlebowski commented Apr 11, 2021

you should post it as code in github to prevent it from getting mangled.
For that you need to select the text and click on the "smaller than" and "greater than " symbols.

image

In my case it wasn't mangled, I sent the correct code to my brother in whatsapp, but then did it a 2nd time with the dash and the percent swapped.

As he never used the 2nd time code it wasn't noticed that it was incorrect.
I however used that whatsapp window to copy/paste it in github.

When you prove or disprove something, you should lose all the superfluous code, keep it as simple as possible enter the lines on the prompt and then paste the commands and the result in the github window.
Next "codify" it to prevent it from getting mangled by the website.

Your double percent is working, but the 2nd percent is just superfluous as is proved here:

# available_version=1.22.2.4282-6000
# echo ${available_version%-*}
1.22.2.4282
# echo ${available_version%%-*}
1.22.2.4282

A single percent strips the shortest substring, a double percent strips the longest substring.
As there is only 1 substring, both will work.
To be honest, I had to look that one up ;-)
https://tldp.org/LDP/abs/html/string-manipulation.html

@jakemauer
Copy link

@notlebowski Thanks for writing that up, your changes worked for me. There may be some consequence for omitting build versions but I assume if they had to replace a build because of a bug or error they would just increment the smallest digit in the version number. Maybe @cowboy can chime in with a reason check against those build strings.

@oscaritoro
Copy link

@notlebowski LOL... I should have checked here before, would have saved me a couple of minutes debugging mine... Essentially came up with the same answer as you did, but yours is more "elegant"... I had gone with:
available_version=$(echo $available_version | sed 's/-.*$//')
After that worked for me I said to myself, "gee I wonder if someone else has reported this issue... if not then I probably should..."

@oscaritoro
Copy link

Side note: Pretty sure this is a side effect of the Plex team changing their spk build process after they started adding DSM7 builds... I noticed that DSM6 builds have "-6000" appended and DSM7 builds have "-7000" appended.

@oscaritoro
Copy link

oscaritoro commented Apr 26, 2021

@notlebowski / @cowboy : Another potential solution would be to get the "installed_version" from the actual binary that's currently installed:

/var/packages/Plex Media Server/target# ./Plex\ Media\ Server --version
v1.22.3.4392-d7c624def

@cowboy
Copy link
Owner

cowboy commented Apr 26, 2021

Thanks for looking into this!

I like the idea of running /var/packages/Plex\ Media\ Server/target/Plex\ Media\ Server --version to get the version. However, I'm concerned that the Plex Media Server app might somehow get installed into a different location on some machines, since I don't really know how synopkg install works.

@oscaritoro would you be interested in creating a PR to update the script set_installed_version function to do that? Be sure to test any changes you make locally! 😄

Just an FYI: I'm in the middle of moving, so it might be some time before my PC is all set up again. I'll check back in soon.

@notlebowski
Copy link

@notlebowski / @cowboy : Another potential solution would be to get the "installed_version" from the actual binary that's currently installed:

/var/packages/Plex Media Server/target# ./Plex\ Media\ Server --version
v1.22.3.4392-d7c624def

I don't really know what you mean by that.
if you think the script doesn't correctly detect the current version you're mistaken.
I did a "strings on the binary" and it shows it's correctly identifying the local version.

I'm convinced everything behind the dash is irrelevant. One shouldn't overthink the issue at hand.
You're really not missing any interesting update.

@cowboy
Copy link
Owner

cowboy commented Apr 27, 2021

@notlebowski I've dealt with enough weird inconsistencies while writing this script that I'm feeling very cautious about removing the number / hash from after the dash. Do you think there's a problem with running /var/packages/Plex\ Media\ Server/target/Plex\ Media\ Server --version? Because that seems like a more reliable solution to me.

@oscaritoro
Copy link

Thanks for looking into this!

I like the idea of running /var/packages/Plex\ Media\ Server/target/Plex\ Media\ Server --version to get the version. However, I'm concerned that the Plex Media Server app might somehow get installed into a different location on some machines, since I don't really know how synopkg install works.

@oscaritoro would you be interested in creating a PR to update the script set_installed_version function to do that? Be sure to test any changes you make locally! 😄

Just an FYI: I'm in the middle of moving, so it might be some time before my PC is all set up again. I'll check back in soon.

@cowboy I'll try to get one up this week. FYSA: I'll test on the only platform I currently have available, my DS918+ with DSM v6.2.4.

@oscaritoro
Copy link

@notlebowski / @cowboy : Another potential solution would be to get the "installed_version" from the actual binary that's currently installed:

/var/packages/Plex Media Server/target# ./Plex\ Media\ Server --version

v1.22.3.4392-d7c624def

I don't really know what you mean by that.

if you think the script doesn't correctly detect the current version you're mistaken.

I did a "strings on the binary" and it shows it's correctly identifying the local version.

I'm convinced everything behind the dash is irrelevant. One shouldn't overthink the issue at hand.

You're really not missing any interesting update.

@notlebowski the script correctly detects the version that the Plex Devs put into the synology package(.spk), but the Plex Devs recently changed the logic they used to set the version within the spk and it no longer matches their full versioning scheme... they take the final component of their version number (the one after the dash) and change it to either "-6000" for Synology DSM6 builds, or "-7000" for Synology DSM7 builds... what I wrote before was just another potential source of currently installed version that should match the version schemes for what they make available for download.

@oscaritoro
Copy link

@cowboy : Quick update on my progress investigating this:
1- I did some research on the Synology SPK process (it's structure and the install procedure) in order to understand what we can trust as a "location" of the Plex Media Server executable. Here's two useful links:
A. https://help.synology.com/developer-guide/synology_package/package_structure.html
B. https://help.synology.com/developer-guide/synology_package/scripts.html
2- From 1, took away that SPKs are tars and that they are required to have a "start-stop-status" script within. Suspected that it would have some logic within on how to determine the location of the executable.
3- Downloaded all 10 SPK files (5 for DSM6, 5 for DSM7; depending on architecture) for Synology (listed in https://plex.tv/api/downloads/5.json), extracted each one (renamed to .tar and used 7zip to extract), and reviewed/compared the contents of each "start-stop-status" script.
4- All 5 of the DSM6 specific packages have the following defined within:

# Base Plex installation directory
PLEX_DIR="/var/packages/Plex Media Server/target"

Though, interesting side note, they don't actually use that variable they defined to start the process... they all use then end up using a full path to start it:

   su plex -s /bin/sh -c \
  "export LC_ALL=en_US.utf8; \
   ... (redacted)
   /var/packages/Plex\ Media\ Server/target/Plex\ Media\ Server >/dev/null 2>&1 &"

5- All 5 of the DSM7 specific packages have new logic, as in different from DSM6 but same for all 5 of DSM7... A review of their "start-stop-status" script shows this as how they start the Plex Media Server:

  # Spawn service binary
  "$SYNOPKG_PKGDEST/Plex Media Server" >> /dev/null 2>&1 &

According to this: https://help.synology.com/developer-guide/synology_package/script_env_var.html , SYNOPKG_PKGDEST is "exported by Package Center and can be used in the scripts"... but, unfortunately, it doesn't appear to be usable inside "update-lex.sh"

I'll continue my investigation later... for now it seems that if I can find a way to access $SYNOPKG_PKGDEST then I can create a simple patch that would work on all synology NAS (DSM6 & DSM7)... other wise for now I have a way that would work in DSM6 but is questionable for DSM7...

... To Be Continued...

@oscaritoro
Copy link

Another note for those following along... This developer's guide page for DSM6 confirms the official location of package installs is indeed "/var/packages/[package identity]/target" : https://help.synology.com/developer-guide/integrate_dsm/manage_storage.html

@oscaritoro
Copy link

oscaritoro commented Apr 27, 2021

@cowboy : Found the DMS7 Beta Developer's Guide - https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware/DSM/7.0/enu/DSM_Developer_Guide_7_0_Beta.pdf
Page 76 (Package Filesystem Hierarchy Standard) shows that while some install destinations may differ now, they still plan to keep the /var/packages/[package_name]/target link pointing to the official location (and that's what the SYNOPKG_PKGDEST variable will point to)... so it should be safe (at least for now) to use that for both DSM6 and DSM7...
Given that, my solution will probably look as follows:

function set_installed_version() {
  #installed_version=$(synopkg version 'Plex Media Server')   # Previous solution; broken when Plex Devs modified synopkg version for DSM7 prep
  #installed_version=${installed_version%-*}   # Potential Patch to ignore the final component of the synopkg version
  installed_version=$(/var/packages/Plex\ Media\ Server/target/Plex\ Media\ Server --version)
  installed_version=${installed_version:1}
  echo "Installed version: $installed_version"
}

Thoughts?

@notlebowski
Copy link

like I wrote before, you're overthinking it.
Keep thinking what problem you're trying to solve.

You want to check if there's a newer Plex than the one you already have installed before starting an update procedure.

You don't want to start an update process for nothing. On the other hand you don't want to miss any interesting update.

It's absurd to think you're missing anything if you're ignoring what's behind the dash.

@oscaritoro
Copy link

oscaritoro commented Apr 27, 2021

@notlebowski : I'm tracking, this is most probably overkill and ignoring what's behind the dash may be enough... But lets explore a hypothetical scenario which I'm guessing might be what @cowboy might concerned with:
Plex Developers accidentally promote a build of a version that had an issue with the build process (not with their source)... As in, they "release", lets say, version "1.22.3.4392-b4db11d"... For a probably small but lets assume large enough window of time, this version is publicly available and some users get to download it... Then Plex notices the issue and re-runs their build process to fix it... Which ends up replacing the build number component, lets say they now post "1.22.3.4392-e117eb11d"... In that particular case the "simple solution" of ignoring past the dash would fail to pick up the new build.

oscaritoro added a commit to oscaritoro/synology-update-plex that referenced this issue Apr 27, 2021
- Get installed_version from PMS executable instead of synopkg
- Addresses cowboy#28
@cowboy
Copy link
Owner

cowboy commented May 11, 2023

I believe I've addressed this by just stripping the build suffix in 436280f. Please let me know if it's not fixed and I can revisit. (Sorry for the late reply!)

@cowboy cowboy closed this as completed May 11, 2023
@cowboy
Copy link
Owner

cowboy commented May 12, 2023

This fix has been addressed in the latest release https://github.com/cowboy/synology-update-plex/releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants