Add "Check for Updates" button and disable auto-check as needed

This commit is contained in:
bergware
2017-06-22 22:08:37 +02:00
parent e37edf5613
commit 4571a2fde0
4 changed files with 44 additions and 18 deletions
+6 -2
View File
@@ -19,7 +19,8 @@ Tabs="true"
<?
$empty = "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-spinner fa-spin icon'></i><em>Please wait, retrieving and updating plugin information ...</em></td><tr>";
// Remove stale /tmp/plugin/*.plg entries
if ($path != $prev) foreach (glob("/tmp/plugins/*.{plg,txt}", GLOB_NOSORT+GLOB_BRACE) as $entry) if (!file_exists("/var/log/plugins/".basename($entry))) @unlink($entry);
foreach (glob("/tmp/plugins/*.{plg,txt}", GLOB_NOSORT+GLOB_BRACE) as $entry) if (!file_exists("/var/log/plugins/".basename($entry))) @unlink($entry);
$audit = $notify['version'] ? 1 : 0;
?>
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
<style>
@@ -41,7 +42,7 @@ function resize(bind) {
}
<?endif;?>
$(function() {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{},function(data) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{audit:<?=$audit?>},function(data) {
if (data) $('#plugin_list').html(data);
<?if ($display['resize']):?>
resize();
@@ -51,6 +52,9 @@ $(function() {
$('.desc_readmore').readmore({maxHeight:58});
});
$('#plugin_tree').fileTree({root:'/boot/',filter:'plg'}, function(file) {$('#plugin_file').val(file);});
<?if (!$audit):?>
$('.tabs').append("<span class='status vhshift'><input type='button' value='Check for Updates' onclick='openBox(\"/plugins/dynamix.plugin.manager/scripts/plugin&arg1=checkall\",\"Plugin Update Check\",490,430,true)'></span>");
<?endif;?>
});
</script>
<table class='tablesorter plugins shift' id='plugin_table'>
+14 -8
View File
@@ -14,34 +14,40 @@ Title="Update OS"
*/
?>
<?$empty = "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-spinner fa-spin icon'></i><em>Please wait, retrieving and updating system information ...</em></td><tr>"?>
<?
$empty = "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-spinner fa-spin icon'></i><em>Please wait, retrieving and updating system information ...</em></td><tr>";
$audit = $notify['unraidos'] ? 1 : 0;
?>
<script>
var original = null;
function update_table(release) {
function update_table(branch) {
$('#os_list').html("<?=$empty?>");
if (original) {
if (release != original) release = '';
if (branch != original) branch = '';
} else {
if (release) original = release;
if (branch) original = branch;
}
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true',release:release},function(data) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true',branch:branch},function(data) {
if (data) $('#os_list').html(data);
$('#os_table').trigger('update',true);
});
}
$(function() {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true'},function(data) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true',audit:<?=$audit?>},function(data) {
if (data) $('#os_list').html(data);
$('#os_table').tablesorter({sortList:[[1,0]],headers:{0:{sorter:false},5:{sorter:false}}});
<?if (preg_match("/^\*\*REBOOT REQUIRED\!\*\*/",@file_get_contents("$docroot/plugins/unRAIDServer/README.md"))):?>
$('#change_release').prop('disabled',true);
$('#change_branch').prop('disabled',true);
<?endif;?>
});
<?if (!$audit):?>
$('.tabs').append("<span class='status vhshift'><input type='button' value='Check for Updates' onclick='openBox(\"/plugins/dynamix.plugin.manager/scripts/plugin&arg1=checkos\",\"Plugin Update Check\",490,430,true)'></span>");
<?endif;?>
});
</script>
<table class='tablesorter plugins shift' id='os_table'>
<thead><tr><th></th><th>System</th><th>Author</th><th>Version</th><th>Status</th><th>Release</th></tr></thead>
<thead><tr><th></th><th>Component</th><th>Author</th><th>Version</th><th>Status</th><th>Branch</th></tr></thead>
<tbody id="os_list"><?=$empty?></tbody>
</table>
@@ -16,8 +16,9 @@ require_once "$docroot/webGui/include/Markdown.php";
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
$current = parse_ini_file('/etc/unraid-version');
$release = $_GET['release'] ?? false;
$branch = $_GET['branch'] ?? false;
$system = $_GET['system'] ?? false;
$audit = $_GET['audit'] ?? false;
$empty = true;
$builtin = ['unRAIDServer','dynamix'];
$https = ['stable' => 'https://raw.github.com/limetech/\&name;/master/\&name;.plg',
@@ -32,20 +33,20 @@ foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
$custom = in_array($name,$builtin);
//switch between system and custom plugins
if (($system && !$custom) || (!$system && $custom)) continue;
//forced plugin check
$checked = check_plugin("$name.plg");
//forced plugin check?
$checked = ($audit || $branch) ? check_plugin("$name.plg") : true;
//OS update?
$os = $system && $name==$builtin[0];
$toggle = false;
//toggle stable/next release?
if ($os && $release) {
if ($os && $branch) {
$toggle = plugin('version',$plugin_file);
$cat = strpos($toggle,'rc')!==false ? 'stable' : 'next';
$tmp_plg = "$name-.plg";
$tmp_file = "/var/tmp/$name.plg";
copy($plugin_file,$tmp_file);
exec("sed -ri 's|^(<!ENTITY category).*|\\1 \"{$cat}\">|' $tmp_file");
exec("sed -ri 's|^(<!ENTITY pluginURL).*|\\1 \"{$https[$release]}\">|' $tmp_file");
exec("sed -ri 's|^(<!ENTITY pluginURL).*|\\1 \"{$https[$branch]}\">|' $tmp_file");
symlink($tmp_file,"/var/log/plugins/$tmp_plg");
if (check_plugin($tmp_plg)) {
copy("/tmp/plugins/$tmp_plg",$tmp_file);
@@ -75,7 +76,7 @@ foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
$changes_file = $plugin_file;
$URL = plugin('pluginURL',$plugin_file);
if ($URL !== false) {
$filename = "/tmp/plugins/".(($os && $release) ? $tmp_plg : basename($URL));
$filename = "/tmp/plugins/".(($os && $branch) ? $tmp_plg : basename($URL));
if ($checked && file_exists($filename)) {
if ($toggle && $toggle != $version) {
$status = make_link('install',$plugin_file,'forced');
@@ -88,10 +89,10 @@ foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
$status = make_link("update",basename($plugin_file));
$changes_file = $filename;
} else {
$status = "up-to-date";
$status = filemtime($filename) >= filemtime($plugin_file) ? 'up-to-date' : 'need check';
}
} else {
$status = "up-to-date";
$status = filemtime($filename) >= filemtime($plugin_file) ? 'up-to-date' : 'need check';
}
}
}
@@ -367,12 +367,14 @@ if ($argc < 2) {
exit(1);
}
$method = $argv[1];
$builtin = ['unRAIDServer','dynamix'];
// plugin checkall
// check all installed plugins
//
if ($method == "checkall") {
foreach (glob("/var/log/plugins/*", GLOB_NOSORT) as $link) {
if (in_array(basename($link,'.plg'),$builtin)) continue;
// only consider symlinks
$installed_plugin_file = @readlink($link);
if ($installed_plugin_file === false) continue;
@@ -384,6 +386,19 @@ if ($method == "checkall") {
exit(0);
}
if ($method == "checkos") {
foreach ($builtin as $link) {
// only consider symlinks
$installed_plugin_file = @readlink("/var/log/plugins/$link.plg");
if ($installed_plugin_file === false) continue;
if (plugin("pluginURL", $installed_plugin_file, $error) === false) continue;
$plugin = basename($installed_plugin_file);
echo "plugin: checking $plugin ...\n";
exec(realpath($argv[0]) . " check $plugin", $output, $retval);
}
exit(0);
}
if ($argc < 3) {
echo $usage;
exit(1);