2025-06-20 18:06:57 +02:00
|
|
|
<?php
|
2025-06-20 18:17:13 +02:00
|
|
|
$mode = $_GET['mode'] ?? 'git';
|
|
|
|
$repoPath = '/usr/thos';
|
|
|
|
|
2025-06-20 18:48:13 +02:00
|
|
|
function getLatestLocalCommit($path) {
|
|
|
|
return trim(shell_exec("git -C $path rev-parse HEAD"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLatestRemoteCommit($path) {
|
|
|
|
return trim(shell_exec("git -C $path rev-parse origin/main"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCommitLogs($path, $from, $to) {
|
|
|
|
return shell_exec("git -C $path log --pretty=format:'• %C(yellow)%h%Creset %s %Cgreen(%cr)%Creset' $from..$to");
|
|
|
|
}
|
|
|
|
|
2025-06-20 18:17:13 +02:00
|
|
|
function forceGitUpdate($path) {
|
|
|
|
$output = [];
|
|
|
|
|
2025-06-20 18:48:13 +02:00
|
|
|
shell_exec("git -C $path fetch origin 2>&1");
|
|
|
|
|
|
|
|
$localBefore = getLatestLocalCommit($path);
|
|
|
|
$remote = getLatestRemoteCommit($path);
|
|
|
|
|
|
|
|
if ($localBefore === $remote) {
|
|
|
|
return "Already up to date!";
|
|
|
|
}
|
2025-06-20 18:17:13 +02:00
|
|
|
|
2025-06-20 18:48:13 +02:00
|
|
|
$changelog = getCommitLogs($path, $localBefore, $remote);
|
|
|
|
|
|
|
|
$output[] = "Soft-resetting local system files...";
|
|
|
|
$output[] = shell_exec("git -C $path reset --hard origin/main 2>&1");
|
2025-06-20 18:17:13 +02:00
|
|
|
$output[] = shell_exec("git -C $path clean -fd 2>&1");
|
|
|
|
|
2025-06-20 18:48:13 +02:00
|
|
|
$output[] = "\n<strong>Changelog:</strong>";
|
|
|
|
$output[] = $changelog ?: "No new commits.";
|
|
|
|
|
2025-06-20 18:17:13 +02:00
|
|
|
return implode("\n", $output);
|
|
|
|
}
|
2025-06-20 18:06:57 +02:00
|
|
|
|
|
|
|
if ($mode === 'git') {
|
2025-06-20 18:48:13 +02:00
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
echo "<pre style='font-family: monospace; background-color: #0f172a; color: #e2e8f0; padding: 1rem; border-radius: 0.5rem'>";
|
|
|
|
echo "<strong>Running THOS Git Update...</strong>\n\n";
|
2025-06-20 18:17:13 +02:00
|
|
|
echo forceGitUpdate($repoPath);
|
2025-06-20 18:48:13 +02:00
|
|
|
echo "\n</pre>";
|
2025-06-20 18:06:57 +02:00
|
|
|
} elseif ($mode === 'curl') {
|
2025-06-20 18:48:13 +02:00
|
|
|
echo "Running installer...\n\n";
|
|
|
|
echo shell_exec("sudo bash '$(curl -fsSL https://surillya.com/thos/thos.sh)'");
|
2025-06-20 18:06:57 +02:00
|
|
|
} else {
|
|
|
|
http_response_code(400);
|
2025-06-20 18:48:13 +02:00
|
|
|
echo "Unknown update mode";
|
2025-06-20 18:06:57 +02:00
|
|
|
}
|