Replace installer preview Python with jq
This commit is contained in:
1 parent
a5e605af4c
commit
c2a58526f4
1 file changed
+40
-43
+40
-43
@@ -2,53 +2,50 @@
|
||||
# Preview the shipped Omarchy installer dashboard without building an ISO.
|
||||
set -euo pipefail
|
||||
|
||||
write_simulation_state() {
|
||||
local state_file="$1" started_at="$2" phase_started_at="$3" current_phase="$4"
|
||||
local finished_at="${5:-null}" temporary="${state_file}.tmp"
|
||||
|
||||
jq -n \
|
||||
--argjson started_at "$started_at" \
|
||||
--argjson phase_started_at "$phase_started_at" \
|
||||
--arg current_phase "$current_phase" \
|
||||
--argjson finished_at "$finished_at" \
|
||||
'{
|
||||
started_at: $started_at,
|
||||
phase_started_at: $phase_started_at,
|
||||
current_phase: $current_phase
|
||||
} + if $finished_at == null then {} else {finished_at: $finished_at} end' \
|
||||
>"$temporary"
|
||||
mv -f -- "$temporary" "$state_file"
|
||||
}
|
||||
|
||||
simulate_install() {
|
||||
local state_file="$1"
|
||||
local started_at="$EPOCHREALTIME"
|
||||
local phase phase_started_at finished_at duration i
|
||||
local -a phases=(
|
||||
"Starting installation" 0.5
|
||||
"Preparing live environment" 0.8
|
||||
"Installing Arch + Omarchy" 5.0
|
||||
"Configuring system" 1.2
|
||||
"Finalizing Limine boot" 1.0
|
||||
"Finalizing user" 1.0
|
||||
"Configuring login" 0.6
|
||||
"Validating boot setup" 0.8
|
||||
)
|
||||
|
||||
python - "$state_file" <<'PY'
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
for ((i = 0; i < ${#phases[@]}; i += 2)); do
|
||||
phase="${phases[i]}"
|
||||
duration="${phases[i + 1]}"
|
||||
phase_started_at="$EPOCHREALTIME"
|
||||
write_simulation_state "$state_file" "$started_at" "$phase_started_at" "$phase"
|
||||
sleep "$duration"
|
||||
done
|
||||
|
||||
state_file = sys.argv[1]
|
||||
started_at = time.time()
|
||||
phases = [
|
||||
("Starting installation", 0.5),
|
||||
("Preparing live environment", 0.8),
|
||||
("Installing Arch + Omarchy", 5.0),
|
||||
("Configuring system", 1.2),
|
||||
("Finalizing Limine boot", 1.0),
|
||||
("Finalizing user", 1.0),
|
||||
("Configuring login", 0.6),
|
||||
("Validating boot setup", 0.8),
|
||||
]
|
||||
|
||||
|
||||
def write_state(current_phase, phase_started_at, finished_at=None):
|
||||
state = {
|
||||
"started_at": started_at,
|
||||
"phase_started_at": phase_started_at,
|
||||
"current_phase": current_phase,
|
||||
}
|
||||
if finished_at is not None:
|
||||
state["finished_at"] = finished_at
|
||||
|
||||
temporary = f"{state_file}.tmp"
|
||||
with open(temporary, "w") as output:
|
||||
json.dump(state, output)
|
||||
os.replace(temporary, state_file)
|
||||
|
||||
|
||||
for phase, duration in phases:
|
||||
phase_started_at = time.time()
|
||||
write_state(phase, phase_started_at)
|
||||
time.sleep(duration)
|
||||
|
||||
finished_at = time.time()
|
||||
write_state("Installation complete", finished_at, finished_at)
|
||||
time.sleep(0.3)
|
||||
PY
|
||||
finished_at="$EPOCHREALTIME"
|
||||
write_simulation_state "$state_file" "$started_at" "$finished_at" "Installation complete" "$finished_at"
|
||||
sleep 0.3
|
||||
}
|
||||
|
||||
if [[ ${1:-} == "--simulate-install" ]]; then
|
||||
|
||||
Reference in new issue
Block a user