formatting, add package json and desc to scandir filter
This commit is contained in:
parent
45afd2f9e5
commit
9ad12b1a00
|
@ -3,7 +3,7 @@ $plg_path = '/boot/config/plugins/NerdPack/'; // plugin path
|
||||||
$os_version = substr(parse_ini_file('/etc/unraid-version')['version'],0,3);
|
$os_version = substr(parse_ini_file('/etc/unraid-version')['version'],0,3);
|
||||||
$pkg_path = $plg_path."packages/$os_version/"; // package path
|
$pkg_path = $plg_path."packages/$os_version/"; // package path
|
||||||
if (!is_dir($pkg_path))
|
if (!is_dir($pkg_path))
|
||||||
mkdir($pkg_path);
|
mkdir($pkg_path);
|
||||||
|
|
||||||
$pkg_desc = 'https://raw.githubusercontent.com/dmacias72/unRAID-plugins/master/plugins/packages-desc';
|
$pkg_desc = 'https://raw.githubusercontent.com/dmacias72/unRAID-plugins/master/plugins/packages-desc';
|
||||||
$pkg_repo = "https://api.github.com/repos/dmacias72/unRAID-plugins/contents/packages/$os_version";
|
$pkg_repo = "https://api.github.com/repos/dmacias72/unRAID-plugins/contents/packages/$os_version";
|
||||||
|
@ -16,7 +16,7 @@ $config_file = $plg_path.'NerdPack.cfg';
|
||||||
$pkg_cfg = (is_file($config_file)) ? parse_ini_file($config_file) : [];
|
$pkg_cfg = (is_file($config_file)) ? parse_ini_file($config_file) : [];
|
||||||
|
|
||||||
// get array of downloaded packages
|
// get array of downloaded packages
|
||||||
$pkgs_downloaded = file_exists($pkg_path) ? array_diff(scandir($pkg_path, 1), ['.', '..']) : [];
|
$pkgs_downloaded = file_exists($pkg_path) ? array_diff(scandir($pkg_path, 1), ['.', '..','packages.json','packages-desc']) : [];
|
||||||
|
|
||||||
// get array of all installed packages
|
// get array of all installed packages
|
||||||
$pkgs_installed = array_diff(scandir("/var/log/packages", 1), ['.', '..']);
|
$pkgs_installed = array_diff(scandir("/var/log/packages", 1), ['.', '..']);
|
||||||
|
@ -29,44 +29,44 @@ $pkgs_github_array = json_decode($pkgs_github_file, true);
|
||||||
|
|
||||||
|
|
||||||
function logger($output, $quiet = false) {
|
function logger($output, $quiet = false) {
|
||||||
exec('echo '.escapeshellarg($output).' 2>&1 | logger -tnerdpack');
|
exec('echo '.escapeshellarg($output).' 2>&1 | logger -tnerdpack');
|
||||||
if (!$quiet) {
|
if (!$quiet) {
|
||||||
echo "\n".$output." \n";
|
echo "\n".$output." \n";
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function format_size($value, $decimals, $unit = '?') {
|
function format_size($value, $decimals, $unit = '?') {
|
||||||
if ($value == '')
|
if ($value == '')
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
|
|
||||||
/* Autodetect unit that's appropriate */
|
/* Autodetect unit that's appropriate */
|
||||||
if ($unit == '?') {
|
if ($unit == '?') {
|
||||||
if ($value >= 1099511627776)
|
if ($value >= 1099511627776)
|
||||||
$unit = 'T';
|
$unit = 'T';
|
||||||
else
|
else
|
||||||
if ($value >= (1 << 30))
|
if ($value >= (1 << 30))
|
||||||
$unit = 'G';
|
$unit = 'G';
|
||||||
else
|
else
|
||||||
if ($value >= (1 << 20))
|
if ($value >= (1 << 20))
|
||||||
$unit = 'M';
|
$unit = 'M';
|
||||||
else
|
else
|
||||||
if ($value >= (1 << 10))
|
if ($value >= (1 << 10))
|
||||||
$unit = 'K';
|
$unit = 'K';
|
||||||
else
|
else
|
||||||
$unit = 'B';
|
$unit = 'B';
|
||||||
}
|
}
|
||||||
|
|
||||||
$unit = strtoupper($unit);
|
$unit = strtoupper($unit);
|
||||||
|
|
||||||
switch ($unit) {
|
switch ($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';
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user