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>
<body>
<span id="loading">Loading...</span>
<div style="display: none" id="panel">
<div id="update-panel">Checking for updates...</div>
<hr>
Selected networks:
<table id="net-table">
<tr>
@ -104,7 +105,25 @@
}
});
(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>

View File

@ -68,8 +68,18 @@ try {
public function checkUpdates()
{
$this->checkAuth();
$data = shell_exec("git --no-pager fetch --dry-run --porcelain --verbose 2>&1");
return $data;
$data = str_replace("=","",@shell_exec("git --no-pager fetch --dry-run --porcelain --verbose 2>&1 | grep refs"));
$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");
}