Skip to content

Commit 1dd843d

Browse files
ljm42elibosley
authored andcommitted
Add plugin download method with target version support for OS upgrades
1 parent d2d326f commit 1dd843d

File tree

1 file changed

+50
-29
lines changed
  • emhttp/plugins/dynamix.plugin.manager/scripts

1 file changed

+50
-29
lines changed

emhttp/plugins/dynamix.plugin.manager/scripts/plugin

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ Usage: plugin install PLUGIN-FILE [forced]
2323
2424
forced is optional and can be used to install a lower version than currently running.
2525
26-
Usage: plugin download PLUGIN-FILE [forced]
27-
download plugin files without executing any Run commands defined for the install method
28-
29-
PLUGIN-FILE is a plugin definition XML file with ".plg" extension.
30-
31-
PLUGIN-FILE can be a local file, or a URL. If a URL, the plugin file is first downloaded to /tmp/plugins.
32-
33-
forced is optional and can be used to download a lower version than currently running.
34-
35-
Both install and download commands will process all FILE elements in PLUGIN-FILE which are tagged with the
36-
\"install\" method (or that have no method tag).
37-
3826
This command has two major use cases:
3927
4028
1) Invoked at system startup by /etc/rc.d/rc.local on each .plg file found int /boot/config/plugins.
@@ -88,6 +76,15 @@ Usage: plugin update PLUGIN
8876
Note: to support `plugin check` and `plugin update` the plugin file must contain both "pluginURL" and
8977
"version" attributes.
9078
79+
Usage: plugin download PLUGIN-FILE [TARGET-VERSION] [forced]
80+
Downloads plugin files without executing any Run commands defined for the install method.
81+
This method first updates the plugin definition file (.plg) to the latest version, then
82+
downloads all required files but skips script execution. This makes it suitable for
83+
preparing plugin files before an Unraid OS upgrade.
84+
85+
TARGET-VERSION is optional and specifies the Unraid version to use for version compatibility
86+
checks (Min/Max attributes). If omitted, the current Unraid version is used.
87+
9188
Usage: plugin [attribute name] PLUGIN-FILE
9289
9390
Any method which is not one of the actions listed above is assumed to be the name of an attribute of
@@ -296,7 +293,7 @@ function filter_url($url) {
296293
// is processed for any of those methods.
297294
//
298295
function plugin($method, $plugin_file, &$error) {
299-
global $unraid, $logger, $download_only;
296+
global $logger, $download_only, $check_version;
300297
$methods = ['install', 'remove'];
301298

302299
// parse plugin definition XML file
@@ -363,13 +360,17 @@ function plugin($method, $plugin_file, &$error) {
363360
$name = $file->attributes()->Name ?: '';
364361
// bergware - check Unraid version dependency (if present)
365362
$min = $file->attributes()->Min;
366-
if ($min && version_compare($unraid['version'],$min,'<')) {
367-
write("plugin: skipping: ".basename($name)." - Unraid version too low, requires at least version $min\n");
363+
if ($min && version_compare($check_version,$min,'<')) {
364+
if (!$download_only) {
365+
write("plugin: skipping: ".basename($name)." - Unraid version too low, requires at least version $min\n");
366+
}
368367
continue;
369368
}
370369
$max = $file->attributes()->Max;
371-
if ($max && version_compare($unraid['version'],$max,'>')) {
372-
write("plugin: skipping: ".basename($name)." - Unraid version too high, requires at most version $max\n");
370+
if ($max && version_compare($check_version,$max,'>')) {
371+
if (!$download_only) {
372+
write("plugin: skipping: ".basename($name)." - Unraid version too high, requires at most version $max\n");
373+
}
373374
continue;
374375
}
375376
// Name can be missing but only makes sense if Run attribute is present
@@ -478,7 +479,6 @@ function plugin($method, $plugin_file, &$error) {
478479
my_logger("running: $command $file->LOCAL", $logger);
479480
$retval = run("$command $file->LOCAL");
480481
} elseif ($file->INLINE) {
481-
482482
$name = '/tmp/inline'.$current_file.'-'.pathinfo($plugin_file, PATHINFO_FILENAME).'.sh';
483483
file_put_contents($name, $file->INLINE);
484484
$exec = $command." ".escapeshellarg($name);
@@ -511,15 +511,31 @@ $args = array_slice($argv, 2);
511511
$extra_args = array_slice($args, 1); // anything after the plugin path
512512
$builtin = ['unRAIDServer','unRAIDServer-'];
513513

514+
// Load Unraid version and initialize check_version
515+
$unraid = parse_ini_file('/etc/unraid-version');
516+
$check_version = $unraid['version'];
517+
514518
// Optional flags
519+
// nchan must be the final argument
515520
$nchan = ($argc > 0) && ($argv[$argc-1] === 'nchan'); // console or nchan output
516521
if ($nchan) array_pop($extra_args);
517-
$forced = !empty($extra_args); // any extra arg (besides nchan) signals forced
518522

519-
// Normalize download to reuse the install flow while skipping run steps.
523+
// Extract target version if present (for download/update methods)
524+
// Version pattern: starts with digit, contains dots, optionally has dash suffix (e.g., "7.2.0", "7.2.0-rc.1")
525+
if (!empty($extra_args) && ($method === 'download' || $method === 'update')) {
526+
$first_arg = $extra_args[0];
527+
if (preg_match('/^\d+\.\d+\.\d+(-.*)?$/', $first_arg)) {
528+
$check_version = $first_arg;
529+
array_shift($extra_args);
530+
}
531+
}
532+
533+
$forced = !empty($extra_args); // any extra arg (besides nchan and TARGET-VERSION) signals forced
534+
535+
// Normalize download to reuse the update flow while skipping run steps.
520536
if ($method === 'download') {
521537
$download_only = true;
522-
$method = 'install';
538+
$method = 'update';
523539
}
524540

525541
// In following code,
@@ -616,7 +632,6 @@ if ($argc < 3) {
616632
// b) [plugin_file] is a URL
617633
// c) dirname of [plugin_file] is not /boot/config/plugins
618634
//
619-
$unraid = parse_ini_file('/etc/unraid-version');
620635
if ($method == 'install') {
621636
$argv[2] = preg_replace('#[\x00-\x1F\x80-\xFF]#', '', $argv[2]);
622637
$plugin = basename($argv[2]);
@@ -647,8 +662,9 @@ if ($method == 'install') {
647662
$plugin_file = realpath($argv[2]);
648663
}
649664
// bergware - check Unraid version dependency (if present)
665+
global $check_version;
650666
$min = plugin('min', $plugin_file, $error);
651-
if ($min && version_compare($unraid['version'], $min, '<')) {
667+
if ($min && version_compare($check_version, $min, '<')) {
652668
write("plugin: installed Unraid version is too low, require at least version $min\n");
653669
if (dirname($plugin_file) == "$boot") {
654670
move($plugin_file, "$boot-error");
@@ -658,7 +674,7 @@ if ($method == 'install') {
658674
done(1);
659675
}
660676
$max = plugin('max', $plugin_file, $error) ?: plugin('Unraid', $plugin_file, $error);
661-
if ($max && version_compare($unraid['version'], $max, '>')) {
677+
if ($max && version_compare($check_version, $max, '>')) {
662678
write("plugin: installed Unraid version is too high, require at most version $max\n");
663679
if (dirname($plugin_file) == "$boot") {
664680
move($plugin_file, "$boot-error");
@@ -813,7 +829,11 @@ if ($method == 'check') {
813829
if ($method == 'update') {
814830
$plugin = $argv[2];
815831
$symlink = "$plugins/$plugin";
816-
write("plugin: updating: $plugin\n");
832+
if ($download_only) {
833+
write("plugin: download-only mode enabled, skipping install commands\n");
834+
}
835+
$action = $download_only ? 'downloading' : 'updating';
836+
write("plugin: $action: $plugin\n");
817837
$installed_plugin_file = @readlink($symlink);
818838
if ($installed_plugin_file === false) {
819839
write("plugin: $plugin not installed\n");
@@ -829,14 +849,14 @@ if ($method == 'update') {
829849
}
830850
// bergware - check Unraid version dependency (if present)
831851
$min = plugin('min', $plugin_file, $error);
832-
if ($min && version_compare($unraid['version'], $min, '<')) {
852+
if ($min && version_compare($check_version, $min, '<')) {
833853
write("plugin: installed Unraid version is too low, require at least version $min\n");
834854
// run hook scripts for post processing
835855
post_hooks($error);
836856
done(1);
837857
}
838858
$max = plugin('max', $plugin_file, $error) ?: plugin('Unraid', $plugin_file, $error);
839-
if ($max && version_compare($unraid['version'], $max, '>')) {
859+
if ($max && version_compare($check_version, $max, '>')) {
840860
write("plugin: installed Unraid version is too high, require at most version $max\n");
841861
// run hook scripts for post processing
842862
post_hooks($error);
@@ -863,8 +883,9 @@ if ($method == 'update') {
863883
$target = "$boot/$plugin";
864884
copy($plugin_file, $target);
865885
symlink($target, $symlink);
866-
write("plugin: $plugin updated\n");
867-
my_logger("$plugin updated", $logger);
886+
$status = $download_only ? 'downloaded' : 'updated';
887+
write("plugin: $plugin $status\n");
888+
my_logger("$plugin $status", $logger);
868889
// run hook scripts for post processing
869890
post_hooks();
870891
done(0);

0 commit comments

Comments
 (0)