From 1f3654465736104ddad71f27c2ed161d1ebca247 Mon Sep 17 00:00:00 2001 From: Derek Macias Date: Tue, 2 Feb 2016 11:39:44 -0700 Subject: [PATCH] add check for other plugin dependencies --- .../emhttp/plugins/NerdPack/NerdPack.page | 9 ++--- .../emhttp/plugins/NerdPack/css/NerdPack.css | 2 +- .../plugins/NerdPack/include/PackageQuery.php | 15 ++++++-- .../plugins/NerdPack/js/jquery.NerdPack.js | 8 ++--- .../plugins/NerdPack/scripts/packagemanager | 34 ++++++++++++++----- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page index 66ed910a..503b4a68 100644 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page @@ -1,5 +1,5 @@ Icon="NerdPack.png" -Menu="NetworkServices" +Menu="UserPreferences" Title="Nerd Pack" --- @@ -7,8 +7,8 @@ Title="Nerd Pack" - - + +
@@ -20,6 +20,7 @@ Title="Nerd Pack" Size Downloaded Installed + Plugins @@ -35,4 +36,4 @@ Title="Nerd Pack" - + \ No newline at end of file diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/css/NerdPack.css b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/css/NerdPack.css index 13de74fa..819d98a7 100644 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/css/NerdPack.css +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/css/NerdPack.css @@ -6,4 +6,4 @@ } .switch-button-label.off { color: inherit; -} \ No newline at end of file +} diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageQuery.php b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageQuery.php index 743c3e9b..6726f2d5 100644 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageQuery.php +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/PackageQuery.php @@ -14,6 +14,7 @@ foreach ($pkgs_github_array as $pkg_github) { $pkg_nameArray = explode('-', $pkg_github['name']); // split package name into array $pkg_name = $pkg_nameArray[0]; + if (sizeof($pkg_nameArray) > 4) { //if package name has a subset get it for ($ii = 1; $ii < sizeof($pkg_nameArray)-3; $ii++) { $pkg_name .= '-'.$pkg_nameArray[$ii]; @@ -26,6 +27,15 @@ foreach ($pkgs_github_array as $pkg_github) { $pkg_pattern = '/^'.$pkg_name.'.*/'; // search patter for packages + $plugins = []; + exec("cd /boot/config/plugins ; find *.plg | xargs grep '${pkg_github['name']}' -sl",$plugins); + $pkg_plgs = ""; + if ($plugins){ + foreach ($plugins as $plugin){ + $pkg_plgs .= pathinfo($plugin, PATHINFO_FILENAME)." "; + } + } + $pkg = [ 'name' => $pkg_github['name'], // add full package name 'pkgname' => $pkg_name, // add package name only @@ -33,10 +43,11 @@ foreach ($pkgs_github_array as $pkg_github) { 'pkgversion' => $pkg_version, // add package name with raw version 'size' => format_size($pkg_github['size'], 1, '?'), // add package size 'installed' => preg_grep($pkg_pattern, $pkgs_installed) ? 'yes' : 'no', // checks if package name is installed - 'installeq' => in_array(pathinfo($pkg_github['name'], PATHINFO_FILENAME), $pkgs_installed) ? 'yes' : 'no', // checks if package is installed equals github exactly + 'installeq' => in_array(pathinfo($pkg_github['name'], PATHINFO_FILENAME), $pkgs_installed) ? 'yes' : 'no', // checks if package installed equals github exactly 'downloaded' => preg_grep($pkg_pattern, $pkgs_downloaded) ? 'yes' : 'no', // checks if package name is downloaded - 'downloadeq' => in_array($pkg_github['name'], $pkgs_downloaded) ? 'yes' : 'no', // checks if package is downloaded equals github exactly + 'downloadeq' => in_array($pkg_github['name'], $pkgs_downloaded) ? 'yes' : 'no', // checks if package downloaded equals github exactly 'config' => isset($pkg_cfg[$pkg_nver]) ? $pkg_cfg[$pkg_nver] : 'no', // checks config for install preference + 'plugins' => $pkg_plgs, // checks plugins dependency on package 'desc' => $pkgs_desc_array[$pkg_name] ]; diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/js/jquery.NerdPack.js b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/js/jquery.NerdPack.js index 20d0cd36..3e51481f 100644 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/js/jquery.NerdPack.js +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/js/jquery.NerdPack.js @@ -95,13 +95,13 @@ function packageQuery(force) { if (data[i].installeq != data[i].installed) Installed = 'old'; - $("#tblPackages tbody").append( - ""+ + $("#tblPackages tbody").append(""+ ""+data[i].name+""+ // package name ""+Update+""+ // package status ""+data[i].size+""+ // package size - ""+Downloaded+""+ // package installed + ""+Downloaded+""+ // package downloaded ""+Installed+""+ // package installed + ""+data[i].plugins+""+ // package dependents ""+ ""+ ""); @@ -137,4 +137,4 @@ function checkDepends() { $("#python").switchButton({checked: true}); $("#python", ".pkgvalue").val("yes"); } -} +} \ No newline at end of file diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager index 148bfc27..13f5b34a 100755 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager @@ -56,11 +56,23 @@ foreach ($pkg_cfg as $pkg_name => $pkg_pref) { // get preferences for each packa $pkg_name = str_replace('_', '.', $pkg_name); // replace "_" with "." in package names $pkg_pattern = '/^'.$pkg_name.'.*/'; // search patter for packages $pkg_install_status = preg_grep($pkg_pattern, $pkgs_installed); // check install status + $pkg_download_status = preg_grep($pkg_pattern, $pkgs_downloaded); // check package download status + + //check if plugin is dependent on package + $plugins = []; + exec("cd /boot/config/plugins ; find *.plg | xargs grep '$pkg_name' -sl",$plugins); + if ($plugins){ + $plg_msg = "$pkg_name used by plugin: "; + foreach ($plugins as $plugin){ + $plg_msg .= pathinfo($plugin, PATHINFO_FILENAME)." "; + } + logger($plg_msg); + } if ($pkg_pref == 'yes') { // if executing from the wegui check status and download if necessary if ($argd) { - if (!preg_grep($pkg_pattern, $pkgs_downloaded)) { + if (!$pkg_download_status) { $pkg_online_status = preg_grep($pkg_pattern, $pkgs_github_array); @@ -88,21 +100,25 @@ foreach ($pkg_cfg as $pkg_name => $pkg_pref) { // get preferences for each packa $pkg_cmd = 'upgradepkg --install-new '.$pkg_path.$pkg_name.'* 2>&1'; } } else if ($pkg_pref == 'no' && $pkg_install_status && $argu) { - $pkg_msg = 'Uninstalling'; - $pkg_cmd = 'removepkg '.$pkg_path.$pkg_name.'* 2>&1'; - if ($argr) { - $pkg_cmd .= '; rm '.$pkg_path.$pkg_name.'* 2>&1'; - $pkg_msg .= ' and deleting'; + if($plugins){ + logger("Unable to uninstall $pkg_name",$argq); + }else{ + $pkg_msg = 'Uninstalling'; + $pkg_cmd = 'removepkg '.$pkg_path.$pkg_name.'* 2>&1'; + if ($argr) { + $pkg_cmd .= '; rm '.$pkg_path.$pkg_name.'* 2>&1'; + $pkg_msg .= ' and deleting'; + } } } if (!empty($pkg_cmd)) { - logger($pkg_msg.' '.$pkg_name.' package...'); + logger("$pkg_msg $pkg_name package..."); shell_exec($pkg_cmd); //$output = shell_exec($pkg_cmd); //logger($output); } else - logger($pkg_name.' package up to date', $argq); + logger("$pkg_name package up to date", $argq); } -logger('All packages processed'); +logger('All packages processed '); ?> \ No newline at end of file