From 62b78fbeeab1d5db71645351a3d98e0accc86932 Mon Sep 17 00:00:00 2001 From: Derek Macias Date: Mon, 14 Dec 2015 23:27:33 -0700 Subject: [PATCH] add delete function --- plugins/NerdPack.plg | 5 +- .../emhttp/plugins/NerdPack/NerdPack.page | 4 +- .../emhttp/plugins/NerdPack/include/fetch.php | 65 ------------------- .../NerdPack/javascript/jquery.NerdPack.js | 48 ++++++-------- .../plugins/NerdPack/scripts/packagemanager | 12 ++-- 5 files changed, 32 insertions(+), 102 deletions(-) delete mode 100644 source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/fetch.php diff --git a/plugins/NerdPack.plg b/plugins/NerdPack.plg index db919b20..4271a462 100644 --- a/plugins/NerdPack.plg +++ b/plugins/NerdPack.plg @@ -3,7 +3,7 @@ - + @@ -17,10 +17,9 @@ -###2015.12.15 +###2015.12.14 - add update functions - add remove package function -###2015.12.14 - fix some minor bugs ###2015.12.13 - initial commit of wrapper plugin for packages in repo diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page index 3cd5ee21..8c03691d 100644 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/NerdPack.page @@ -13,7 +13,8 @@ get_content_from_github($pkg_repo, $repo_file); - + +
@@ -25,7 +26,6 @@ get_content_from_github($pkg_repo, $repo_file); - diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/fetch.php b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/fetch.php deleted file mode 100644 index 8379772c..00000000 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/include/fetch.php +++ /dev/null @@ -1,65 +0,0 @@ - -\n", $argv[0]); - exit(1); -} - -function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { - static $filesize = null; - - switch($notification_code) { - case STREAM_NOTIFY_RESOLVE: - case STREAM_NOTIFY_AUTH_REQUIRED: - case STREAM_NOTIFY_COMPLETED: - case STREAM_NOTIFY_FAILURE: - case STREAM_NOTIFY_AUTH_RESULT: - /* Ignore */ - break; - - case STREAM_NOTIFY_REDIRECTED: - echo "Being redirected to: ", $message, "\n"; - break; - - case STREAM_NOTIFY_CONNECT: - echo "Connected...\n"; - break; - - case STREAM_NOTIFY_FILE_SIZE_IS: - $filesize = $bytes_max; - echo "Filesize: ", $filesize, "\n"; - break; - - case STREAM_NOTIFY_MIME_TYPE_IS: - echo "Mime-type: ", $message, "\n"; - break; - - case STREAM_NOTIFY_PROGRESS: - if ($bytes_transferred > 0) { - if (!isset($filesize)) { - printf("\rUnknown filesize.. %2d kb done..", $bytes_transferred/1024); - } else { - $length = (int)(($bytes_transferred/$filesize)*100); - printf("\r[%-100s] %d%% (%2d/%2d kb)", str_repeat("=", $length). ">", $length, ($bytes_transferred/1024), $filesize/1024); - } - } - break; - } -} - -isset($argv[1], $argv[2]) or usage($argv); - -$ctx = stream_context_create(); -stream_context_set_params($ctx, array("notification" => "stream_notification_callback")); - -$fp = fopen($argv[1], "r", false, $ctx); -if (is_resource($fp) && file_put_contents($argv[2], $fp)) { - echo "\nDone!\n"; - exit(0); -} - -$err = error_get_last(); -echo "\nErrrrrorr..\n", $err["message"], "\n"; -exit(1); -?> diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js index bc588fb2..b368f709 100644 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/javascript/jquery.NerdPack.js @@ -6,12 +6,24 @@ $(function(){ $('#removepkg') .switchButton({ labels_placement: "left", - on_label: 'unInstall Packages', - off_label: 'unInstall Packages', - checked: $.cookie('nerdpack_packages') == 'remove' + on_label: 'unInstall On', + off_label: 'unInstall Off', + checked: $.cookie('nerdpack_packages_remove') == 'remove' }) .change(function () { - $.cookie('nerdpack_packages', $('#removepkg').prop('checked') ? 'remove' : 'donotremove', { expires: 3650 }); + $.cookie('nerdpack_packages_remove', $('#removepkg').prop('checked') ? 'remove' : 'donotremove', { expires: 3650 }); + }); + + // "delete package" switch and cookie + $('#deletepkg') + .switchButton({ + labels_placement: "left", + on_label: 'delete On', + off_label: 'delete Off', + checked: $.cookie('nerdpack_packages_delete') == 'delete' + }) + .change(function () { + $.cookie('nerdpack_packages_delete', $('#removepkg').prop('checked') ? 'delete' : 'donotdelete', { expires: 3650 }); }); // select all packages switch @@ -55,8 +67,10 @@ function packageManager() { url : "/update.php", data : $('#package_form').serializeArray(), success: function() { - openBox('/plugins/NerdPack/scripts/packagemanager&arg1=download&arg2='+ - $.cookie('nerdpack_packages'),'Manage Packages',600,900,true); + openBox('/plugins/NerdPack/scripts/packagemanager&arg1=download'+ + '&arg2='+$.cookie('nerdpack_packages_remove')+ + '&arg3='+$.cookie('nerdpack_packages_delete'), + 'Manage Packages',600,900,true); } }); }; @@ -86,10 +100,7 @@ function packageQuery() { ""+ - ""+ ""); - $(".btnRemove").unbind("click", Remove).bind("click", Remove); $('#'+data[i].pkgname) .switchButton({ labels_placement: 'right', @@ -126,22 +137,3 @@ function checkDepends() { $('#python','.pkgvalue').val('yes'); } }; - -function Remove(){ - var par = $(this).parent().parent(); - if (par.children("td:nth-child(4)").html() == "yes"){ - var Package = par.children("td:nth-child(1)").html(); - var Downloaded = par.children("td:nth-child(4)").html(); - var Confirm = confirm("Remove package "+Package+" from flash drive?") - if (Confirm) { - par.children("td:nth-child(4)").html("no"); - $.ajax({ - type : "POST", - url: '/plugins/NerdPack/include/PackageRemove.php', - data : {pkg:Package}, - success: function() { - } - }); - } - } -}; diff --git a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager index 76c38dcb..9ae01b00 100755 --- a/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager +++ b/source/NerdPack/usr/local/emhttp/plugins/NerdPack/scripts/packagemanager @@ -62,19 +62,23 @@ foreach($pkg_cfg as $pkg_name => $pkg_pref) { //get preferences for each package } if (!$pkg_install_status){ $pkg_msg = "Installing"; - $pkg_cmd = "upgradepkg --install-new "; + $pkg_cmd = "upgradepkg --install-new ".$pkg_path.$pkg_name."* 2>&1"; } }elseif($pkg_pref == "no" && $pkg_install_status && $argv[2] == "remove"){ $pkg_msg = "Removing"; - $pkg_cmd = "removepkg "; - + $pkg_cmd = "removepkg ".$pkg_path.$pkg_name."* 2>&1"; + if ($argv[3] == "delete"){ + $pkg_cmd .= "; rm ".$pkg_path.$pkg_name."* 2>&1"; + $pkg_msg .= " and deleting"; + } } if(!empty($pkg_cmd)){ logger("$pkg_msg $pkg_name package..."); - $pkg_cmd = $pkg_cmd.$pkg_path.$pkg_name."* 2>&1"; + usleep(100000); $output = shell_exec($pkg_cmd); logger($output); + usleep(100000); }else logger($pkg_name." package up to date"); }
Downloaded Installed Remove
"+ "