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',
|
||||||
|
]);
|
20
index.php
20
index.php
@ -1,6 +1,11 @@
|
|||||||
<img?php $statePath='/home/surillya/.thos_state.json' ; $state=file_exists($statePath) ?
|
<?php
|
||||||
json_decode(file_get_contents($statePath), true) : null; if (!file_exists($statePath)) { header('Location: oobe.php');
|
require_once('state.php');
|
||||||
exit(); } ?>
|
$state = thos_load_state();
|
||||||
|
if (!$state || !isset($state['localData']) || !json_decode($state['localData'], true)['thos_done']) {
|
||||||
|
header('Location: oobe.php');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
@ -352,8 +357,7 @@
|
|||||||
<svg class="w-6 h-6 text-yellow-300 mx-auto" fill="none" stroke="currentColor" stroke-width="2"
|
<svg class="w-6 h-6 text-yellow-300 mx-auto" fill="none" stroke="currentColor" stroke-width="2"
|
||||||
viewBox="0 0 24 24">
|
viewBox="0 0 24 24">
|
||||||
<path d="M12 15a3 3 0 100-6 3 3 0 000 6z" />
|
<path d="M12 15a3 3 0 100-6 3 3 0 000 6z" />
|
||||||
<path
|
<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
|
||||||
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
|
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
|
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
|
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>
|
<script>
|
||||||
window.THOS = {
|
window.THOS = {
|
||||||
version: '6 Build-28'
|
version: '6 Build-30'
|
||||||
};
|
};
|
||||||
|
|
||||||
let timeoutSeconds = 180;
|
let timeoutSeconds = 180;
|
||||||
@ -693,8 +697,8 @@
|
|||||||
<button class="max-btn" title="Maximize/Restore">🗖</button>
|
<button class="max-btn" title="Maximize/Restore">🗖</button>
|
||||||
<button class="close-btn" title="Close">×</button>
|
<button class="close-btn" title="Close">×</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>`
|
||||||
`;
|
;
|
||||||
|
|
||||||
if (!sandbox) {
|
if (!sandbox) {
|
||||||
win.innerHTML += `<iframe src="${url}" class="window-content" allowtransparency="true"></iframe>`;
|
win.innerHTML += `<iframe src="${url}" class="window-content" allowtransparency="true"></iframe>`;
|
||||||
|
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
|
<?php
|
||||||
|
require_once('state.php');
|
||||||
$input = json_decode(file_get_contents('php://input'), true);
|
$input = json_decode(file_get_contents('php://input'), true);
|
||||||
if ($input) {
|
if ($input) thos_save_state($input);
|
||||||
file_put_contents('/home/surillya/.thos_state.json', json_encode($input));
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
|
73
settings.php
73
settings.php
@ -85,6 +85,19 @@
|
|||||||
<option value="never">Never</option>
|
<option value="never">Never</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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 -->
|
<!-- Will eventually actually add this, but requires stuff in .xinitrc and really don't want to do it rn -->
|
||||||
<!-- <div>
|
<!-- <div>
|
||||||
<label for="powerMode" class="block text-sm text-gray-300 mb-2">Power Mode</label>
|
<label for="powerMode" class="block text-sm text-gray-300 mb-2">Power Mode</label>
|
||||||
@ -176,6 +189,66 @@
|
|||||||
location.reload();
|
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>
|
</script>
|
||||||
</body>
|
</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