From ff3ab3109678da086e0abdc8a9a2fe19a1de94e7 Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 7 Jul 2022 11:03:56 +0200 Subject: [PATCH 1/7] Update multiplugin Allow execution of both PLG and XML files --- plugins/dynamix.plugin.manager/scripts/multiplugin | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/dynamix.plugin.manager/scripts/multiplugin b/plugins/dynamix.plugin.manager/scripts/multiplugin index 6b7d43b4b..74a7b4950 100755 --- a/plugins/dynamix.plugin.manager/scripts/multiplugin +++ b/plugins/dynamix.plugin.manager/scripts/multiplugin @@ -15,6 +15,7 @@ $method = $argv[1]; $plugins = explode('*',$argv[2]); $console = $argv[$argc-1] != 'nchan'; // console or nchan output +$call = ['plg' => 'plugin', 'xml' => 'language']; function write($message){ global $console; @@ -36,9 +37,9 @@ function write($message){ usleep(50000); foreach ($plugins as $plugin) { - if (!$plugin) continue; + if (!$plugin || (!$cmd = $call[pathinfo($plugin)['extension']])) continue; $line = ''; - $run = popen("plugin $method $plugin",'r'); + $run = popen("$cmd $method $plugin",'r'); while (!feof($run)) { $line .= fgetc($run); if (in_array($line[-1],["\r","\n"])) {write($line); $line = '';} From 35a5991dd42aa7d87a1f782f1f0fc9b38b4075a4 Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 7 Jul 2022 13:46:29 +0200 Subject: [PATCH 2/7] Plugin system update Run post-hook scripts unconditionally --- .../post-hooks/post_plugin_checks | 6 +++++- plugins/dynamix.plugin.manager/scripts/plugin | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks b/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks index f8b529c81..04f255024 100755 --- a/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks +++ b/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks @@ -28,9 +28,13 @@ function searchLink(&$db,$url) { } $method = $argv[1]; -$plugin = "/boot/config/plugins/{$argv[2]}"; +$name = $argv[2]; +$plugin = "/boot/config/plugins/$name"; +$link = "/var/log/plugins/$name"; if ($method == 'install' or $method == 'update') { + // check if plugin is installed + if (@readlink($link)===false) die; // update support link in plugin file $info = readJson('/tmp/community.applications/tempFiles/templates.json'); // find matching support link diff --git a/plugins/dynamix.plugin.manager/scripts/plugin b/plugins/dynamix.plugin.manager/scripts/plugin index 4bcba7605..7a5a55867 100755 --- a/plugins/dynamix.plugin.manager/scripts/plugin +++ b/plugins/dynamix.plugin.manager/scripts/plugin @@ -204,7 +204,7 @@ function pre_hooks() { } } -// Run hooked scripts after successful completion of "method" +// Run hooked scripts after successful or failed completion of "method" // method = install, update, remove, check // hook programs receives two parameters: method and plugin-name // @@ -619,6 +619,8 @@ if ($method == 'install') { $subject = "plugin: ".basename($plugin_file); $description = "Plugin failed to install"; exec("$notify -e $event -s $subject -d $description) -i 2"); + // run hook scripts for post processing + post_hooks(); exit(1); } // remove symlink for re-install @@ -632,6 +634,8 @@ if ($method == 'install') { if (dirname($plugin_file) == "$boot") { move($plugin_file, "$boot-error"); } + // run hook scripts for post processing + post_hooks(); exit(1); } } @@ -680,6 +684,8 @@ if ($method == 'check') { $version = plugin('version', $plugin_file, $error); if ($version === false) { write("plugin: $error\n"); + // run hook scripts for post processing + post_hooks(); exit(1); } write("$version\n"); @@ -732,6 +738,8 @@ if ($method == 'update') { // install the updated plugin if (plugin('install', $plugin_file, $error) === false) { write("plugin: $error\n"); + // run hook scripts for post processing + post_hooks(); exit(1); } // install was successful, save the updated plugin so it installs again next boot @@ -764,6 +772,8 @@ if ($method == 'remove') { // but if can't remove, restore the symlink if (is_file($installed_plugin_file)) symlink($installed_plugin_file, $symlink); write("plugin: $error\n"); + // run hook scripts for post processing + post_hooks(); exit(1); } } From 3b5238cd0d90e8dc0a409a817466477ab3395c4e Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 7 Jul 2022 14:02:34 +0200 Subject: [PATCH 3/7] Plugin system update --- .../dynamix.plugin.manager/post-hooks/post_plugin_checks | 6 +++--- plugins/dynamix.plugin.manager/scripts/plugin | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks b/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks index 04f255024..e7a7ce5cb 100755 --- a/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks +++ b/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks @@ -29,12 +29,12 @@ function searchLink(&$db,$url) { $method = $argv[1]; $name = $argv[2]; +$error = $argv[3]; $plugin = "/boot/config/plugins/$name"; -$link = "/var/log/plugins/$name"; if ($method == 'install' or $method == 'update') { - // check if plugin is installed - if (@readlink($link)===false) die; + // check if plugin + if ($error) die; // update support link in plugin file $info = readJson('/tmp/community.applications/tempFiles/templates.json'); // find matching support link diff --git a/plugins/dynamix.plugin.manager/scripts/plugin b/plugins/dynamix.plugin.manager/scripts/plugin index 7a5a55867..2ac91baad 100755 --- a/plugins/dynamix.plugin.manager/scripts/plugin +++ b/plugins/dynamix.plugin.manager/scripts/plugin @@ -206,14 +206,14 @@ function pre_hooks() { // Run hooked scripts after successful or failed completion of "method" // method = install, update, remove, check -// hook programs receives two parameters: method and plugin-name +// hook programs receives three parameters: method and plugin-name and error (empty if none) // function post_hooks() { - global $method, $plugin; + global $method, $plugin, $error; $hooks = "/usr/local/emhttp/plugins/dynamix.plugin.manager/post-hooks"; foreach (glob("$hooks/*") as $hook) if (is_executable($hook)) { write("Executing hook script: ".basename($hook)."\n"); - run("$hook $method $plugin"); + run("$hook $method $plugin $error"); } } From 3bc84df18367fe0eeb78abfef026a4a740b9473e Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 7 Jul 2022 14:17:49 +0200 Subject: [PATCH 4/7] Plugin system update --- plugins/dynamix.plugin.manager/scripts/plugin | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/dynamix.plugin.manager/scripts/plugin b/plugins/dynamix.plugin.manager/scripts/plugin index 2ac91baad..bbd3f7068 100755 --- a/plugins/dynamix.plugin.manager/scripts/plugin +++ b/plugins/dynamix.plugin.manager/scripts/plugin @@ -629,6 +629,7 @@ if ($method == 'install') { // run hook scripts for pre processing pre_hooks(); // fresh install + $error = ''; if (plugin('install', $plugin_file, $error) === false) { write("plugin: $error\n"); if (dirname($plugin_file) == "$boot") { @@ -650,6 +651,7 @@ if ($method == 'install') { write("script: $plugin executed\n"); logger("script: $plugin executed"); } + $error = ''; // run hook scripts for post processing post_hooks(); exit(0); @@ -689,6 +691,7 @@ if ($method == 'check') { exit(1); } write("$version\n"); + $error = ''; // run hook scripts for post processing post_hooks(); exit(0); @@ -749,6 +752,7 @@ if ($method == 'update') { symlink($target, $symlink); write("plugin: $plugin updated\n"); logger("plugin: $plugin updated"); + $error = ''; // run hook scripts for post processing post_hooks(); exit(0); @@ -782,6 +786,7 @@ if ($method == 'remove') { write("plugin: $plugin removed\n"); logger("plugin: $plugin removed"); exec("/usr/local/sbin/update_cron"); + $error = ''; // run hook scripts for post processing post_hooks(); exit(0); From 451b4ee2fed0bada176cee3bbd45bc96e1af2c88 Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 7 Jul 2022 14:21:51 +0200 Subject: [PATCH 5/7] Plugin system update --- plugins/dynamix.plugin.manager/scripts/plugin | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/plugins/dynamix.plugin.manager/scripts/plugin b/plugins/dynamix.plugin.manager/scripts/plugin index bbd3f7068..f04e947a2 100755 --- a/plugins/dynamix.plugin.manager/scripts/plugin +++ b/plugins/dynamix.plugin.manager/scripts/plugin @@ -208,8 +208,8 @@ function pre_hooks() { // method = install, update, remove, check // hook programs receives three parameters: method and plugin-name and error (empty if none) // -function post_hooks() { - global $method, $plugin, $error; +function post_hooks($error) { + global $method, $plugin; $hooks = "/usr/local/emhttp/plugins/dynamix.plugin.manager/post-hooks"; foreach (glob("$hooks/*") as $hook) if (is_executable($hook)) { write("Executing hook script: ".basename($hook)."\n"); @@ -620,7 +620,7 @@ if ($method == 'install') { $description = "Plugin failed to install"; exec("$notify -e $event -s $subject -d $description) -i 2"); // run hook scripts for post processing - post_hooks(); + post_hooks($error); exit(1); } // remove symlink for re-install @@ -636,7 +636,7 @@ if ($method == 'install') { move($plugin_file, "$boot-error"); } // run hook scripts for post processing - post_hooks(); + post_hooks($error); exit(1); } } @@ -651,9 +651,8 @@ if ($method == 'install') { write("script: $plugin executed\n"); logger("script: $plugin executed"); } - $error = ''; // run hook scripts for post processing - post_hooks(); + post_hooks(''); exit(0); } @@ -687,13 +686,12 @@ if ($method == 'check') { if ($version === false) { write("plugin: $error\n"); // run hook scripts for post processing - post_hooks(); + post_hooks($error); exit(1); } write("$version\n"); - $error = ''; // run hook scripts for post processing - post_hooks(); + post_hooks(''); exit(0); } @@ -742,7 +740,7 @@ if ($method == 'update') { if (plugin('install', $plugin_file, $error) === false) { write("plugin: $error\n"); // run hook scripts for post processing - post_hooks(); + post_hooks($error); exit(1); } // install was successful, save the updated plugin so it installs again next boot @@ -752,9 +750,8 @@ if ($method == 'update') { symlink($target, $symlink); write("plugin: $plugin updated\n"); logger("plugin: $plugin updated"); - $error = ''; // run hook scripts for post processing - post_hooks(); + post_hooks(''); exit(0); } @@ -777,7 +774,7 @@ if ($method == 'remove') { if (is_file($installed_plugin_file)) symlink($installed_plugin_file, $symlink); write("plugin: $error\n"); // run hook scripts for post processing - post_hooks(); + post_hooks($error); exit(1); } } @@ -786,9 +783,8 @@ if ($method == 'remove') { write("plugin: $plugin removed\n"); logger("plugin: $plugin removed"); exec("/usr/local/sbin/update_cron"); - $error = ''; // run hook scripts for post processing - post_hooks(); + post_hooks(''); exit(0); } From 462e558600d0e5c481345f9d5f136e3780db913a Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 7 Jul 2022 14:25:36 +0200 Subject: [PATCH 6/7] Plugin system update --- plugins/dynamix.plugin.manager/scripts/plugin | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/dynamix.plugin.manager/scripts/plugin b/plugins/dynamix.plugin.manager/scripts/plugin index f04e947a2..8d0d4e39c 100755 --- a/plugins/dynamix.plugin.manager/scripts/plugin +++ b/plugins/dynamix.plugin.manager/scripts/plugin @@ -208,7 +208,7 @@ function pre_hooks() { // method = install, update, remove, check // hook programs receives three parameters: method and plugin-name and error (empty if none) // -function post_hooks($error) { +function post_hooks($error='') { global $method, $plugin; $hooks = "/usr/local/emhttp/plugins/dynamix.plugin.manager/post-hooks"; foreach (glob("$hooks/*") as $hook) if (is_executable($hook)) { @@ -629,7 +629,6 @@ if ($method == 'install') { // run hook scripts for pre processing pre_hooks(); // fresh install - $error = ''; if (plugin('install', $plugin_file, $error) === false) { write("plugin: $error\n"); if (dirname($plugin_file) == "$boot") { @@ -652,7 +651,7 @@ if ($method == 'install') { logger("script: $plugin executed"); } // run hook scripts for post processing - post_hooks(''); + post_hooks(); exit(0); } @@ -691,7 +690,7 @@ if ($method == 'check') { } write("$version\n"); // run hook scripts for post processing - post_hooks(''); + post_hooks(); exit(0); } @@ -751,7 +750,7 @@ if ($method == 'update') { write("plugin: $plugin updated\n"); logger("plugin: $plugin updated"); // run hook scripts for post processing - post_hooks(''); + post_hooks(); exit(0); } @@ -784,7 +783,7 @@ if ($method == 'remove') { logger("plugin: $plugin removed"); exec("/usr/local/sbin/update_cron"); // run hook scripts for post processing - post_hooks(''); + post_hooks(); exit(0); } From 7ae3bcc7da1e11b4854d413bdf78003716412c68 Mon Sep 17 00:00:00 2001 From: bergware Date: Thu, 7 Jul 2022 14:29:55 +0200 Subject: [PATCH 7/7] Plugin system update --- plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks b/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks index e7a7ce5cb..8a84b8e44 100755 --- a/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks +++ b/plugins/dynamix.plugin.manager/post-hooks/post_plugin_checks @@ -33,7 +33,7 @@ $error = $argv[3]; $plugin = "/boot/config/plugins/$name"; if ($method == 'install' or $method == 'update') { - // check if plugin + // check if method successfully completed if ($error) die; // update support link in plugin file $info = readJson('/tmp/community.applications/tempFiles/templates.json');