fix empty package list on new install

This commit is contained in:
Derek Macias 2016-09-16 11:01:40 -06:00
parent c26f03a888
commit 321546778c
3 changed files with 23 additions and 19 deletions

View File

@ -21,12 +21,9 @@ $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);
$pkgs_desc_array = (file_exists($desc_file)) ? json_decode(file_get_contents($desc_file), true) : '[]';
$pkgs_github_array = (file_exists($repo_file)) ? json_decode(file_get_contents($repo_file), true) : '[]';
function logger($output, $quiet = false) {
exec('echo '.escapeshellarg($output).' 2>&1 | logger -tnerdpack');

View File

@ -3,9 +3,11 @@ require_once '/usr/local/emhttp/plugins/NerdPack/include/NerdPackHelpers.php';
require_once '/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php';
// Only download repo update if the current one is 1 hour old or more
if (!is_file($repo_file) || !empty($_GET['force']) || (filemtime($repo_file) < (time() - 3600))) {
if (!file_exists($repo_file) || !empty($_GET['force']) || (filemtime($repo_file) < (time() - 3600))) {
get_content_from_github($pkg_repo, $repo_file);
get_content_from_github($pkg_desc, $desc_file);
$pkgs_desc_array = (file_exists($desc_file)) ? json_decode(file_get_contents($desc_file), true) : '[]';
$pkgs_github_array = (file_exists($repo_file)) ? json_decode(file_get_contents($repo_file), true) : '[]';
}
$pkgs_array = [];

View File

@ -57,16 +57,16 @@ foreach ($pkg_cfg as $pkg_name => $pkg_pref) { // get preferences for each packa
$pkg_pattern = '/^'.$pkg_name.'.*/'; // search pattern 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
$pkg_online_status = preg_grep($pkg_pattern, $pkgs_github_array);
$pkg_online_status = preg_grep($pkg_pattern, $pkgs_github_array);
$pkg_matches = array_filter($pkgs_github_array, function($a) use ($pkg_pattern) {
return preg_grep($pkg_pattern, $a);
});
$pkg_matches = array_filter($pkgs_github_array, function($a) use ($pkg_pattern) {
return preg_grep($pkg_pattern, $a);
});
$pkg_gitname = array_values($pkg_matches)[0]['name'];
$pkg_file = $pkg_path.$pkg_gitname;
$pkg_url = array_values($pkg_matches)[0]['download_url'];
$pkg_sha1 = array_values($pkg_matches)[0]['sha'];
$pkg_gitname = array_values($pkg_matches)[0]['name'];
$pkg_file = $pkg_path.$pkg_gitname;
$pkg_url = array_values($pkg_matches)[0]['download_url'];
$pkg_sha1 = array_values($pkg_matches)[0]['sha'];
//check if plugin is dependent on package
$plugins = [];
@ -75,8 +75,8 @@ foreach ($pkg_cfg as $pkg_name => $pkg_pref) { // get preferences for each packa
$plg_msg = "$pkg_name used by plugin: ";
foreach ($plugins as $plugin){
$plg_msg .= pathinfo($plugin, PATHINFO_FILENAME).", ";
}
logger(substr($plg_msg, 0, -2));
}
logger(substr($plg_msg, 0, -2));
}
if ($pkg_pref == 'yes') { // if package is selected to be installed
@ -97,10 +97,12 @@ foreach ($pkg_cfg as $pkg_name => $pkg_pref) { // get preferences for each packa
}
}
}
if (!$pkg_install_status) { // if package is not installed
$pkg_msg = 'Installing';
$pkg_cmd = 'upgradepkg --install-new '.$pkg_path.$pkg_name.'* 2>&1';
}
} else if ($pkg_pref == 'no' && $pkg_install_status && $argu) {
if($plugins){
logger("$pkg_name in use by another plugin, not uninstalled.",$argq);
@ -113,6 +115,7 @@ foreach ($pkg_cfg as $pkg_name => $pkg_pref) { // get preferences for each packa
}
}
}
if (!empty($pkg_cmd)) {
logger("$pkg_msg $pkg_name package...");
shell_exec($pkg_cmd);
@ -122,14 +125,16 @@ foreach ($pkg_cfg as $pkg_name => $pkg_pref) { // get preferences for each packa
if ($pkg_pref == 'yes'){
if (file_exists($pkg_file)){
if (file_check_sha1($pkg_file, $pkg_sha1))
logger($pkg_gitname.' package up to date, checksum ok.', $argq);
$pkg_msg = 'package up to date, checksum ok.';
else{
if (file_exists($pkg_file))
unlink($pkg_file);
logger($pkg_gitname.' package checksum failed! package deleted.', $argq);
$pkg_msg = 'checksum failed! package deleted.';
}
}else
logger($pkg_gitname.' package missing!', $argq);
$pkg_msg = ' package missing!';
logger($pkg_name." $pkg_msg", $argq);
}
}
}