add delete function

This commit is contained in:
Derek Macias 2015-12-14 23:27:33 -07:00
parent 79eb8db9d5
commit 62b78fbeea
5 changed files with 32 additions and 102 deletions

View File

@ -3,7 +3,7 @@
<!DOCTYPE PLUGIN [ <!DOCTYPE PLUGIN [
<!ENTITY name "NerdPack"> <!ENTITY name "NerdPack">
<!ENTITY author "dmacias72"> <!ENTITY author "dmacias72">
<!ENTITY version "2015.12.15"> <!ENTITY version "2015.12.14">
<!ENTITY launch "Settings/&name;"> <!ENTITY launch "Settings/&name;">
<!ENTITY gitURL "https://raw.githubusercontent.com/&author;/unRAID-plugins/master"> <!ENTITY gitURL "https://raw.githubusercontent.com/&author;/unRAID-plugins/master">
<!ENTITY pluginURL "&gitURL;/plugins/&name;.plg"> <!ENTITY pluginURL "&gitURL;/plugins/&name;.plg">
@ -17,10 +17,9 @@
<PLUGIN name="&name;" author="&author;" version="&version;" launch="&launch;" pluginURL="&pluginURL;"> <PLUGIN name="&name;" author="&author;" version="&version;" launch="&launch;" pluginURL="&pluginURL;">
<CHANGES> <CHANGES>
###2015.12.15 ###2015.12.14
- add update functions - add update functions
- add remove package function - add remove package function
###2015.12.14
- fix some minor bugs - fix some minor bugs
###2015.12.13 ###2015.12.13
- initial commit of wrapper plugin for packages in repo - initial commit of wrapper plugin for packages in repo

View File

@ -13,7 +13,8 @@ get_content_from_github($pkg_repo, $repo_file);
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css"> <link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
<span class="status" style="margin-top: -45px;"><input id="removepkg" type="checkbox"></span> <span class="status" style="display: inline-block; margin-right: 110px;margin-top: -45px;"><input id="removepkg" type="checkbox"></span>
<span class="status" style="display: inline-block;margin-top: -45px;"><input id="deletepkg" type="checkbox"></span>
<form markdown="1" id="package_form" name="package_settings" method="POST" action="/update.php" target="progressFrame"> <form markdown="1" id="package_form" name="package_settings" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" name="#file" value="NerdPack/NerdPack.cfg" /> <input type="hidden" name="#file" value="NerdPack/NerdPack.cfg" />
<table style="margin-top:-22px;" class="tablesorter" id="tblPackages"> <table style="margin-top:-22px;" class="tablesorter" id="tblPackages">
@ -25,7 +26,6 @@ get_content_from_github($pkg_repo, $repo_file);
<th> Downloaded </th> <th> Downloaded </th>
<th> Installed </th> <th> Installed </th>
<th><input id="checkall" type="checkbox"></th> <th><input id="checkall" type="checkbox"></th>
<th> Remove </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

@ -1,65 +0,0 @@
<?php
function usage($argv) {
echo "Usage:\n";
printf("\tphp %s <http://example.com/file> <localfile>\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);
?>

View File

@ -6,12 +6,24 @@ $(function(){
$('#removepkg') $('#removepkg')
.switchButton({ .switchButton({
labels_placement: "left", labels_placement: "left",
on_label: 'unInstall Packages', on_label: 'unInstall On',
off_label: 'unInstall Packages', off_label: 'unInstall Off',
checked: $.cookie('nerdpack_packages') == 'remove' checked: $.cookie('nerdpack_packages_remove') == 'remove'
}) })
.change(function () { .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 // select all packages switch
@ -55,8 +67,10 @@ function packageManager() {
url : "/update.php", url : "/update.php",
data : $('#package_form').serializeArray(), data : $('#package_form').serializeArray(),
success: function() { success: function() {
openBox('/plugins/NerdPack/scripts/packagemanager&arg1=download&arg2='+ openBox('/plugins/NerdPack/scripts/packagemanager&arg1=download'+
$.cookie('nerdpack_packages'),'Manage Packages',600,900,true); '&arg2='+$.cookie('nerdpack_packages_remove')+
'&arg3='+$.cookie('nerdpack_packages_delete'),
'Manage Packages',600,900,true);
} }
}); });
}; };
@ -86,10 +100,7 @@ function packageQuery() {
"<td><input class='pkgcheckbox' id='"+data[i].pkgname+"' type='checkbox'>"+ "<td><input class='pkgcheckbox' id='"+data[i].pkgname+"' type='checkbox'>"+
"<input class='pkgvalue' type='hidden' id='"+data[i].pkgname+"_value' name='"+ "<input class='pkgvalue' type='hidden' id='"+data[i].pkgname+"_value' name='"+
data[i].pkgnver+"' value='"+data[i].config+"'></td>"+ data[i].pkgnver+"' value='"+data[i].config+"'></td>"+
"<td><img src='/plugins/dynamix/images/close.png' width='24' height='24' "+
"class='btnRemove' title='remove package from flash drive'/></td>"+
"</tr>"); "</tr>");
$(".btnRemove").unbind("click", Remove).bind("click", Remove);
$('#'+data[i].pkgname) $('#'+data[i].pkgname)
.switchButton({ .switchButton({
labels_placement: 'right', labels_placement: 'right',
@ -126,22 +137,3 @@ function checkDepends() {
$('#python','.pkgvalue').val('yes'); $('#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() {
}
});
}
}
};

View File

@ -62,19 +62,23 @@ foreach($pkg_cfg as $pkg_name => $pkg_pref) { //get preferences for each package
} }
if (!$pkg_install_status){ if (!$pkg_install_status){
$pkg_msg = "Installing"; $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"){ }elseif($pkg_pref == "no" && $pkg_install_status && $argv[2] == "remove"){
$pkg_msg = "Removing"; $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)){ if(!empty($pkg_cmd)){
logger("$pkg_msg $pkg_name package..."); logger("$pkg_msg $pkg_name package...");
$pkg_cmd = $pkg_cmd.$pkg_path.$pkg_name."* 2>&1"; usleep(100000);
$output = shell_exec($pkg_cmd); $output = shell_exec($pkg_cmd);
logger($output); logger($output);
usleep(100000);
}else }else
logger($pkg_name." package up to date"); logger($pkg_name." package up to date");
} }