diff --git a/run_update.php b/run_update.php index e17f908..61185b3 100644 --- a/run_update.php +++ b/run_update.php @@ -2,24 +2,52 @@ $mode = $_GET['mode'] ?? 'git'; $repoPath = '/usr/thos'; +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"); +} + function forceGitUpdate($path) { $output = []; - $output[] = shell_exec("git -C $path fetch origin 2>&1"); - $output[] = shell_exec("git -C $path reset --hard origin/main 2>&1"); + shell_exec("git -C $path fetch origin 2>&1"); + $localBefore = getLatestLocalCommit($path); + $remote = getLatestRemoteCommit($path); + + if ($localBefore === $remote) { + return "Already up to date!"; + } + + $changelog = getCommitLogs($path, $localBefore, $remote); + + $output[] = "Soft-resetting local system files..."; + $output[] = shell_exec("git -C $path reset --hard origin/main 2>&1"); $output[] = shell_exec("git -C $path clean -fd 2>&1"); + $output[] = "\nChangelog:"; + $output[] = $changelog ?: "No new commits."; + return implode("\n", $output); } if ($mode === 'git') { - echo "🔄 Forcing full git reset and update...\n\n"; + header('Content-Type: text/html; charset=utf-8'); + echo "
"; + echo "Running THOS Git Update...\n\n"; echo forceGitUpdate($repoPath); + echo "\n"; } elseif ($mode === 'curl') { - echo "🔧 Running installer...\n\n"; - echo shell_exec("curl -s https://surillya.com/thos/thos.sh | sudo bash 2>&1"); + echo "Running installer...\n\n"; + echo shell_exec("sudo bash '$(curl -fsSL https://surillya.com/thos/thos.sh)'"); } else { http_response_code(400); - echo "❌ Unknown update mode"; + echo "Unknown update mode"; }