Cleaned up the update output
This commit is contained in:
@ -11,41 +11,35 @@ function getLatestRemoteCommit($path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCommitLogs($path, $from, $to) {
|
function getCommitLogs($path, $from, $to) {
|
||||||
return shell_exec("git -C $path log --pretty=format:'• %C(yellow)%h%Creset %s %Cgreen(%cr)%Creset' $from..$to");
|
return shell_exec("git -C $path log --pretty=format:'- %h %s (%cr)' $from..$to");
|
||||||
}
|
}
|
||||||
|
|
||||||
function forceGitUpdate($path) {
|
function forceGitUpdate($path) {
|
||||||
$output = [];
|
|
||||||
|
|
||||||
shell_exec("git -C $path fetch origin 2>&1");
|
shell_exec("git -C $path fetch origin 2>&1");
|
||||||
|
|
||||||
$localBefore = getLatestLocalCommit($path);
|
$localBefore = getLatestLocalCommit($path);
|
||||||
$remote = getLatestRemoteCommit($path);
|
$remote = getLatestRemoteCommit($path);
|
||||||
|
|
||||||
if ($localBefore === $remote) {
|
if ($localBefore === $remote) {
|
||||||
return "Already up to date!";
|
return "Already up to date.";
|
||||||
}
|
}
|
||||||
|
|
||||||
$changelog = getCommitLogs($path, $localBefore, $remote);
|
$changelog = getCommitLogs($path, $localBefore, $remote);
|
||||||
|
|
||||||
$output[] = "Soft-resetting local system files...";
|
shell_exec("git -C $path reset --hard origin/main 2>&1");
|
||||||
$output[] = shell_exec("git -C $path reset --hard origin/main 2>&1");
|
shell_exec("git -C $path clean -fd 2>&1");
|
||||||
$output[] = shell_exec("git -C $path clean -fd 2>&1");
|
|
||||||
|
|
||||||
$output[] = "\n<strong>Changelog:</strong>";
|
$output = "Update installed successfully, reload system to apply.\n\n";
|
||||||
$output[] = $changelog ?: "No new commits.";
|
$output .= "Changelog:\n";
|
||||||
|
$output .= $changelog ?: "- No new commits found.";
|
||||||
|
|
||||||
return implode("\n", $output);
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mode === 'git') {
|
if ($mode === 'git') {
|
||||||
header('Content-Type: text/html; charset=utf-8');
|
header('Content-Type: text/plain; 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";
|
|
||||||
echo forceGitUpdate($repoPath);
|
echo forceGitUpdate($repoPath);
|
||||||
echo "\n</pre>";
|
|
||||||
} elseif ($mode === 'curl') {
|
} elseif ($mode === 'curl') {
|
||||||
echo "Running installer...\n\n";
|
|
||||||
echo shell_exec("sudo bash '$(curl -fsSL https://surillya.com/thos/thos.sh)'");
|
echo shell_exec("sudo bash '$(curl -fsSL https://surillya.com/thos/thos.sh)'");
|
||||||
} else {
|
} else {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
|
Reference in New Issue
Block a user