Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

1.5 KB
Raw Blame
import type { UpdateStatus } from "@/lib/host/self-update";

export async function readStatus(check: boolean): Promise<UpdateStatus> {
  const res = await fetch("/api/v1/sys/update", {
    ...(check ? { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ action: "check" }) } : {}),
    cache: "no-store",
    signal: AbortSignal.timeout(55_000),
  });
  if (!res.ok) throw new Error(res.status === 401 || res.status === 403
    ? "Sign in as an Owner to check software updates."
    : `Could not read update status (HTTP ${res.status}). Try again.`);
  return (await res.json()) as UpdateStatus;
}

export function hasAvailableUpdate(status: Pick<UpdateStatus, "behind" | "pendingBuild" | "remoteChecked">): boolean {
  return status.pendingBuild === true || (status.remoteChecked === true && status.behind > 0);
}

/** Which host-side remedy the refusal text points at, or `null` when the operator
 *  cannot fix it from a shell either (no git checkout, no service unit). */
export function updateRefusalRemedy(reason: string | null | undefined): "branch" | "dirty" | null {
  const text = reason ?? "";
  if (text.includes("on main")) return "branch";
  if (text.includes("uncommitted changes")) return "dirty";
  return null;
}

export const REFUSAL_COMMANDS: Record<"branch" | "dirty", string> = {
  branch: "cd /path/to/mso\ngit checkout main\ngit pull --ff-only origin main\nmso update --rebuild",
  dirty: "cd /path/to/mso\ngit status\ngit stash   # or commit\ngit pull --ff-only origin main\nmso update --rebuild",
};