installer: make dashboard own install flow
This commit is contained in:
6 files changed
+287
-352
No files matched your search
@@ -1,17 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# Render the live Omarchy install dashboard on tty1 while installer output is
|
||||
# captured to logs. This is presentation only: it must never read input or gate
|
||||
# install completion.
|
||||
# Foreground Omarchy ISO install UI supervisor.
|
||||
#
|
||||
# This process is the only owner of the visible install UI. It launches the
|
||||
# actual installer as a non-interactive child, sends child output to the support
|
||||
# log, renders progress while the child runs, then renders the final installed
|
||||
# time + reboot prompt itself. There is deliberately no background dashboard.
|
||||
set -euo pipefail
|
||||
|
||||
LOG_FILE="${1:-/var/log/omarchy-install.log}"
|
||||
STATE_FILE="${2:-/run/omarchy-install/state.json}"
|
||||
STATE_DIR="$(dirname "$STATE_FILE")"
|
||||
STOP_FILE="$STATE_DIR/dashboard.stop"
|
||||
PID_FILE="$STATE_DIR/dashboard.pid"
|
||||
LOGO_PATH="${OMARCHY_PATH:-/usr/share/omarchy}/logo.txt"
|
||||
TTY_PATH="${OMARCHY_DASHBOARD_TTY:-/dev/tty}"
|
||||
usage() {
|
||||
echo "Usage: $0 <log-file> <state-file> -- <installer command...>" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
(( $# >= 4 )) || usage
|
||||
LOG_FILE="$1"
|
||||
STATE_FILE="$2"
|
||||
shift 2
|
||||
[[ ${1:-} == "--" ]] || usage
|
||||
shift
|
||||
(( $# > 0 )) || usage
|
||||
INSTALL_CMD=("$@")
|
||||
|
||||
TTY_PATH="${OMARCHY_DASHBOARD_TTY:-/dev/tty}"
|
||||
LOGO_PATH="${OMARCHY_PATH:-/usr/share/omarchy}/logo.txt"
|
||||
CSI=$'\033['
|
||||
RESET="${CSI}0m"
|
||||
DIM="${CSI}2m"
|
||||
@@ -20,11 +31,12 @@ SHOW_CURSOR="${CSI}?25h"
|
||||
CLEAR="${CSI}2J${CSI}H"
|
||||
CLEAR_LINE="${CSI}2K"
|
||||
CLEAR_TO_END="${CSI}J"
|
||||
# Use the 16-color ANSI palette configured by .automated_script.sh. The Linux
|
||||
# VT does not reliably map 256-color indexes the same way terminal emulators do.
|
||||
GREEN="${CSI}32m"
|
||||
DARK="${CSI}90m"
|
||||
|
||||
child_pid=""
|
||||
child_pgid=""
|
||||
|
||||
whimsy=(
|
||||
"making Linux feel like home"
|
||||
"installing the good defaults"
|
||||
@@ -46,10 +58,37 @@ whimsy=(
|
||||
|
||||
cleanup() {
|
||||
printf '%s%s' "$RESET" "$SHOW_CURSOR" >"$TTY_PATH" 2>/dev/null || true
|
||||
rm -f "$PID_FILE" 2>/dev/null || true
|
||||
}
|
||||
|
||||
stop_child() {
|
||||
[[ -n ${child_pid:-} ]] || return 0
|
||||
if kill -0 "$child_pid" 2>/dev/null; then
|
||||
if [[ -n ${child_pgid:-} ]]; then
|
||||
kill -- -"$child_pgid" 2>/dev/null || true
|
||||
fi
|
||||
kill "$child_pid" 2>/dev/null || true
|
||||
for _ in {1..20}; do
|
||||
kill -0 "$child_pid" 2>/dev/null || break
|
||||
sleep 0.05
|
||||
done
|
||||
if kill -0 "$child_pid" 2>/dev/null; then
|
||||
[[ -n ${child_pgid:-} ]] && kill -9 -- -"$child_pgid" 2>/dev/null || true
|
||||
kill -9 "$child_pid" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
wait "$child_pid" 2>/dev/null || true
|
||||
}
|
||||
|
||||
interrupt() {
|
||||
local code="$1"
|
||||
stop_child
|
||||
cleanup
|
||||
exit "$code"
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
trap 'cleanup; exit 0' INT TERM
|
||||
trap 'interrupt 130' INT
|
||||
trap 'interrupt 143' TERM
|
||||
|
||||
term_size() { stty size 2>/dev/null <"$TTY_PATH" || printf '24 80\n'; }
|
||||
term_cols() { local size; size="$(term_size)"; printf '%s\n' "${size#* }"; }
|
||||
@@ -150,8 +189,6 @@ phase = state.get('current_phase') or 'Starting installation'
|
||||
if state.get('finished_at') or phase == 'Installation complete':
|
||||
print(100, end='')
|
||||
raise SystemExit
|
||||
# Internal weighting only. Keep estimates conservative but close to observed
|
||||
# ISO installs so the bar does not sit at 12% then jump to 90%.
|
||||
weights = [
|
||||
('Starting installation', 1, 2, 2),
|
||||
('Preparing live environment', 2, 6, 5),
|
||||
@@ -163,7 +200,6 @@ weights = [
|
||||
('Configuring login', 98, 99, 3),
|
||||
('Validating protected boot setup', 99, 100, 5),
|
||||
('Validating boot setup', 99, 100, 5),
|
||||
('Finishing', 99, 100, 3),
|
||||
]
|
||||
start, end, expected = 1, 99, 90
|
||||
for name, s, e, seconds in weights:
|
||||
@@ -178,22 +214,6 @@ print(min(100, start + active), end='')
|
||||
PY
|
||||
}
|
||||
|
||||
dashboard_should_stop() {
|
||||
[[ -f $STATE_FILE ]] || return 1
|
||||
python - "$STATE_FILE" <<'PY' 2>/dev/null
|
||||
import json, sys
|
||||
try:
|
||||
state = json.load(open(sys.argv[1]))
|
||||
except Exception:
|
||||
raise SystemExit(1)
|
||||
phase = state.get('current_phase')
|
||||
# The final installed-time/reboot prompt is rendered inside the Finishing
|
||||
# phase. Stop before drawing another dashboard frame so the prompt cannot be
|
||||
# covered while it waits for input.
|
||||
raise SystemExit(0 if state.get('finished_at') or phase in ('Finishing', 'Installation complete') else 1)
|
||||
PY
|
||||
}
|
||||
|
||||
current_whimsy() {
|
||||
local frame="$1" pct="$2"
|
||||
printf '%s' "${whimsy[$(( (pct / 8 + frame / 8) % ${#whimsy[@]} ))]}"
|
||||
@@ -204,11 +224,10 @@ render_static() {
|
||||
blank_line
|
||||
|
||||
if command -v tte >/dev/null 2>&1 && command -v timeout >/dev/null 2>&1 && [[ -f $LOGO_PATH ]]; then
|
||||
if timeout 8s tte -i "$LOGO_PATH" --canvas-width 0 --anchor-text c --frame-rate 920 laseretch 2>/dev/null; then
|
||||
if timeout 8s tte -i "$LOGO_PATH" --canvas-width 0 --anchor-text c --frame-rate 920 laseretch >"$TTY_PATH" 2>/dev/null; then
|
||||
blank_line
|
||||
return
|
||||
fi
|
||||
# If animation fails or times out, clear any partial frame before fallback.
|
||||
printf '%s' "$CLEAR"
|
||||
blank_line
|
||||
fi
|
||||
@@ -239,22 +258,92 @@ render_dynamic() {
|
||||
printf '%s' "$CLEAR_TO_END"
|
||||
}
|
||||
|
||||
if [[ ! -e $TTY_PATH ]]; then
|
||||
exit 0
|
||||
fi
|
||||
install_duration() {
|
||||
local path line duration
|
||||
for path in /mnt/var/log/omarchy-install.log "$LOG_FILE"; do
|
||||
[[ -f $path ]] || continue
|
||||
for prefix in Total Omarchy; do
|
||||
line="$(grep "^$prefix:" "$path" 2>/dev/null | tail -n 1 || true)"
|
||||
[[ -n $line ]] || continue
|
||||
duration="${line#*:}"
|
||||
duration="${duration#${duration%%[![:space:]]*}}"
|
||||
[[ -n $duration ]] && { printf '%s' "$duration"; return; }
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
mkdir -p "$STATE_DIR"
|
||||
echo "$$" >"$PID_FILE"
|
||||
render_finish() {
|
||||
local duration message cols
|
||||
cols="$(term_cols)"
|
||||
printf '%s%s' "$SHOW_CURSOR" "$CLEAR" >"$TTY_PATH"
|
||||
if command -v tte >/dev/null 2>&1 && command -v timeout >/dev/null 2>&1 && [[ -f $LOGO_PATH ]]; then
|
||||
timeout 8s tte -i "$LOGO_PATH" --canvas-width 0 --anchor-text c --frame-rate 920 laseretch >"$TTY_PATH" 2>/dev/null || true
|
||||
else
|
||||
render_logo >"$TTY_PATH"
|
||||
fi
|
||||
duration="$(install_duration)"
|
||||
message="Finished installing"
|
||||
[[ -n $duration ]] && message="Installed in $duration"
|
||||
{
|
||||
blank_line
|
||||
center "$message" "$cols"
|
||||
blank_line
|
||||
} >"$TTY_PATH"
|
||||
}
|
||||
|
||||
reboot_prompt() {
|
||||
local prompt_pad
|
||||
prompt_pad=$(( ( $(term_cols) - 18 ) / 2 ))
|
||||
(( prompt_pad < 0 )) && prompt_pad=0
|
||||
gum confirm \
|
||||
--padding "0 0 0 $prompt_pad" \
|
||||
--show-help=false \
|
||||
--default \
|
||||
--affirmative "Reboot Now" \
|
||||
--negative "" \
|
||||
"" <"$TTY_PATH" >"$TTY_PATH" 2>&1
|
||||
}
|
||||
|
||||
launch_child() {
|
||||
mkdir -p "$(dirname "$LOG_FILE")"
|
||||
# Child is non-interactive. All visible UI belongs to this supervisor.
|
||||
setsid "${INSTALL_CMD[@]}" </dev/null > >(sed -u 's/\x1b\[[0-9;]*[a-zA-Z]//g' >>"$LOG_FILE") 2>&1 &
|
||||
child_pid=$!
|
||||
child_pgid=$child_pid
|
||||
}
|
||||
|
||||
[[ -e $TTY_PATH ]] || exit 2
|
||||
printf '%s' "$HIDE_CURSOR" >"$TTY_PATH"
|
||||
render_static >"$TTY_PATH"
|
||||
launch_child
|
||||
|
||||
frame=0
|
||||
while true; do
|
||||
[[ -e $STOP_FILE ]] && break
|
||||
dashboard_should_stop && break
|
||||
while jobs -pr | grep -qx "$child_pid"; do
|
||||
render_dynamic "$frame" >"$TTY_PATH"
|
||||
[[ -e $STOP_FILE ]] && break
|
||||
dashboard_should_stop && break
|
||||
frame=$((frame + 1))
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
set +e
|
||||
wait "$child_pid"
|
||||
status=$?
|
||||
set -e
|
||||
child_pid=""
|
||||
child_pgid=""
|
||||
|
||||
if (( status != 0 )); then
|
||||
printf '%s%s' "$SHOW_CURSOR" "$CLEAR" >"$TTY_PATH"
|
||||
exit "$status"
|
||||
fi
|
||||
|
||||
render_finish
|
||||
if [[ ${OMARCHY_UI_AUTO_REBOOT:-} == "no" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if reboot_prompt; then
|
||||
printf '%s' "$CLEAR" >"$TTY_PATH"
|
||||
reboot 2>/dev/null || systemctl reboot 2>/dev/null || true
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -38,7 +38,6 @@ def build_phases(ctx: InstallContext):
|
||||
configure_login,
|
||||
validate_boot_full,
|
||||
validate_boot_protected,
|
||||
finish,
|
||||
)
|
||||
|
||||
if ctx.is_protected:
|
||||
@@ -50,7 +49,6 @@ def build_phases(ctx: InstallContext):
|
||||
("Finalizing in chroot", run_chroot_finalizer),
|
||||
("Configuring login", configure_login),
|
||||
("Validating protected boot setup", validate_boot_protected),
|
||||
("Finishing", finish),
|
||||
]
|
||||
|
||||
return [
|
||||
@@ -59,7 +57,6 @@ def build_phases(ctx: InstallContext):
|
||||
("Finalizing in chroot", run_chroot_finalizer),
|
||||
("Configuring login", configure_login),
|
||||
("Validating boot setup", validate_boot_full),
|
||||
("Finishing", finish),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ Phase ordering (full-disk):
|
||||
run_chroot_finalizer → bind mounts + sudoers shim + arch-chroot finalize.sh
|
||||
configure_login → sddm autologin for unencrypted installs
|
||||
validate_boot_full → assert UKI / limine.conf / kernel cmdline are sane
|
||||
finish → reboot prompt
|
||||
|
||||
Phase ordering (protected / pre-mounted):
|
||||
|
||||
@@ -26,13 +25,11 @@ Phase ordering (protected / pre-mounted):
|
||||
run_chroot_finalizer → same
|
||||
configure_login → same
|
||||
validate_boot_protected → implemented in Step 8
|
||||
finish → same
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -42,7 +39,7 @@ from pathlib import Path
|
||||
|
||||
from . import archinstall_adapter as arch
|
||||
from .context import InstallContext
|
||||
from .ui import confirm, info
|
||||
from .ui import info
|
||||
|
||||
|
||||
# Packages installed BEFORE useradd. omarchy-settings and omarchy-nvim
|
||||
@@ -1045,215 +1042,3 @@ def cleanup_protected_state(ctx: InstallContext) -> None:
|
||||
check=False,
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# finish: prompt for reboot. Bind mounts are unwound in main()'s finally.
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
def _dashboard_stopped(pid: int) -> bool:
|
||||
stat = Path(f"/proc/{pid}/stat")
|
||||
if not stat.exists():
|
||||
return True
|
||||
try:
|
||||
# /proc/<pid>/stat field 3 is process state. A zombie cannot write to
|
||||
# the tty anymore; the shell parent will reap it when control returns.
|
||||
return stat.read_text().split()[2] == "Z"
|
||||
except OSError:
|
||||
return True
|
||||
|
||||
|
||||
def _pid_is_dashboard(pid: int) -> bool:
|
||||
try:
|
||||
cmdline = Path(f"/proc/{pid}/cmdline").read_bytes().replace(b"\0", b" ")
|
||||
except OSError:
|
||||
return False
|
||||
return b"omarchy-install-dashboard" in cmdline
|
||||
|
||||
|
||||
def _add_dashboard_pid(pids: list[int], pid_text: str | None) -> None:
|
||||
if not pid_text:
|
||||
return
|
||||
try:
|
||||
pid = int(pid_text.strip())
|
||||
except ValueError:
|
||||
return
|
||||
if pid not in pids and _pid_is_dashboard(pid):
|
||||
pids.append(pid)
|
||||
|
||||
|
||||
def _dashboard_pids() -> list[int]:
|
||||
pids: list[int] = []
|
||||
|
||||
_add_dashboard_pid(pids, os.environ.get("OMARCHY_INSTALL_DASHBOARD_PID"))
|
||||
|
||||
pid_file = Path("/run/omarchy-install/dashboard.pid")
|
||||
try:
|
||||
_add_dashboard_pid(pids, pid_file.read_text())
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# Last-resort /proc scan. Do not rely on pgrep being present in the ISO.
|
||||
for proc_dir in Path("/proc").iterdir():
|
||||
if not proc_dir.name.isdigit():
|
||||
continue
|
||||
_add_dashboard_pid(pids, proc_dir.name)
|
||||
|
||||
return pids
|
||||
|
||||
|
||||
def _signal_dashboard(pid: int, signal_number: int) -> None:
|
||||
# Dashboard is launched with setsid, making its PID the process group ID.
|
||||
# Signal the group first so child sleep/tte processes cannot keep drawing.
|
||||
try:
|
||||
os.killpg(pid, signal_number)
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
os.kill(pid, signal_number)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def _stop_install_dashboard() -> None:
|
||||
stop_file = Path("/run/omarchy-install/dashboard.stop")
|
||||
try:
|
||||
stop_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
stop_file.touch()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
pids = _dashboard_pids()
|
||||
for signal_number in (15, 9):
|
||||
for pid in pids:
|
||||
if _dashboard_stopped(pid):
|
||||
continue
|
||||
if not _pid_is_dashboard(pid):
|
||||
continue
|
||||
_signal_dashboard(pid, signal_number)
|
||||
deadline = time.time() + (1.0 if signal_number == 15 else 0.5)
|
||||
while time.time() < deadline:
|
||||
if all(_dashboard_stopped(pid) for pid in pids):
|
||||
break
|
||||
time.sleep(0.05)
|
||||
if all(_dashboard_stopped(pid) for pid in pids):
|
||||
break
|
||||
|
||||
try:
|
||||
with open("/dev/tty", "w", encoding="utf-8") as tty:
|
||||
tty.write("\033[?25h\033[H\033[2J")
|
||||
tty.flush()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def _tty_size() -> tuple[int, int]:
|
||||
try:
|
||||
with open("/dev/tty", "rb") as tty:
|
||||
res = subprocess.run(
|
||||
["stty", "size"],
|
||||
stdin=tty,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
rows, cols = res.stdout.strip().split()
|
||||
return int(rows), int(cols)
|
||||
except Exception: # noqa: BLE001
|
||||
return 24, 80
|
||||
|
||||
|
||||
def _center_text(text: str, width: int) -> str:
|
||||
pad = max((width - len(text)) // 2, 0)
|
||||
return " " * pad + text
|
||||
|
||||
|
||||
def _install_duration(ctx: InstallContext) -> str | None:
|
||||
candidates = [
|
||||
ctx.target / "var" / "log" / "omarchy-install.log",
|
||||
Path("/var/log/omarchy-install.log"),
|
||||
]
|
||||
patterns = ("Total:", "Omarchy:")
|
||||
for path in candidates:
|
||||
if not path.exists():
|
||||
continue
|
||||
try:
|
||||
lines = path.read_text(errors="ignore").splitlines()
|
||||
except OSError:
|
||||
continue
|
||||
for prefix in patterns:
|
||||
for line in reversed(lines[-80:]):
|
||||
if line.startswith(prefix):
|
||||
duration = line.split(":", 1)[1].strip()
|
||||
if duration:
|
||||
return duration
|
||||
return None
|
||||
|
||||
|
||||
def _render_tte_logo(logo_path: Path) -> bool:
|
||||
if not logo_path.exists() or not shutil.which("tte"):
|
||||
return False
|
||||
try:
|
||||
with open("/dev/tty", "rb", buffering=0) as stdin, open("/dev/tty", "wb", buffering=0) as stdout:
|
||||
subprocess.run(
|
||||
[
|
||||
"tte",
|
||||
"-i", str(logo_path),
|
||||
"--canvas-width", "0",
|
||||
"--anchor-text", "c",
|
||||
"--frame-rate", "920",
|
||||
"laseretch",
|
||||
],
|
||||
stdin=stdin,
|
||||
stdout=stdout,
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=8,
|
||||
check=True,
|
||||
)
|
||||
return True
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return False
|
||||
|
||||
|
||||
def _render_static_finish_logo(tty, logo_path: Path, cols: int) -> None:
|
||||
green = "\033[32m"
|
||||
reset = "\033[0m"
|
||||
if logo_path.exists():
|
||||
logo_lines = logo_path.read_text(errors="ignore").splitlines()
|
||||
logo_width = max((len(line) for line in logo_lines), default=0)
|
||||
left = max((cols - logo_width) // 2, 0)
|
||||
for line in logo_lines:
|
||||
tty.write(" " * left + green + line + reset + "\n")
|
||||
else:
|
||||
tty.write(_center_text("Omarchy", cols) + "\n")
|
||||
|
||||
|
||||
def _render_finish_screen(ctx: InstallContext) -> None:
|
||||
_, cols = _tty_size()
|
||||
logo_path = Path("/usr/share/omarchy/logo.txt")
|
||||
try:
|
||||
with open("/dev/tty", "w", encoding="utf-8") as tty:
|
||||
tty.write("\033[?25h\033[H\033[2J\n")
|
||||
tty.flush()
|
||||
|
||||
if not _render_tte_logo(logo_path):
|
||||
with open("/dev/tty", "w", encoding="utf-8") as tty:
|
||||
tty.write("\033[?25h\033[H\033[2J\n")
|
||||
_render_static_finish_logo(tty, logo_path, cols)
|
||||
tty.flush()
|
||||
|
||||
with open("/dev/tty", "w", encoding="utf-8") as tty:
|
||||
tty.write("\n")
|
||||
duration = _install_duration(ctx)
|
||||
message = f"Installed in {duration}" if duration else "Finished installing"
|
||||
tty.write(_center_text(message, cols) + "\n\n")
|
||||
tty.flush()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def finish(ctx: InstallContext) -> None:
|
||||
_stop_install_dashboard()
|
||||
_render_finish_screen(ctx)
|
||||
if confirm("Reboot now?", default=True):
|
||||
os.system("reboot")
|
||||
@@ -16,12 +16,6 @@ def style(text: str, *, foreground: str | None = None, padding: str | None = Non
|
||||
subprocess.run(cmd, check=False)
|
||||
|
||||
|
||||
def confirm(prompt: str, *, default: bool = True) -> bool:
|
||||
cmd = ["gum", "confirm", "--default" if default else "--no-default", prompt]
|
||||
with open("/dev/tty", "rb") as stdin, open("/dev/tty", "wb") as stdout:
|
||||
return subprocess.run(cmd, stdin=stdin, stdout=stdout, stderr=stdout).returncode == 0
|
||||
|
||||
|
||||
def info(text: str) -> None:
|
||||
style(text, foreground="3", padding="1 0 0 4")
|
||||
|
||||
|
||||
Reference in new issue
Block a user