Fixing updates

This commit is contained in:
kirillius 2024-12-24 14:53:04 +03:00
parent 3e2437144c
commit 67a5c2e480
2 changed files with 35 additions and 6 deletions

View File

@ -7,10 +7,11 @@
</head> </head>
<body> <body>
<span id="loading">Loading...</span> <span id="loading">Loading...</span>
<div style="display: none" id="panel"> <div style="display: none" id="panel">
<div id="update-panel">Checking for updates...</div> <div id="update-panel">Checking for updates...</div>
<hr>
Selected networks: Selected networks:
<table id="net-table"> <table id="net-table">
<tr> <tr>
@ -93,7 +94,7 @@
self.prop("disabled", true); self.prop("disabled", true);
(async function () { (async function () {
try { try {
alert( await JSONRPC.__invoke("restart_quagga")); alert(await JSONRPC.__invoke("restart_quagga"));
} finally { } finally {
setTimeout(() => { setTimeout(() => {
self.prop("disabled", false); self.prop("disabled", false);
@ -103,8 +104,26 @@
})(); })();
} }
}); });
(async function(){ (async function () {
alert(await JSONRPC.__invoke("checkUpdates")); let state = (await JSONRPC.__invoke("checkUpdates"));
if (state === null) {
$("#update-panel").html(`<span style="color:red;">Error checking updates</span>`);
} else if (state === false) {
$("#update-panel").html(`<span style="color:black;">There is no updates</span>`);
} else if (state === true) {
$("#update-panel").html(`<span style="color:green;">Some updates are available</span>&nbsp;<button>Update</button>`);
$("#update-panel button").click(async function () {
$("#panel").hide();
$("#loading").show().text("Installing updates...");
try {
console.log(await JSONRPC.__invoke("installUpdates"));
} finally {
setTimeout(() => location.reload(), 10000);
}
});
}
})(); })();
}); });
</script> </script>

View File

@ -68,8 +68,18 @@ try {
public function checkUpdates() public function checkUpdates()
{ {
$this->checkAuth(); $this->checkAuth();
$data = shell_exec("git --no-pager fetch --dry-run --porcelain --verbose 2>&1"); $data = str_replace("=","",@shell_exec("git --no-pager fetch --dry-run --porcelain --verbose 2>&1 | grep refs"));
return $data; $parts = explode(" ", trim($data));
if(count($parts) < 3){
return null;
}
return $parts[0] != $parts[1];
}
public function installUpdates()
{
return @shell_exec("git --no-pager pull --verbose 2>&1");
} }