michealespinola / syno.plexupdate

A script to automagically update Plex Media Server on Synology NAS
GNU General Public License v3.0
273 stars 23 forks source link

some random self update ideas #11

Closed justme-1968 closed 2 years ago

justme-1968 commented 3 years ago

here are some random ideas for the self update that just came to me when trying to get the 3.0.2 fix for the version umbers:

michealespinola commented 3 years ago

My thoughts:

  1. Separate minimum age for script updates / I've been thinking of this, but I'm unsure of the value. Either you want to protect yourself with a minimum age or not. If you don't trust Plex devs, you probably should trust me even less. 😅 Again, I am considering it, but I have been unable to quantify the value of it.
  2. Download everything no matter what to a locale archive / The purpose of the script isn't to create an offline version archive of everything or alert the user to new versions. The purpose is to upgrade if stability can be safely assumed. If a version is released only a few days before a subsequent update is released - what is the value of downloading that version? If a [Public channel] version is stable and worth saving (for rollback purposes), it will remain without additional updates for at least a week. Betas are a different story and perhaps should use a shorter minimum age if that's the update channel you want to use.
    • As a point of reference, I recently bamboozled myself by updating to Public channel PMS 1.22.1.4228 without waiting the 7 days I normally wait. It turns out that PMS .4228 would crash immediately when any of my up-to-date android clients connected to it (it broke mobile and Nvidia Shield connections). It was a nightmare. Android client updates would fix the Nvidia Shield, but mobile clients still would crash the PMS. 4228 is the current release Public version, but Plex support recommends you avoid it.
  3. Update the script and restart it before checking Plex updates / It seems logical. I'm not sure how to do it though.
  4. Force immediate update with a command-line switch / I've been thinking about doing this.
lordvandal commented 3 years ago

One suggestion regarding the third point:

3. **Update the script and restart it before checking Plex updates** / It seems logical. I'm not sure how to do it though.

The command you probably want to use is: exec "$0" "$@"

The exec bash builtin command replaces the current program with a new one.

$0 and $@ are bash special parameters:

($0) Expands to the name of the shell or shell script. This is set at shell initialization. If Bash is invoked with a file of commands (see Shell Scripts), $0 is set to the name of that file. If Bash is started with the -c option (see Invoking Bash), then $0 is set to the first argument after the string to be executed, if one is present. Otherwise, it is set to the filename used to invoke Bash, as given by argument zero.

($@) Expands to the positional parameters, starting from one. In contexts where word splitting is performed, this expands each positional parameter to a separate word; if not within double quotes, these words are subject to word splitting. In contexts where word splitting is not performed, this expands to a single word with each positional parameter separated by a space. When the expansion occurs within double quotes, and word splitting is performed, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" …. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed).

michealespinola commented 3 years ago

Thank you for this, it's much appreciated! My only outlying concern is how notifications will be affected by the cycled output. This will be interesting to test

lordvandal commented 3 years ago

For the upgrade process I would create a temporary .lock file somewhere with some variables in it:

And anything else you think is useful, e.g.:

You could even use this lock file for the Plex upgrade too. And also to test if the script and/or Plex server upgrades were successful.

The report should be issued only after the upgrade process and the aforementioned tests. And this way the report can contain the information about the success or failure of the upgrade too.

michealespinola commented 3 years ago

The report is simply a log of standard stream output from the task. Its not anything I can separately generate and email because of the limitations of the DSM. It's all very hackish, but there isn't a built-in alternative that I am aware of.

michealespinola commented 3 years ago

Thinking about this more while walking away from my keyboard, I think I can understand how what you suggest might be possible with various stream redirections to suppress/capture output until complete and ready to be displayed as a "report" when the script reaches its terminus.

lordvandal commented 2 years ago

Some quite extensive examples of self updating scripts, from https://glennr.nl/:

michealespinola commented 2 years ago

I will take a look at those for ideas, thanks!