Code cleanup, refactoring and bug fixes:
- Fixed first time running warnings about missing packages.json / desc files - Fixed bug preventing Select All from being able to be clicked - Fixed bug in select all and dependent checkboxes / race condition - Eliminated vertical space gap between page header and table
This commit is contained in:
parent
534c5775b8
commit
7576dc3f31
|
@ -3,43 +3,32 @@ Menu="NetworkServices"
|
||||||
Title="Nerd Pack"
|
Title="Nerd Pack"
|
||||||
---
|
---
|
||||||
<?php
|
<?php
|
||||||
include("/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php");
|
require_once '/usr/local/emhttp/plugins/NerdPack/include/NerdPackHelpers.php';
|
||||||
|
require_once '/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php';
|
||||||
$theme = $display["theme"];
|
|
||||||
$plg_path ="/boot/config/plugins/NerdPack";// plugin path
|
|
||||||
$pkg_path = "$plg_path/packages"; // package path
|
|
||||||
|
|
||||||
$pkg_repo = "https://api.github.com/repos/eschultz/unraid6-nerdpack/contents/packages";
|
|
||||||
$repo_file= "$pkg_path/packages.json";
|
|
||||||
|
|
||||||
$pkg_desc = "https://raw.githubusercontent.com/dmacias72/unRAID-plugins/master/plugins/packages-desc";
|
|
||||||
$desc_file= "$pkg_path/packages-desc";
|
|
||||||
|
|
||||||
get_content_from_github($pkg_repo, $repo_file);
|
get_content_from_github($pkg_repo, $repo_file);
|
||||||
get_content_from_github($pkg_desc, $desc_file);
|
get_content_from_github($pkg_desc, $desc_file);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<link type="text/css" rel="stylesheet" href="/plugins/NerdPack/css/NerdPack.css">
|
|
||||||
<link type="text/css" rel="stylesheet" href="/plugins/tablesorter/css/tablesorter.css">
|
<link type="text/css" rel="stylesheet" href="/plugins/tablesorter/css/tablesorter.css">
|
||||||
<link type="text/css" rel="stylesheet" href="/plugins/tablesorter/css/tablesorter-<?=$theme;?>.css">
|
<link type="text/css" rel="stylesheet" href="/plugins/tablesorter/css/tablesorter-<?=$display["theme"];?>.css">
|
||||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
||||||
|
<link type="text/css" rel="stylesheet" href="/plugins/NerdPack/css/NerdPack.css">
|
||||||
|
|
||||||
<span class="status" style="display: inline-block; margin-right: 110px;margin-top: -45px;"><input id="uninstallpkg" type="checkbox"></span>
|
<span class="status" style="display: inline-block;margin-right: 110px;margin-top: -45px;"><input id="uninstallpkg" type="checkbox"></span>
|
||||||
<span class="status" style="display: inline-block;margin-top: -45px;"><input id="deletepkg" 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" />
|
|
||||||
|
|
||||||
<table class="tablesorter hover-highlight" id="tblPackages">
|
<table class="tablesorter hover-highlight" id="tblPackages">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="filter-name" data-placeholder="Search..."> Name </th>
|
<th class="filter-name" data-placeholder="Search..."> Name </th>
|
||||||
<th class="filter-version" data-placeholder="by status"> Version </th>
|
<th class="filter-version" data-placeholder="by status"> Version </th>
|
||||||
<th class="sorter-metric filter-false" data-placeholder="by size"
|
<th class="sorter-metric filter-false" data-placeholder="by size" data-metric-name-full="byte|Byte|BYTE" data-metric-name-abbr="b|B"> Size </th>
|
||||||
data-metric-name-full="byte|Byte|BYTE" data-metric-name-abbr="b|B"> Size </th>
|
|
||||||
<th class="filter-downloaded" data-placeholder="by download"> Downloaded </th>
|
<th class="filter-downloaded" data-placeholder="by download"> Downloaded </th>
|
||||||
<th class="filter-installed" data-placeholder="by install"> Installed </th>
|
<th class="filter-installed" data-placeholder="by install"> Installed </th>
|
||||||
<th class="sorter-false filter-false"><input id="checkall" type="checkbox"></th>
|
<th class="parser-false filter-false"><input id="checkall" type="checkbox"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -48,9 +37,10 @@ get_content_from_github($pkg_desc, $desc_file);
|
||||||
|
|
||||||
<button title="reset filters" type="button" class="reset">Reset</button>
|
<button title="reset filters" type="button" class="reset">Reset</button>
|
||||||
: <input id="btnApply" type="button" value="Apply"><input type="button" value="Done" onClick="done()">
|
: <input id="btnApply" type="button" value="Apply"><input type="button" value="Done" onClick="done()">
|
||||||
|
<input type="hidden" name="#file" value="NerdPack/NerdPack.cfg">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script type="text/javascript" src="/plugins/NerdPack/js/jquery.NerdPack.js"></script>
|
|
||||||
<script type="text/javascript" src="/plugins/tablesorter/js/jquery.tablesorter.combined.min.js"></script>
|
<script type="text/javascript" src="/plugins/tablesorter/js/jquery.tablesorter.combined.min.js"></script>
|
||||||
<script type="text/javascript" src="/plugins/tablesorter/js/parsers/parser-metric.min.js"></script>
|
<script type="text/javascript" src="/plugins/tablesorter/js/parsers/parser-metric.min.js"></script>
|
||||||
<script type="text/javascript" src="/webGui/javascript/jquery.switchbutton.js"></script>
|
<script type="text/javascript" src="/webGui/javascript/jquery.switchbutton.js"></script>
|
||||||
|
<script type="text/javascript" src="/plugins/NerdPack/js/jquery.NerdPack.js"></script>
|
|
@ -1,3 +1,9 @@
|
||||||
.package {
|
.package {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
#package_form {
|
||||||
|
margin-top: -22px;
|
||||||
|
}
|
||||||
|
.switch-button-label.off {
|
||||||
|
color: inherit;
|
||||||
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Progress bar for curl download
|
// Progress bar for curl download
|
||||||
function progress_bar($download_size, $downloaded_size, $upload_size = null, $uploaded_size = null)
|
function progress_bar($download_size, $downloaded_size, $upload_size = null, $uploaded_size = null) {
|
||||||
{
|
|
||||||
ob_start();
|
ob_start();
|
||||||
static $previousProgress = 0;
|
static $previousProgress = 0;
|
||||||
|
|
||||||
|
@ -11,28 +10,27 @@ function progress_bar($download_size, $downloaded_size, $upload_size = null, $up
|
||||||
else
|
else
|
||||||
$progress = round($downloaded_size * 100 / $download_size);
|
$progress = round($downloaded_size * 100 / $download_size);
|
||||||
|
|
||||||
if ( $progress > $previousProgress){
|
if ($progress > $previousProgress) {
|
||||||
$previousProgress = $progress;
|
$previousProgress = $progress;
|
||||||
$pct=(double)($progress/100);
|
$pct = (double)($progress / 100);
|
||||||
$bar=round($pct * 30);
|
$bar = round($pct * 30);
|
||||||
$pct_disp=number_format($pct * 100, 0);
|
$pct_disp = number_format($pct * 100, 0);
|
||||||
$status_bar="\r[";
|
$status_bar = "\r[";
|
||||||
$status_bar.=str_repeat("|", $bar);
|
$status_bar .= str_repeat("|", $bar);
|
||||||
|
|
||||||
if($bar < 30){
|
if ($bar < 30) {
|
||||||
$status_bar.=">";
|
$status_bar .= ">";
|
||||||
$status_bar.=str_repeat("-", 30 - $bar);
|
$status_bar .= str_repeat("-", 30 - $bar);
|
||||||
} else {
|
} else {
|
||||||
$status_bar.="|";
|
$status_bar .= "|";
|
||||||
}
|
}
|
||||||
|
|
||||||
$status_bar.="] $pct_disp%";
|
$status_bar .= "] $pct_disp%";
|
||||||
|
|
||||||
echo $status_bar;
|
echo $status_bar;
|
||||||
ob_flush();
|
ob_flush();
|
||||||
|
|
||||||
|
if ($progress == 100) {
|
||||||
if($progress == 100) {
|
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,42 +46,39 @@ function get_file_from_url($file, $url) {
|
||||||
//curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
|
//curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
|
||||||
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
|
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, 'curl/' . $ch_vers['version'] );
|
curl_setopt($ch, CURLOPT_USERAGENT, 'curl/'.$ch_vers['version']);
|
||||||
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progress_bar' );
|
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progress_bar');
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_FILE, $chfile );
|
curl_setopt($ch, CURLOPT_FILE, $chfile);
|
||||||
curl_exec($ch);
|
curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
fclose($chfile);
|
fclose($chfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a json array of the contents of gihub repo
|
// get a json array of the contents of gihub repo
|
||||||
function get_content_from_github($repo, $file){
|
function get_content_from_github($repo, $file) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
$ch_vers = curl_version();
|
$ch_vers = curl_version();
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
|
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json', 'Content-Type: application/json']);
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, 'curl/' . $ch_vers['version'] );
|
curl_setopt($ch, CURLOPT_USERAGENT, 'curl/'.$ch_vers['version']);
|
||||||
curl_setopt($ch, CURLOPT_URL, $repo);
|
curl_setopt($ch, CURLOPT_URL, $repo);
|
||||||
$content = curl_exec($ch);
|
$content = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
if ((!empty($content)) && ($content != file_get_contents($file)))
|
if (!empty($content) && (!is_file($file) || $content != file_get_contents($file)))
|
||||||
file_put_contents($file, $content);
|
file_put_contents($file, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare the github sha1 value of a file
|
// Compare the github sha1 value of a file
|
||||||
function file_check_sha1($file, $sha1){
|
function file_check_sha1($file, $sha1) {
|
||||||
$size = filesize($file);
|
$size = filesize($file);
|
||||||
$handle = fopen($file, "rb");
|
$contents = file_get_contents($file);
|
||||||
$contents = fread($handle, $size);
|
|
||||||
fclose($handle);
|
|
||||||
|
|
||||||
// create a sha1 like github does
|
// create a sha1 like github does
|
||||||
$str = "blob ".$size."\0".$contents;
|
$str = "blob ".$size."\0".$contents;
|
||||||
$sha1_file = sha1($str);
|
$sha1_file = sha1($str);
|
||||||
|
|
||||||
$return = ($sha1_file == $sha1) ? true : false;
|
return ($sha1_file == $sha1);
|
||||||
return $return;
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -1,5 +1,39 @@
|
||||||
<?php
|
<?php
|
||||||
function format_size($value, $decimals, $unit='?') {
|
$plg_path = '/boot/config/plugins/NerdPack/'; // plugin path
|
||||||
|
$pkg_path = $plg_path.'packages/'; // package path
|
||||||
|
|
||||||
|
$pkg_desc = 'https://raw.githubusercontent.com/dmacias72/unRAID-plugins/master/plugins/packages-desc';
|
||||||
|
$pkg_repo = 'https://api.github.com/repos/eschultz/unraid6-nerdpack/contents/packages';
|
||||||
|
|
||||||
|
$desc_file = $pkg_path.'packages-desc';
|
||||||
|
$repo_file = $pkg_path.'packages.json';
|
||||||
|
$config_file = $plg_path.'NerdPack.cfg';
|
||||||
|
|
||||||
|
// get package configs
|
||||||
|
$pkg_cfg = (is_file($config_file)) ? parse_ini_file($config_file) : [];
|
||||||
|
|
||||||
|
// get array of downloaded packages
|
||||||
|
$pkgs_downloaded = file_exists($pkg_path) ? array_diff(scandir($pkg_path, 1), ['.', '..']) : [];
|
||||||
|
|
||||||
|
// get array of all installed packages
|
||||||
|
$pkgs_installed = array_diff(scandir("/var/log/packages", 1), ['.', '..']);
|
||||||
|
|
||||||
|
$pkgs_desc_file = (is_file($desc_file)) ? file_get_contents($desc_file) : '[]';
|
||||||
|
$pkgs_desc_array = json_decode($pkgs_desc_file, true);
|
||||||
|
|
||||||
|
$pkgs_github_file = (is_file($repo_file)) ? file_get_contents($repo_file) : '[]';
|
||||||
|
$pkgs_github_array = json_decode($pkgs_github_file, true);
|
||||||
|
|
||||||
|
|
||||||
|
function logger($output, $quiet = false) {
|
||||||
|
exec('echo '.escapeshellarg($output).' 2>&1 | logger -tnerdpack');
|
||||||
|
if (!$quiet) {
|
||||||
|
echo "\n".$output." \n";
|
||||||
|
usleep(100000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_size($value, $decimals, $unit = '?') {
|
||||||
if ($value == '')
|
if ($value == '')
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
|
|
||||||
|
@ -26,7 +60,7 @@ function format_size($value, $decimals, $unit='?') {
|
||||||
case 'T': return number_format($value / (float)1099511627776, $decimals).' TB';
|
case 'T': return number_format($value / (float)1099511627776, $decimals).' TB';
|
||||||
case 'G': return number_format($value / (float)(1 << 30), $decimals).' GB';
|
case 'G': return number_format($value / (float)(1 << 30), $decimals).' GB';
|
||||||
case 'M': return number_format($value / (float)(1 << 20), $decimals).' MB';
|
case 'M': return number_format($value / (float)(1 << 20), $decimals).' MB';
|
||||||
case 'K': return number_format($value / (float)(1 << 10), $decimals).' kB';
|
case 'K': return number_format($value / (float)(1 << 10), $decimals).' KB';
|
||||||
case 'B': return $value.' B';
|
case 'B': return $value.' B';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,68 +1,37 @@
|
||||||
<?php
|
<?php
|
||||||
require_once("/usr/local/emhttp/plugins/NerdPack/include/NerdPackHelpers.php");
|
require_once '/usr/local/emhttp/plugins/NerdPack/include/NerdPackHelpers.php';
|
||||||
|
|
||||||
$plg_path ="/boot/config/plugins/NerdPack";// plugin path
|
$pkgs_array = [];
|
||||||
$pkg_path = "$plg_path/packages/"; // package path
|
|
||||||
$config_file = "$plg_path/NerdPack.cfg";// config file
|
|
||||||
|
|
||||||
$pkg_cfg = (is_file($config_file)) ? parse_ini_file($config_file) : array(); // get package configs
|
foreach ($pkgs_github_array as $pkg_github) {
|
||||||
|
$pkg_nameArray = explode('-', $pkg_github['name']); // split package name into array
|
||||||
$pkgs_downloaded = array_diff( scandir($pkg_path, 1), array(".", "..") ); // get array of downloaded packages
|
|
||||||
|
|
||||||
$pkgs_installed = array_diff( scandir("/var/log/packages", 1), array(".", "..") ); // get array of all installed packages
|
|
||||||
|
|
||||||
$pkgs_desc_file = file_get_contents($pkg_path."packages-desc");// get package descriptions
|
|
||||||
$pkgs_desc_array = json_decode($pkgs_desc_file, true);
|
|
||||||
|
|
||||||
$pkgs_github_file = file_get_contents($pkg_path."packages.json");// get packages
|
|
||||||
$pkgs_github_array = json_decode($pkgs_github_file, true);
|
|
||||||
|
|
||||||
$pkgs_array = array();
|
|
||||||
|
|
||||||
for ($i = 0; $i < sizeof($pkgs_github_array); $i++) {
|
|
||||||
|
|
||||||
$pkg_nameArray = explode("-", $pkgs_github_array[$i]["name"]); // split package name into array
|
|
||||||
|
|
||||||
$pkg_name = $pkg_nameArray[0];
|
$pkg_name = $pkg_nameArray[0];
|
||||||
if (sizeof($pkg_nameArray) > 4){ //if package name has a subset get it
|
if (sizeof($pkg_nameArray) > 4) { //if package name has a subset get it
|
||||||
for ($ii = 1; $ii < sizeof($pkg_nameArray)-3; $ii++) {
|
for ($ii = 1; $ii < sizeof($pkg_nameArray)-3; $ii++) {
|
||||||
$pkg_name = $pkg_name."-".$pkg_nameArray[$ii];
|
$pkg_name .= '-'.$pkg_nameArray[$ii];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$pkg_version = $pkg_nameArray[sizeof($pkg_nameArray)-3]; // get package version
|
$pkg_version = $pkg_nameArray[sizeof($pkg_nameArray) - 3]; // get package version
|
||||||
|
|
||||||
$pkg_nver = $pkg_name."-".str_replace(".", "_", $pkg_version); // add underscored version to package name
|
$pkg_nver = $pkg_name.'-'.str_replace('.', '_', $pkg_version); // add underscored version to package name
|
||||||
|
|
||||||
$pkg_pattern = "/^".$pkg_name.".*/"; // search patter for packages
|
$pkg_pattern = '/^'.$pkg_name.'.*/'; // search patter for packages
|
||||||
|
|
||||||
$pkg = array();
|
$pkg = [
|
||||||
|
'name' => $pkg_github['name'], // add full package name
|
||||||
$pkg["name"] = $pkgs_github_array[$i]["name"]; // add full package name
|
'pkgname' => $pkg_name, // add package name only
|
||||||
|
'pkgnver' => $pkg_nver, // add package name with underscored version
|
||||||
$pkg["pkgname"] = $pkg_name; // add package name only
|
'pkgversion' => $pkg_version, // add package name with raw version
|
||||||
|
'size' => format_size($pkg_github['size'], 1, '?'), // add package size
|
||||||
$pkg["pkgnver"] = $pkg_nver; // add package name with underscored version
|
'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
|
||||||
$pkg["pkgversion"] = $pkg_version; // add package name with underscored version
|
'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
|
||||||
$pkg["size"] = format_size($pkgs_github_array[$i]["size"], 1, '?'); // add package size
|
'config' => isset($pkg_cfg[$pkg_nver]) ? $pkg_cfg[$pkg_nver] : 'no', // checks config for install preference
|
||||||
|
'desc' => $pkgs_desc_array[$pkg_name]
|
||||||
// checks if package name is installed
|
];
|
||||||
$pkg["installed"] = preg_grep($pkg_pattern , $pkgs_installed) ? "yes" : "no";
|
|
||||||
|
|
||||||
// checks if package is installed equals github exactly
|
|
||||||
$pkg["installeq"] = in_array( pathinfo($pkgs_github_array[$i]["name"], PATHINFO_FILENAME), $pkgs_installed ) ? "yes" : "no";
|
|
||||||
|
|
||||||
// checks if package name is downloaded
|
|
||||||
$pkg["downloaded"] = preg_grep($pkg_pattern , $pkgs_downloaded) ? "yes" : "no";
|
|
||||||
|
|
||||||
// checks if package is downloaded equals github exactly
|
|
||||||
$pkg["downloadeq"] = in_array( $pkgs_github_array[$i]["name"], $pkgs_downloaded ) ? "yes" : "no";
|
|
||||||
|
|
||||||
$pkg["config"] = isset($pkg_cfg["$pkg_nver"]) ? $pkg_cfg["$pkg_nver"] : "no"; // checks config for install preference
|
|
||||||
|
|
||||||
$pkg["desc"] = $pkgs_desc_array["$pkg_name"];
|
|
||||||
|
|
||||||
$pkgs_array[] = $pkg;
|
$pkgs_array[] = $pkg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,153 +1,132 @@
|
||||||
$(function(){
|
$(function(){
|
||||||
// "uninstall package" switch and cookie
|
// tablesorter options
|
||||||
$('#uninstallpkg')
|
$("#tblPackages").tablesorter({
|
||||||
.switchButton({
|
sortList: [[0,1]],
|
||||||
labels_placement: "left",
|
widgets: ["saveSort", "filter", "stickyHeaders"],
|
||||||
on_label: 'unInstall On',
|
widgetOptions: {
|
||||||
off_label: 'unInstall Off',
|
stickyHeaders_filteredToTop: true,
|
||||||
checked: $.cookie('nerdpack_packages_uninstall') == '--uninstall'
|
filter_hideEmpty: true,
|
||||||
})
|
filter_liveSearch: true,
|
||||||
.change(function () {
|
filter_saveFilters: true,
|
||||||
$.cookie('nerdpack_packages_uninstall', $('#uninstallpkg').prop('checked') ? '--uninstall' : '', { expires: 3650 });
|
filter_reset: "button.reset",
|
||||||
|
filter_functions: {
|
||||||
|
".filter-version": true,
|
||||||
|
".filter-downloaded": true,
|
||||||
|
".filter-installed": true
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// "uninstall package" switch and cookie
|
||||||
|
$("#uninstallpkg")
|
||||||
|
.switchButton({
|
||||||
|
labels_placement: "left",
|
||||||
|
on_label: "unInstall On",
|
||||||
|
off_label: "unInstall Off",
|
||||||
|
checked: $.cookie("nerdpack_packages_uninstall") == "--uninstall"
|
||||||
|
})
|
||||||
|
.change(function () {
|
||||||
|
$.cookie("nerdpack_packages_uninstall", $(this).prop("checked") ? "--uninstall" : "", { expires: 3650 });
|
||||||
|
});
|
||||||
|
|
||||||
// "delete package" switch and cookie
|
// "delete package" switch and cookie
|
||||||
$('#deletepkg')
|
$("#deletepkg")
|
||||||
.switchButton({
|
.switchButton({
|
||||||
labels_placement: "left",
|
labels_placement: "left",
|
||||||
on_label: 'delete On',
|
on_label: "delete On",
|
||||||
off_label: 'delete Off',
|
off_label: "delete Off",
|
||||||
checked: $.cookie('nerdpack_packages_delete') == '--delete'
|
checked: $.cookie("nerdpack_packages_delete") == "--delete"
|
||||||
})
|
})
|
||||||
.change(function () {
|
.change(function () {
|
||||||
$.cookie('nerdpack_packages_delete', $('#deletepkg').prop('checked') ? '--delete' : '', { expires: 3650 });
|
$.cookie("nerdpack_packages_delete", $(this).prop("checked") ? "--delete" : "", { expires: 3650 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// select all packages switch
|
// select all packages switch
|
||||||
$('#checkall')
|
$("#checkall")
|
||||||
.switchButton({
|
.switchButton({
|
||||||
labels_placement: "right",
|
labels_placement: "right",
|
||||||
on_label: 'Select All',
|
on_label: "Select All",
|
||||||
off_label: 'Select All',
|
off_label: "Select All",
|
||||||
checked: $.cookie('nerdpack_checkall') == 'yes'
|
checked: $.cookie("nerdpack_checkall") == "yes"
|
||||||
})
|
})
|
||||||
.change(function() { //on change
|
.change(function () {
|
||||||
if(this.checked) { // check select status
|
var myval = $(this).prop("checked");
|
||||||
$('.pkgcheckbox').each(function() { //loop through each checkbox
|
$.cookie("nerdpack_checkall", myval ? "yes" : "no", { expires: 3650 });
|
||||||
$(this).switchButton({checked: true});
|
$(".pkgcheckbox").each(function() { // loop through each checkbox
|
||||||
});
|
$(this).switchButton({checked: myval});
|
||||||
$('.pkgvalue').each(function() { //loop through each value
|
});
|
||||||
$(this).val('yes');
|
$(".pkgvalue").each(function() { // loop through each value
|
||||||
});
|
$(this).val(myval ? "yes": "no");
|
||||||
}else{
|
});
|
||||||
$('.pkgcheckbox').each(function() { //loop through each checkbox
|
});
|
||||||
$(this).switchButton({checked: false});
|
|
||||||
});
|
|
||||||
$('.pkgvalue').each(function() { //loop through each value
|
|
||||||
$(this).val('no');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// set cookie on apply button press
|
// set cookie on apply button press
|
||||||
$('#btnApply').click(function(event) {
|
$("#btnApply").click(function() {
|
||||||
$.cookie('nerdpack_checkall', $('#checkall').prop('checked') ? 'yes' : 'no', { expires: 3650 });
|
checkDepends();
|
||||||
packageManager();
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "/update.php",
|
||||||
|
data: $("#package_form").serializeArray(),
|
||||||
|
success: function() {
|
||||||
|
openBox("/plugins/NerdPack/scripts/packagemanager&arg1=--download"+
|
||||||
|
"&arg2="+$.cookie("nerdpack_packages_uninstall")+
|
||||||
|
"&arg3="+$.cookie("nerdpack_packages_delete"),
|
||||||
|
"Package Manager", 600, 900, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
packageQuery();
|
packageQuery();
|
||||||
});
|
});
|
||||||
|
|
||||||
function packageManager() {
|
|
||||||
$.ajax({
|
|
||||||
type : "POST",
|
|
||||||
url : "/update.php",
|
|
||||||
data : $('#package_form').serializeArray(),
|
|
||||||
success: function() {
|
|
||||||
openBox('/plugins/NerdPack/scripts/packagemanager&arg1=--download'+
|
|
||||||
'&arg2='+$.cookie('nerdpack_packages_uninstall')+
|
|
||||||
'&arg3='+$.cookie('nerdpack_packages_delete'),
|
|
||||||
'Package Manager',600,900,true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
//list all available packages in a table
|
//list all available packages in a table
|
||||||
function packageQuery() {
|
function packageQuery() {
|
||||||
$("#tblPackages tbody").empty();
|
$("#tblPackages tbody").empty();
|
||||||
$.ajax({
|
$.getJSON("/plugins/NerdPack/include/PackageQuery.php", function(data) {
|
||||||
type: "GET",
|
for (var i in data) {
|
||||||
dataType: "json",
|
var Update;
|
||||||
url: "/plugins/NerdPack/include/PackageQuery.php",
|
if (data[i].downloadeq == data[i].downloaded && data[i].installeq == data[i].installed)
|
||||||
success: function(data) {
|
Update = "<span style=\"color:#44B012;white-space:nowrap;\"><i class=\"fa fa-check\"></i> up-to-date</span>";
|
||||||
for( i in data ) {
|
else
|
||||||
var Update;
|
Update = "<span style=\"white-space:nowrap;\"><a><i class=\"fa fa-cloud-download\"></i> update ready</a></span>";
|
||||||
if (data[i].downloadeq == data[i].downloaded && data[i].installeq == data[i].installed )
|
|
||||||
Update = "<span style=\"color:#44B012;white-space:nowrap;\"><i class=\"fa fa-check\"></i> up-to-date</span>";
|
|
||||||
else
|
|
||||||
Update = "<span style=\"white-space:nowrap;\"><i class=\"fa fa-cloud-download\"></i><a> update ready<a></span>";
|
|
||||||
|
|
||||||
$("#tblPackages tbody").append(
|
$("#tblPackages tbody").append(
|
||||||
"<tr>"+
|
"<tr>"+
|
||||||
"<td class='package' title='"+data[i].desc+"'>"+data[i].name+"</td>"+ //package name
|
"<td class='package' title='"+data[i].desc+"'>"+data[i].name+"</td>"+ // package name
|
||||||
"<td>"+Update+"</td>"+ //package status
|
"<td>"+Update+"</td>"+ // package status
|
||||||
"<td>"+data[i].size+"</td>"+ //package size
|
"<td>"+data[i].size+"</td>"+ // package size
|
||||||
"<td>"+data[i].downloaded+"</td>"+ //package installed
|
"<td>"+data[i].downloaded+"</td>"+ // package installed
|
||||||
"<td>"+data[i].installed+"</td>"+ //package installed
|
"<td>"+data[i].installed+"</td>"+ // package installed
|
||||||
"<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>"+
|
"</tr>");
|
||||||
"</tr>");
|
|
||||||
|
|
||||||
$('#'+data[i].pkgname)
|
$("#"+data[i].pkgname)
|
||||||
.switchButton({
|
.switchButton({
|
||||||
labels_placement: 'right',
|
labels_placement: "right",
|
||||||
on_label: 'On',
|
on_label: "On",
|
||||||
off_label: 'Off',
|
off_label: "Off",
|
||||||
checked: data[i].config == "yes"
|
checked: data[i].config == "yes"
|
||||||
})
|
})
|
||||||
.change(function() {
|
.change(function() {
|
||||||
var par = $(this).parent().parent();
|
$(this).parent().parent().find(".pkgvalue").val(this.checked ? "yes": "no");
|
||||||
if(this.checked)
|
if (this.checked)
|
||||||
par.find('.pkgvalue').val("yes");
|
checkDepends();
|
||||||
else
|
|
||||||
par.find('.pkgvalue').val("no");
|
|
||||||
$("#btnApply").prop("disabled", false);
|
$("#btnApply").prop("disabled", false);
|
||||||
checkDepends();
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
$("#tblPackages").trigger("update");
|
|
||||||
|
|
||||||
//tablesorter options
|
|
||||||
$('#tblPackages').tablesorter({
|
|
||||||
sortList: [[0,1]],
|
|
||||||
widgets: ['saveSort', 'filter', 'stickyHeaders'],
|
|
||||||
widgetOptions: {
|
|
||||||
stickyHeaders_filteredToTop: true,
|
|
||||||
filter_hideEmpty : true,
|
|
||||||
filter_liveSearch : true,
|
|
||||||
filter_saveFilters : true,
|
|
||||||
filter_reset : 'button.reset',
|
|
||||||
filter_functions: {
|
|
||||||
'.filter-version' : true,
|
|
||||||
'.filter-downloaded' : true,
|
|
||||||
'.filter-installed' : true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
}
|
}
|
||||||
|
$("#tblPackages").trigger("update");
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
function checkDepends() {
|
function checkDepends() {
|
||||||
if ($('#screen').prop('checked') == true){
|
if ($("#screen").prop("checked")) {
|
||||||
$('#utempter').switchButton({checked: true});
|
$("#utempter").switchButton({checked: true});
|
||||||
$('#utempter','.pkgvalue').val('yes');
|
$("#utempter", ".pkgvalue").val("yes");
|
||||||
}
|
}
|
||||||
if ($('#iotop').prop('checked') == true){
|
if ($("#iotop").prop("checked")) {
|
||||||
$('#python').switchButton({checked: true});
|
$("#python").switchButton({checked: true});
|
||||||
$('#python','.pkgvalue').val('yes');
|
$("#python", ".pkgvalue").val("yes");
|
||||||
}
|
}
|
||||||
};
|
}
|
|
@ -18,8 +18,8 @@ Usage: packagemanager [options]
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
$shortopts = "drquv";
|
$shortopts = "drquv";
|
||||||
$longopts = array(
|
$longopts = [
|
||||||
"delete",
|
"delete",
|
||||||
"download",
|
"download",
|
||||||
"help",
|
"help",
|
||||||
|
@ -27,17 +27,17 @@ $longopts = array(
|
||||||
"uninstall",
|
"uninstall",
|
||||||
"verbose",
|
"verbose",
|
||||||
"version"
|
"version"
|
||||||
);
|
];
|
||||||
$args = getopt($shortopts, $longopts);
|
$args = getopt($shortopts, $longopts);
|
||||||
|
|
||||||
if (array_key_exists("help", $args)) {
|
if (array_key_exists("help", $args)) {
|
||||||
echo $usage;
|
echo $usage;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists("version", $args)) {
|
if (array_key_exists("version", $args)) {
|
||||||
echo "Package Manager Version: 1.2\n";
|
echo "Package Manager Version: 1.2\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$argd = (array_key_exists("d", $args) || array_key_exists("download", $args));
|
$argd = (array_key_exists("d", $args) || array_key_exists("download", $args));
|
||||||
|
@ -46,89 +46,63 @@ $argr = (array_key_exists("r", $args) || array_key_exists("delete", $args));
|
||||||
$argu = (array_key_exists("u", $args) || array_key_exists("uninstall", $args));
|
$argu = (array_key_exists("u", $args) || array_key_exists("uninstall", $args));
|
||||||
$argv = (array_key_exists("v", $args) || array_key_exists("verbose", $args));
|
$argv = (array_key_exists("v", $args) || array_key_exists("verbose", $args));
|
||||||
|
|
||||||
require_once("/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php");
|
require_once '/usr/local/emhttp/plugins/NerdPack/include/NerdPackHelpers.php';
|
||||||
|
require_once '/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php';
|
||||||
|
|
||||||
function logger($output, $quiet) {
|
logger('Processing Packages...');
|
||||||
shell_exec( "echo '$output' 2>&1 | logger -tnerdpack");
|
|
||||||
if (!$quiet)
|
|
||||||
echo "\n".$output." \n";
|
|
||||||
usleep(100000);
|
|
||||||
}
|
|
||||||
|
|
||||||
$plg_path ="/boot/config/plugins/NerdPack";// plugin path
|
|
||||||
$pkg_path = "$plg_path/packages/"; // package path
|
|
||||||
$config_file = "$plg_path/NerdPack.cfg";// config file
|
|
||||||
|
|
||||||
$pkg_cfg = (is_file($config_file)) ? parse_ini_file($config_file) : array(); // get package configs
|
|
||||||
|
|
||||||
$pkgs_downloaded = array_diff( scandir($pkg_path, 1), array(".", "..") ); // get array of packages
|
|
||||||
|
|
||||||
$pkgs_installed = array_diff( scandir("/var/log/packages", 1), array(".", "..") );
|
|
||||||
|
|
||||||
$pkgs_json = $pkg_path."packages.json";
|
|
||||||
$pkgs_file = (is_file($pkgs_json)) ? file_get_contents($pkgs_json) : array();
|
|
||||||
|
|
||||||
$pkgs_github = json_decode($pkgs_file, true);
|
|
||||||
|
|
||||||
logger("Processing Packages...", 0);
|
|
||||||
|
|
||||||
foreach($pkg_cfg as $pkg_name => $pkg_pref) { //get preferences for each package
|
|
||||||
|
|
||||||
|
foreach ($pkg_cfg as $pkg_name => $pkg_pref) { // get preferences for each package
|
||||||
$pkg_cmd = '';
|
$pkg_cmd = '';
|
||||||
$pkg_name = str_replace("_", ".", $pkg_name); // replace "_" with "." in package names
|
$pkg_name = str_replace('_', '.', $pkg_name); // replace "_" with "." in package names
|
||||||
$pkg_pattern = "/^".$pkg_name.".*/"; // search patter for packages
|
$pkg_pattern = '/^'.$pkg_name.'.*/'; // search patter for packages
|
||||||
$pkg_install_status = preg_grep($pkg_pattern, $pkgs_installed); // check install status
|
$pkg_install_status = preg_grep($pkg_pattern, $pkgs_installed); // check install status
|
||||||
|
|
||||||
if($pkg_pref == "yes"){
|
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 executing from the wegui check status and download if necessary
|
$pkg_online_status = preg_grep($pkg_pattern, $pkgs_github_array);
|
||||||
if ($argd){
|
|
||||||
|
|
||||||
if(!preg_grep($pkg_pattern, $pkgs_downloaded)) {
|
$pkg_matches = array_filter($pkgs_github_array, function($a) use ($pkg_pattern) {
|
||||||
|
return preg_grep($pkg_pattern, $a);
|
||||||
$pkg_online_status = preg_grep($pkg_pattern , $pkgs_github);
|
|
||||||
|
|
||||||
$pkg_matches = array_filter($pkgs_github, function($a) use($pkg_pattern ) {
|
|
||||||
return preg_grep($pkg_pattern , $a);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$pkg_gitname = array_values($pkg_matches)[0]["name"];
|
$pkg_gitname = array_values($pkg_matches)[0]['name'];
|
||||||
$pkg_file = $pkg_path.$pkg_gitname;
|
$pkg_file = $pkg_path.$pkg_gitname;
|
||||||
$pkg_url = array_values($pkg_matches)[0]["download_url"];
|
$pkg_url = array_values($pkg_matches)[0]['download_url'];
|
||||||
$pkg_sha1 = array_values($pkg_matches)[0]["sha"];
|
$pkg_sha1 = array_values($pkg_matches)[0]['sha'];
|
||||||
|
|
||||||
logger("Downloading $pkg_gitname package...", $argq);
|
logger('Downloading '.$pkg_gitname.' package...', $argq);
|
||||||
|
|
||||||
get_file_from_url($pkg_file, $pkg_url);
|
get_file_from_url($pkg_file, $pkg_url);
|
||||||
|
|
||||||
if(file_check_sha1($pkg_file, $pkg_sha1))
|
if (file_check_sha1($pkg_file, $pkg_sha1))
|
||||||
logger("$pkg_gitname package downloaded sucessfully!", $argq);
|
logger($pkg_gitname.' package downloaded sucessfully!', $argq);
|
||||||
else
|
else
|
||||||
logger("$pkg_gitname package download failed!", $argq);
|
logger($pkg_gitname.' package download failed!', $argq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$pkg_install_status){
|
if (!$pkg_install_status) {
|
||||||
$pkg_msg = "Installing";
|
$pkg_msg = 'Installing';
|
||||||
$pkg_cmd = "upgradepkg --install-new ".$pkg_path.$pkg_name."* 2>&1";
|
$pkg_cmd = 'upgradepkg --install-new '.$pkg_path.$pkg_name.'* 2>&1';
|
||||||
}
|
}
|
||||||
}elseif($pkg_pref == "no" && $pkg_install_status && $argu){
|
} else if ($pkg_pref == 'no' && $pkg_install_status && $argu) {
|
||||||
|
$pkg_msg = 'Uninstalling';
|
||||||
$pkg_msg = "Uninstalling";
|
$pkg_cmd = 'removepkg '.$pkg_path.$pkg_name.'* 2>&1';
|
||||||
$pkg_cmd = "removepkg ".$pkg_path.$pkg_name."* 2>&1";
|
if ($argr) {
|
||||||
if ($argr){
|
$pkg_cmd .= '; rm '.$pkg_path.$pkg_name.'* 2>&1';
|
||||||
$pkg_cmd .= "; rm ".$pkg_path.$pkg_name."* 2>&1";
|
$pkg_msg .= ' and deleting';
|
||||||
$pkg_msg .= " and deleting";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!empty($pkg_cmd)){
|
if (!empty($pkg_cmd)) {
|
||||||
logger("$pkg_msg $pkg_name package...", 0);
|
logger($pkg_msg.' '.$pkg_name.' package...');
|
||||||
shell_exec($pkg_cmd);
|
shell_exec($pkg_cmd);
|
||||||
//$output = shell_exec($pkg_cmd);
|
//$output = shell_exec($pkg_cmd);
|
||||||
//logger($output);
|
//logger($output);
|
||||||
}else
|
} else
|
||||||
logger($pkg_name." package up to date", $argq);
|
logger($pkg_name.' package up to date', $argq);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger("All packages processed", 0);
|
logger('All packages processed');
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user