Initiated update-mechanic, minor fixes
This commit is contained in:
8
check_update.php
Normal file
8
check_update.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$repoPath = '/usr/thos';
|
||||
$updateCount = trim(shell_exec("git -C $repoPath fetch origin && git -C $repoPath rev-list HEAD...origin/main --count"));
|
||||
|
||||
echo json_encode([
|
||||
'updates' => (int)$updateCount,
|
||||
'upToDate' => $updateCount === '0',
|
||||
]);
|
34
index.php
34
index.php
@ -1,10 +1,15 @@
|
||||
<img?php $statePath='/home/surillya/.thos_state.json' ; $state=file_exists($statePath) ?
|
||||
json_decode(file_get_contents($statePath), true) : null; if (!file_exists($statePath)) { header('Location: oobe.php');
|
||||
exit(); } ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<?php
|
||||
require_once('state.php');
|
||||
$state = thos_load_state();
|
||||
if (!$state || !isset($state['localData']) || !json_decode($state['localData'], true)['thos_done']) {
|
||||
header('Location: oobe.php');
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>THOS</title>
|
||||
<style>
|
||||
@ -288,9 +293,9 @@
|
||||
}
|
||||
</style>
|
||||
<script src="tailwind.es"></script>
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body class="bg-black">
|
||||
<body class="bg-black">
|
||||
<div id="appWrapper" class="transition-all duration-300">
|
||||
<div id="bg-image" class="fixed inset-0 z-[-10] bg-cover bg-center transition-all duration-300"></div>
|
||||
<div id="app-bar" class="bg-[#1e1e1e] fixed top-0 left-0 w-52 h-screen p-2.5 z-50">
|
||||
@ -352,8 +357,7 @@
|
||||
<svg class="w-6 h-6 text-yellow-300 mx-auto" fill="none" stroke="currentColor" stroke-width="2"
|
||||
viewBox="0 0 24 24">
|
||||
<path d="M12 15a3 3 0 100-6 3 3 0 000 6z" />
|
||||
<path
|
||||
d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1
|
||||
<path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1
|
||||
1.51V21a2 2 0 01-2 2 2 2 0 01-2-2v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83 0 2 2 0
|
||||
010-2.83l.06-.06a1.65 1.65 0 00.33-1.82 1.65 1.65 0 00-1.51-1H3a2 2 0 01-2-2 2 2 0 012-2h.09A1.65 1.65 0 004.6 9a1.65
|
||||
1.65 0 00-.33-1.82l-.06-.06a2 2 0 010-2.83 2 2 0 012.83 0l.06.06a1.65 1.65 0 001.82.33H9a1.65 1.65 0 001-1.51V3a2 2 0
|
||||
@ -408,7 +412,7 @@
|
||||
|
||||
<script>
|
||||
window.THOS = {
|
||||
version: '6 Build-28'
|
||||
version: '6 Build-30'
|
||||
};
|
||||
|
||||
let timeoutSeconds = 180;
|
||||
@ -693,8 +697,8 @@
|
||||
<button class="max-btn" title="Maximize/Restore">🗖</button>
|
||||
<button class="close-btn" title="Close">×</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
</div>`
|
||||
;
|
||||
|
||||
if (!sandbox) {
|
||||
win.innerHTML += `<iframe src="${url}" class="window-content" allowtransparency="true"></iframe>`;
|
||||
@ -975,6 +979,6 @@
|
||||
|
||||
window.notify = notify;
|
||||
</script>
|
||||
</body>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
14
run_update.php
Normal file
14
run_update.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$mode = $_GET['mode'] ?? 'git'; // Future-proof!
|
||||
|
||||
if ($mode === 'git') {
|
||||
$output = shell_exec("git -C /usr/thos pull 2>&1");
|
||||
echo "✅ Git update applied:\n$output";
|
||||
} elseif ($mode === 'curl') {
|
||||
// Placeholder for future upgrade logic
|
||||
$output = shell_exec("curl -s https://your.url/thos-update.sh | sudo bash 2>&1");
|
||||
echo "🔧 Installer run:\n$output";
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo "❌ Unknown update mode";
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once('state.php');
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if ($input) {
|
||||
file_put_contents('/home/surillya/.thos_state.json', json_encode($input));
|
||||
}
|
||||
if ($input) thos_save_state($input);
|
||||
?>
|
||||
|
73
settings.php
73
settings.php
@ -85,6 +85,19 @@
|
||||
<option value="never">Never</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<label class="block text-sm text-gray-300 mb-2">System Update</label>
|
||||
<button id="update-btn" type="button" onclick="checkOrInstallUpdate()"
|
||||
class="w-full bg-gray-800 text-white border border-gray-700 hover:bg-gray-700 font-medium px-4 py-2 rounded-lg transition flex items-center justify-between">
|
||||
<span id="update-button-label">Check for Updates</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-indigo-400" fill="none"
|
||||
viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
</button>
|
||||
<p id="update-status" class="text-xs text-gray-400 mt-2 whitespace-pre-wrap"></p>
|
||||
</div>
|
||||
<!-- Will eventually actually add this, but requires stuff in .xinitrc and really don't want to do it rn -->
|
||||
<!-- <div>
|
||||
<label for="powerMode" class="block text-sm text-gray-300 mb-2">Power Mode</label>
|
||||
@ -176,6 +189,66 @@
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
let updatePending = false;
|
||||
let pendingUpdateCount = 0;
|
||||
|
||||
function checkOrInstallUpdate() {
|
||||
if (updatePending) {
|
||||
installUpdate(); // Confirmed
|
||||
return;
|
||||
}
|
||||
|
||||
const label = document.getElementById("update-button-label");
|
||||
const status = document.getElementById("update-status");
|
||||
const button = document.getElementById("update-btn");
|
||||
|
||||
label.textContent = "Checking...";
|
||||
status.textContent = "";
|
||||
|
||||
fetch("check_update.php")
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.upToDate) {
|
||||
label.textContent = "System is Up To Date";
|
||||
status.textContent = "✅ You're running the latest version of THOS.";
|
||||
} else {
|
||||
updatePending = true;
|
||||
pendingUpdateCount = data.updates;
|
||||
label.textContent = `⬇️ ${data.updates} update(s) available. Click to update.`;
|
||||
button.classList.replace("bg-gray-800", "bg-yellow-800");
|
||||
button.classList.replace("hover:bg-gray-700", "hover:bg-yellow-700");
|
||||
status.textContent = "Updates detected. Click again to confirm and install.";
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
label.textContent = "Check for Updates";
|
||||
status.textContent = "❌ Update check failed.";
|
||||
});
|
||||
}
|
||||
|
||||
function installUpdate() {
|
||||
const label = document.getElementById("update-button-label");
|
||||
const status = document.getElementById("update-status");
|
||||
const button = document.getElementById("update-btn");
|
||||
|
||||
label.textContent = "Installing...";
|
||||
status.textContent = "⏳ Applying updates, please wait...";
|
||||
|
||||
fetch("run_update.php")
|
||||
.then(res => res.text())
|
||||
.then(output => {
|
||||
label.textContent = "✅ Update Applied";
|
||||
status.textContent = "THOS is now up to date!\n\n" + output;
|
||||
button.classList.replace("bg-yellow-800", "bg-green-800");
|
||||
button.classList.replace("hover:bg-yellow-700", "hover:bg-green-700");
|
||||
updatePending = false;
|
||||
})
|
||||
.catch(() => {
|
||||
label.textContent = "❌ Update Failed";
|
||||
status.textContent = "Please try again or check your network.";
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
12
state.php
Normal file
12
state.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
define('THOS_STATE_FILE', '/home/surillya/.thos_state.json');
|
||||
|
||||
function thos_load_state() {
|
||||
if (!file_exists(THOS_STATE_FILE)) return null;
|
||||
return json_decode(file_get_contents(THOS_STATE_FILE), true);
|
||||
}
|
||||
|
||||
function thos_save_state($data) {
|
||||
file_put_contents(THOS_STATE_FILE, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user