Replace dashboard Python heredocs with jq + bash

The install dashboard shelled out to a full Python interpreter to read
four keys from the installer state JSON — including inside the render
loop, twice a second. jq is already on the ISO and does the same job
with plain bash arithmetic for the phase-weight interpolation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier HanssonandClaude Fable 5 committed 2026-07-15 17:52:47 -07:00
1 parent 8c1e143686
commit a5e605af4c
1 file changed
+64 -74
@@ -182,47 +182,56 @@ progress_bar() {
} }
install_progress() { install_progress() {
local phase finished phase_started elapsed span active pct
local start=1 end=99 expected=90
local -a state
[[ -f $STATE_FILE ]] || { printf '1'; return; } [[ -f $STATE_FILE ]] || { printf '1'; return; }
python - "$STATE_FILE" <<'PY' 2>/dev/null || printf '1'
import json, sys, time mapfile -t state < <(jq -r '
path = sys.argv[1] (.current_phase // "Starting installation"),
try: ((.finished_at // 0) | tonumber? // 0 | floor),
state = json.load(open(path)) ((.phase_started_at // .started_at // 0) | tonumber? // 0 | floor)
except Exception: ' "$STATE_FILE" 2>/dev/null)
print(1, end='') (( ${#state[@]} == 3 )) || { printf '1'; return; }
raise SystemExit phase="${state[0]}" finished="${state[1]}" phase_started="${state[2]}"
phase = state.get('current_phase') or 'Starting installation'
if state.get('finished_at') or phase == 'Installation complete': if (( finished > 0 )) || [[ $phase == "Installation complete" ]]; then
print(100, end='') printf '100'
raise SystemExit return
weights = [ fi
('Starting installation', 1, 2, 2),
('Preparing live environment', 2, 6, 5), # Phase weights: start%, end%, expected seconds in phase.
('Verifying protected mounts', 6, 8, 3), case "$phase" in
('Installing Arch + Omarchy', 8, 86, 95), "Starting installation") start=1 end=2 expected=2 ;;
('Installing base system', 8, 84, 85), "Preparing live environment") start=2 end=6 expected=5 ;;
('Configuring protected boot', 84, 86, 8), "Verifying protected mounts") start=6 end=8 expected=3 ;;
('Configuring hibernation', 86, 88, 5), "Installing Arch + Omarchy") start=8 end=86 expected=95 ;;
('Configuring system', 88, 93, 10), "Installing base system") start=8 end=84 expected=85 ;;
('Finalizing Limine boot', 93, 96, 8), "Configuring protected boot") start=84 end=86 expected=8 ;;
('Finalizing user', 96, 98, 10), "Configuring hibernation") start=86 end=88 expected=5 ;;
('Finalizing in chroot', 88, 98, 10), "Configuring system") start=88 end=93 expected=10 ;;
('Configuring login', 98, 99, 3), "Finalizing Limine boot") start=93 end=96 expected=8 ;;
('Configuring DNS resolver', 99, 100, 2), "Finalizing user") start=96 end=98 expected=10 ;;
('Validating protected boot setup', 99, 100, 5), "Finalizing in chroot") start=88 end=98 expected=10 ;;
('Validating boot setup', 99, 100, 5), "Configuring login") start=98 end=99 expected=3 ;;
] "Configuring DNS resolver") start=99 end=100 expected=2 ;;
start, end, expected = 1, 99, 90 "Validating protected boot setup") start=99 end=100 expected=5 ;;
for name, s, e, seconds in weights: "Validating boot setup") start=99 end=100 expected=5 ;;
if phase == name: esac
start, end, expected = s, e, seconds
break (( phase_started > 0 )) || phase_started=$EPOCHSECONDS
phase_started = state.get('phase_started_at') or state.get('started_at') or time.time() elapsed=$(( EPOCHSECONDS - phase_started ))
elapsed = max(0, time.time() - float(phase_started)) (( elapsed < 0 )) && elapsed=0
span = max(0, end - start) span=$(( end - start ))
active = min(max(span - 1, 0), int((elapsed / max(expected, 1)) * span)) (( span < 0 )) && span=0
print(min(100, start + active), end='') (( expected < 1 )) && expected=1
PY active=$(( elapsed * span / expected ))
(( active > span - 1 )) && active=$(( span - 1 ))
(( active < 0 )) && active=0
pct=$(( start + active ))
(( pct > 100 )) && pct=100
printf '%s' "$pct"
} }
current_whimsy() { current_whimsy() {
@@ -260,25 +269,16 @@ install_duration() {
local path line duration local path line duration
if [[ -f $STATE_FILE ]]; then if [[ -f $STATE_FILE ]]; then
duration="$(python - "$STATE_FILE" <<'PY' 2>/dev/null || true duration="$(jq -r '
import json, sys ((.started_at // 0) | tonumber? // 0) as $started
try: | ((.finished_at // 0) | tonumber? // 0) as $finished
state = json.load(open(sys.argv[1])) | if $started <= 0 or $finished <= 0 or $finished < $started then empty
started = float(state.get("started_at") or 0) else (($finished - $started) | round) as $secs
finished = float(state.get("finished_at") or 0) | if $secs >= 3600 then "\($secs / 3600 | floor)h \($secs % 3600 / 60 | floor)m \($secs % 60)s"
except Exception: else "\($secs / 60 | floor)m \($secs % 60)s"
raise SystemExit(0) end
if started <= 0 or finished <= 0 or finished < started: end
raise SystemExit(0) ' "$STATE_FILE" 2>/dev/null || true)"
seconds = int(round(finished - started))
hours, remainder = divmod(seconds, 3600)
minutes, seconds = divmod(remainder, 60)
if hours:
print(f"{hours}h {minutes}m {seconds}s", end="")
else:
print(f"{minutes}m {seconds}s", end="")
PY
)"
[[ -n $duration ]] && { printf '%s' "$duration"; return 0; } [[ -n $duration ]] && { printf '%s' "$duration"; return 0; }
fi fi
@@ -551,21 +551,11 @@ if (( status != 0 )); then
failure_status="$status" failure_status="$status"
failure_summary="" failure_summary=""
if [[ -f $STATE_FILE ]]; then if [[ -f $STATE_FILE ]]; then
failure_summary="$(python - "$STATE_FILE" <<'PY' 2>/dev/null || true failure_summary="$(jq -r '
import json, sys (.current_phase // empty | "last installer phase: \(.)"),
try: ((.phases // []) | map(select(.status == "failed")) | last // empty
state = json.load(open(sys.argv[1])) | "failed phase: \(.name): \(.error)")
except Exception: ' "$STATE_FILE" 2>/dev/null || true)"
raise SystemExit(0)
phase = state.get("current_phase")
if phase:
print(f"last installer phase: {phase}")
for item in reversed(state.get("phases", [])):
if item.get("status") == "failed":
print(f"failed phase: {item.get('name')}: {item.get('error')}")
break
PY
)"
if [[ -n $failure_summary ]]; then if [[ -n $failure_summary ]]; then
while IFS= read -r line; do while IFS= read -r line; do
[[ -n $line ]] && dashboard_log "$line" [[ -n $line ]] && dashboard_log "$line"