-
-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathsetup
More file actions
executable file
·2777 lines (2445 loc) · 107 KB
/
Copy pathsetup
File metadata and controls
executable file
·2777 lines (2445 loc) · 107 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# iNiR setup - installer and maintenance entrypoint
# Commands: install, update, status, migrate, doctor, rollback, my-changes, uninstall (or TUI if no args)
resolve_bootstrap_repo_root() {
local script_dir="$1"
if [[ -d "${script_dir}/.git" && -f "${script_dir}/setup" && -f "${script_dir}/shell.qml" ]]; then
printf '%s' "$script_dir"
return
fi
local xdg_config_home="${XDG_CONFIG_HOME:-$HOME/.config}"
local config_new="${xdg_config_home}/inir"
local config_legacy="${xdg_config_home}/illogical-impulse"
local config_dir=""
if [[ -L "$config_legacy" && -d "$config_new" ]]; then
config_dir="$config_new"
elif [[ -d "$config_legacy" ]]; then
config_dir="$config_legacy"
elif [[ -d "$config_new" ]]; then
config_dir="$config_new"
else
config_dir="$config_new"
fi
local version_file="${config_dir}/version.json"
local stored_repo=""
if [[ -f "$version_file" ]]; then
if command -v jq >/dev/null 2>&1; then
stored_repo=$(jq -r '.repoPath // .repo_path // empty' "$version_file" 2>/dev/null || true)
else
stored_repo=$(sed -n 's/.*"repoPath"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$version_file" | head -1)
[[ -n "$stored_repo" ]] || stored_repo=$(sed -n 's/.*"repo_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$version_file" | head -1)
fi
fi
stored_repo="${stored_repo/#\~/$HOME}"
if [[ -n "$stored_repo" && -d "${stored_repo}/.git" && -f "${stored_repo}/setup" && -f "${stored_repo}/shell.qml" ]]; then
printf '%s' "$stored_repo"
return
fi
printf '%s' "$script_dir"
}
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(resolve_bootstrap_repo_root "$SCRIPT_DIR")"
if [[ ! -d "$REPO_ROOT" || ! -f "$REPO_ROOT/shell.qml" ]]; then
echo "Error: Could not find iNiR repository (resolved to: ${REPO_ROOT:-<empty>})" >&2
echo "Run this script from the iNiR repo directory, or fix ~/.config/inir/version.json" >&2
exit 1
fi
cd "$REPO_ROOT"
# Handle Ctrl+C gracefully
cleanup() {
type _tui_kill_spinner &>/dev/null && _tui_kill_spinner 2>/dev/null || true
echo ""
echo -e "\033[33mCancelled.\033[0m"
rm -rf /tmp/buildyay /tmp/buildparu 2>/dev/null
exit 130
}
###############################################################################
# Migrate
###############################################################################
run_migrate() {
echo ""
tui_title "iNiR Migrations"
echo ""
sync_launcher_from_repo
# Always apply REQUIRED migrations first
run_migrations_auto
local pending=$(count_pending_migrations 2>/dev/null || echo "0")
if [[ "$pending" -gt 0 ]]; then
tui_warn "$pending pending migration(s)"
run_migrations_interactive
else
tui_success "No pending migrations"
fi
}
trap cleanup INT
trap 'type _tui_kill_spinner &>/dev/null && _tui_kill_spinner 2>/dev/null || true; rm -rf /tmp/buildyay /tmp/buildparu 2>/dev/null' EXIT TERM
# Load core libraries
source ./sdata/lib/environment-variables.sh
source ./sdata/lib/functions.sh
source ./sdata/lib/tui.sh
source ./sdata/lib/package-installers.sh
source ./sdata/lib/dist-determine.sh
source ./sdata/lib/conflicts.sh
source ./sdata/lib/versioning.sh
source ./sdata/lib/migrations.sh
source ./sdata/lib/robust-update.sh
source ./sdata/lib/extras.sh
source ./sdata/lib/doctor.sh
source ./sdata/lib/snapshots.sh
source ./sdata/lib/uninstall.sh
source ./sdata/lib/user-modifications.sh
prevent_sudo_or_root
# Defaults
ask=true
quiet=false
# Auto-detect non-interactive context (no terminal on stdin).
# Forces non-interactive mode when launched from QML Process, cron, systemd, etc.
# This is defense-in-depth alongside the -y flag.
if ! [ -t 0 ]; then
ask=false
quiet=true
fi
# DISABLED: webapps — requires quickshell-webengine rebuild, re-enable when ready
# _build_install_qs_webengine() {
# local build_script="${REPO_ROOT}/scripts/quickshell-webengine/build-quickshell-webengine.sh"
# local pkgbuild_dir="${REPO_ROOT}/scripts/quickshell-webengine"
#
# if pacman -Q quickshell &>/dev/null 2>&1 && ! pacman -Q quickshell-webengine-git &>/dev/null 2>&1; then
# tui_info "Removing stock quickshell (will be replaced by webengine build)..."
# pkg_sudo pacman -Rdd --noconfirm quickshell 2>/dev/null || true
# fi
#
# if command -v makepkg >/dev/null 2>&1 && [[ -f "${pkgbuild_dir}/PKGBUILD" ]]; then
# tui_info "Building with PKGBUILD (Arch)..."
# (cd "$pkgbuild_dir" && makepkg -sif --noconfirm) && tui_success "quickshell-webengine installed!" || tui_warn "Build failed — see errors above"
# elif [[ -f "$build_script" ]]; then
# tui_info "Building with generic script..."
# bash "$build_script" --install && tui_success "quickshell-webengine installed!" || tui_warn "Build failed — see errors above"
# else
# tui_warn "No build method available"
# fi
# }
# Check privilege escalation availability
_check_privilege_prereqs() {
# Load the package installers to get access to privilege detection
source ./sdata/lib/package-installers.sh 2>/dev/null
local can_escalate=false
local method=""
# Check each method
if command -v sudo &>/dev/null && sudo -n true 2>/dev/null; then
can_escalate=true
method="sudo"
elif command -v pkexec &>/dev/null && ( [[ -n "${DBUS_SESSION_BUS_ADDRESS}" ]] || [[ -n "${DISPLAY}" ]] || [[ -n "${WAYLAND_DISPLAY}" ]] ); then
can_escalate=true
method="pkexec"
elif command -v su &>/dev/null && [[ -z "${DISPLAY}" ]] && [[ -z "${WAYLAND_DISPLAY}" ]]; then
can_escalate=true
method="su"
fi
if ! $can_escalate; then
echo ""
tui_warn "No privilege escalation method detected!"
echo ""
echo "This may cause installation to fail if sudo credentials are not cached."
echo ""
echo "Detected environment:"
[[ -n "${DISPLAY}" ]] && echo " - DISPLAY: ${DISPLAY}" || echo " - DISPLAY: (not set)"
[[ -n "${WAYLAND_DISPLAY}" ]] && echo " - WAYLAND: ${WAYLAND_DISPLAY}" || echo " - WAYLAND: (not set)"
[[ -n "${DBUS_SESSION_BUS_ADDRESS}" ]] && echo " - D-Bus: available" || echo " - D-Bus: (not set)"
echo " - sudo: $(command -v sudo &>/dev/null && echo 'available' || echo 'not found')"
echo " - pkexec: $(command -v pkexec &>/dev/null && echo 'available' || echo 'not found')"
echo " - su: $(command -v su &>/dev/null && echo 'available' || echo 'not found')"
echo ""
# Only warn in non-interactive mode, otherwise let user decide
if [[ "$1" == "install" ]] && [[ "$ask" == "false" ]]; then
tui_warn "Running in non-interactive mode - may fail. Consider:"
echo " 1. Running interactively: ./setup install"
echo " 2. Configure sudo first: sudo visudo"
echo " 3. Or use a graphical terminal with polkit agent"
echo ""
fi
fi
}
sync_launcher_from_repo() {
local launcher_target="${XDG_BIN_HOME}/inir"
if [[ -f "${REPO_ROOT}/scripts/inir" ]]; then
mkdir -p "$XDG_BIN_HOME"
cp -f "${REPO_ROOT}/scripts/inir" "$launcher_target"
chmod +x "$launcher_target"
ensure_launcher_path_in_shells "$XDG_BIN_HOME"
printf '%s\n' "$launcher_target"
fi
}
sync_user_inir_service_from_repo_if_present() {
local service_asset="${REPO_ROOT}/assets/systemd/inir.service"
local service_target_dir="${XDG_CONFIG_HOME}/systemd/user"
local service_target="${service_target_dir}/inir.service"
local launcher_target="${XDG_BIN_HOME}/inir"
local tmp_file
local changed=false
[[ -f "$service_asset" ]] || return 1
[[ -f "$service_target" ]] || return 1
mkdir -p "$service_target_dir"
mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}"
tmp_file="${XDG_CACHE_HOME:-$HOME/.cache}/inir.service.$$"
sed -e "s|^ExecStart=.*|ExecStart=${launcher_target//&/\\&} run --session|" \
-e "s|^ExecStopPost=-.*|ExecStopPost=-${launcher_target//&/\\&} cleanup-orphans|" \
"$service_asset" > "$tmp_file"
if [[ -L "$service_target" ]]; then
local service_dropin_dir="${service_target_dir}/inir.service.d"
local service_override="${service_dropin_dir}/override.conf"
local override_tmp="${XDG_CACHE_HOME:-$HOME/.cache}/inir.service.override.$$"
mkdir -p "$service_dropin_dir"
cat > "$override_tmp" <<EOF
# Managed locally: keep the repo unit template portable while running the
# developer launcher path from this machine.
[Service]
ExecStart=
ExecStart=${launcher_target} run --session
ExecStopPost=
ExecStopPost=-${launcher_target} cleanup-orphans
EOF
if ! cmp -s "$override_tmp" "$service_override"; then
changed=true
cp -f "$override_tmp" "$service_override"
fi
rm -f "$override_tmp"
elif ! cmp -s "$tmp_file" "$service_target"; then
changed=true
cp -f "$tmp_file" "$service_target"
fi
rm -f "$tmp_file"
if [[ "$changed" == true ]] && command -v systemctl >/dev/null 2>&1; then
systemctl --user daemon-reload >/dev/null 2>&1 || true
fi
if [[ "$changed" == true ]]; then
return 0
fi
return 1
}
ensure_user_inir_service_enabled() {
if ! command -v systemctl >/dev/null 2>&1; then
return 1
fi
local service_path="${XDG_CONFIG_HOME}/systemd/user/inir.service"
if [[ ! -f "$service_path" ]]; then
return 1
fi
# Detect the compositor service — never fall back to graphical-session.target
# because that target is active in KDE/GNOME/etc.
local target=""
if systemctl --user cat niri.service &>/dev/null; then
target="niri.service"
elif systemctl --user cat 'wayland-wm@Hyprland.service' &>/dev/null; then
target="wayland-wm@Hyprland.service"
fi
if [[ -z "$target" ]]; then
return 1 # no compositor found — don't enable
fi
local wants_dir="${XDG_CONFIG_HOME}/systemd/user/${target}.wants"
if [[ ! -e "$wants_dir/inir.service" ]]; then
mkdir -p "$wants_dir"
ln -sf "$service_path" "$wants_dir/inir.service"
fi
systemctl --user daemon-reload >/dev/null 2>&1 || true
return 0
}
###############################################################################
# Help
###############################################################################
setup_current_branch() {
git -C "$REPO_ROOT" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown"
}
setup_tracked_branch() {
get_update_tracking_branch 2>/dev/null || echo "main"
}
setup_service_link_summary() {
local links=()
local wants_dir
for wants_dir in "${XDG_CONFIG_HOME}/systemd/user"/*.wants; do
[[ -d "$wants_dir" ]] || continue
[[ -e "$wants_dir/inir.service" || -L "$wants_dir/inir.service" ]] || continue
links+=("$(basename "${wants_dir%.wants}")")
done
if [[ ${#links[@]} -eq 0 ]]; then
printf '%s' "not enabled"
return
fi
local IFS=', '
printf '%s' "${links[*]}"
}
setup_remote_state_summary() {
local installed_strategy
installed_strategy="$(get_installed_update_strategy)"
if [[ "$installed_strategy" == "package-manager" ]]; then
printf '%s' "package-managed"
return
fi
if [[ ! -d "${REPO_ROOT}/.git" ]] || ! declare -F check_remote_updates >/dev/null 2>&1; then
printf '%s' "unavailable"
return
fi
local rc=0
check_remote_updates || rc=$?
case "$rc" in
0) printf '%s' "update available" ;;
1) printf '%s' "up to date" ;;
2) printf '%s' "offline or missing remote" ;;
3) printf '%s' "ahead of remote" ;;
4) printf '%s' "diverged" ;;
*) printf '%s' "unknown" ;;
esac
}
setup_runtime_change_summary() {
local installed_mode runtime_dir manifest mod_files add_files mod_count=0 add_count=0
installed_mode="$(get_installed_install_mode)"
runtime_dir="$(get_runtime_shell_dir)"
case "$installed_mode" in
package-managed)
printf '%s' "externally managed"
return
;;
repo-link)
if [[ -d "${REPO_ROOT}/.git" ]]; then
local dirty_count
dirty_count="$(git -C "$REPO_ROOT" status --porcelain 2>/dev/null | wc -l | tr -d ' ')"
if [[ "${dirty_count:-0}" -eq 0 ]]; then
printf '%s' "clean"
else
printf '%s' "${dirty_count} local repo change(s)"
fi
return
fi
;;
repo-copy)
[[ -n "$runtime_dir" && -d "$runtime_dir" ]] || { printf '%s' "runtime missing"; return; }
manifest="$(find_runtime_manifest_file "$runtime_dir" 2>/dev/null || true)"
if [[ -n "$manifest" ]] && manifest_has_checksums "$manifest"; then
mod_files="$(detect_user_modifications "$runtime_dir" "$manifest")"
add_files="$(detect_user_additions "$runtime_dir" "$manifest")"
else
mod_files="$(detect_user_modifications_by_source_comparison "$runtime_dir" "$REPO_ROOT")"
add_files=""
fi
[[ -n "$mod_files" ]] && mod_count="$(printf '%s\n' "$mod_files" | grep -c . || true)"
[[ -n "$add_files" ]] && add_count="$(printf '%s\n' "$add_files" | grep -c . || true)"
if [[ "$mod_count" -eq 0 && "$add_count" -eq 0 ]]; then
printf '%s' "clean"
else
printf '%s' "${mod_count} modified, ${add_count} added"
fi
return
;;
esac
printf '%s' "unknown"
}
setup_preserved_mods_summary() {
if [[ ! -d "$USER_MODS_DIR" ]]; then
printf '%s' "0 backups"
return
fi
local count
count="$(find "$USER_MODS_DIR" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | wc -l | tr -d ' ')"
printf '%s' "${count:-0} backups"
}
show_setup_context_card() {
local title="${1:-Current Context}"
local installed_ver installed_commit installed_mode update_strategy runtime_dir current_branch tracked_branch launcher_path service_links remote_state runtime_state
installed_ver="$(get_installed_version)"
installed_commit="$(get_installed_commit)"
installed_mode="$(get_installed_install_mode)"
update_strategy="$(get_installed_update_strategy)"
runtime_dir="$(get_runtime_shell_dir)"
current_branch="$(setup_current_branch)"
tracked_branch="$(setup_tracked_branch)"
launcher_path="$(command -v inir 2>/dev/null || echo "${XDG_BIN_HOME}/inir")"
service_links="$(setup_service_link_summary)"
remote_state="$(setup_remote_state_summary)"
runtime_state="$(setup_runtime_change_summary)"
local pairs=(
"Installed:${installed_ver} (${installed_commit})"
"Mode:${installed_mode}"
"Updates:${update_strategy}"
"Remote:${remote_state}"
"Runtime State:${runtime_state}"
"Runtime:${runtime_dir:-"(missing)"}"
"Launcher:${launcher_path}"
"Service:${service_links}"
)
if [[ -d "${REPO_ROOT}/.git" ]]; then
pairs+=("Branch:${current_branch}")
[[ "$current_branch" == "HEAD" ]] && pairs+=("Tracks:origin/${tracked_branch}")
fi
tui_summary_card "$title" "${pairs[@]}"
}
show_help() {
echo ""
tui_hero_card "iNiR setup" \
"Install, sync, repair, inspect, and unfuck the shell without guessing which entrypoint owns what." \
"Use inir for daily runtime control. Use ./setup when you want the maintenance brain."
tui_key_value "Usage:" "./setup [command] [options]"
show_setup_context_card "Setup Overview"
tui_section_start "What setup owns"
tui_list_item "Install flow, runtime sync, migrations, snapshots, and service refresh"
tui_list_item "Repo-aware updates for repo-link and repo-copy installs"
tui_list_item "Health diagnostics and safe automatic fixes"
tui_section_end
tui_section_start "Everyday maintenance"
tui_list_item "(none) Interactive menu"
tui_list_item "install Full installation (deps + config + files)"
tui_list_item "update Check remote, pull, sync, restart shell"
tui_list_item "doctor Diagnose and fix common breakage"
tui_list_item "status Show install mode, update strategy, and health"
tui_list_item "logs View recent runtime logs"
tui_list_item "info System and shell details dashboard"
tui_section_end
tui_section_start "Recovery and history"
tui_list_item "migrate Review/apply config migrations"
tui_list_item "backup Create a manual snapshot"
tui_list_item "rollback Restore a previous snapshot"
tui_list_item "my-changes View or restore preserved user modifications"
tui_list_item "reinstall Re-run install pipeline for current setup"
tui_list_item "uninstall Remove iNiR from the system"
tui_section_end
tui_section_start "Customization"
tui_list_item "config View and edit shell settings"
tui_list_item "theme Change wallpaper and color scheme"
tui_list_item "extras Install optional extras (iNiR-Walls / SDDM / YAMIS icons)"
tui_section_end
tui_section_start "Options"
tui_list_item "-y, --yes Skip prompts (auto-yes)"
tui_list_item "-q, --quiet Minimal output"
tui_list_item "--local Sync local repo to install (skip git pull)"
tui_list_item "--simulate Walk the update flow visually without touching files (update only)"
tui_list_item "--set-default-shell Set Fish as default shell (uses chsh)"
tui_list_item "-h, --help Show this help"
tui_section_end
tui_section_start "Good defaults"
tui_list_item "./setup install Install iNiR once"
tui_list_item "./setup update Pull, sync, and restart"
tui_list_item "./setup doctor Diagnose weird runtime breakage"
tui_list_item "./setup status See what is installed and what is drifting"
tui_list_item "inir run Start the shell"
tui_list_item "inir logs Read what the shell is complaining about"
tui_section_end
echo ""
}
###############################################################################
# Version Status Display
###############################################################################
show_version_info() {
local installed_ver=$(get_installed_version)
local installed_commit=$(get_installed_commit)
local installed_mode=$(get_installed_install_mode)
local update_strategy=$(get_installed_update_strategy)
local installed_repo_path=$(get_installed_repo_path)
local repo_ver
local repo_commit
local runtime_dir
runtime_dir="$(get_runtime_shell_dir)"
local runtime_dir_display="${runtime_dir:-"(missing)"}"
if [[ -n "$installed_repo_path" && -f "${installed_repo_path}/VERSION" ]]; then
repo_ver="$(head -1 "${installed_repo_path}/VERSION" | tr -d '[:space:]')"
repo_commit="$(git -C "$installed_repo_path" rev-parse --short HEAD 2>/dev/null || echo "unknown")"
else
repo_ver=$(get_repo_version)
repo_commit=$(get_repo_commit)
fi
# Badge row for quick glance
echo ""
local badges_args=("Version" "$installed_ver" "accent")
badges_args+=("Mode" "$installed_mode" "info")
badges_args+=("Updates" "$update_strategy" "muted")
tui_badge_row "${badges_args[@]}"
echo ""
tui_status_line "Installed:" "$installed_ver ($installed_commit)" "ok"
tui_status_line "Runtime:" "$runtime_dir_display" ""
if [[ "$update_strategy" == "package-manager" ]]; then
local update_hint
update_hint=$(get_installed_package_update_hint)
[[ -n "$update_hint" ]] && tui_status_line "Command:" "$update_hint" ""
elif [[ "$installed_mode" != "repo-link" ]]; then
# For repo-copy: show what the local repo has vs what's deployed
tui_status_line "Available:" "$repo_ver ($repo_commit)" ""
fi
# Check for pending migrations
local pending=$(count_pending_migrations 2>/dev/null || echo "0")
if [[ "$pending" -gt 0 ]]; then
tui_status_line "Migrations:" "$pending pending" "warn"
fi
# Shell running status (resolve symlinks so qs -p matches the running instance)
if [[ -n "$runtime_dir" && -f "$runtime_dir/shell.qml" ]]; then
local running_output resolved_runtime_dir
resolved_runtime_dir="$(readlink -f "$runtime_dir" 2>/dev/null || printf '%s' "$runtime_dir")"
running_output="$(qs -p "$resolved_runtime_dir" list 2>/dev/null || true)"
if [[ -n "$running_output" && "$running_output" != No\ running\ instances* ]]; then
tui_status_line "Shell:" "running" "ok"
else
tui_status_line "Shell:" "stopped" "warn"
fi
fi
# Check for updates
if [[ "$update_strategy" != "package-manager" && "$installed_commit" != "$repo_commit" ]]; then
echo ""
tui_alert "info" "Update available" "Run './setup update' or 'inir update' to apply."
fi
}
###############################################################################
# TUI Menu
###############################################################################
tui_menu() {
clear
tui_banner
# Detect current state
local is_installed=false
[[ -f "${FIRSTRUN_FILE}" ]] && is_installed=true
if $is_installed; then
show_version_info
echo ""
tui_divider
fi
echo ""
# Menu options based on state with rich descriptions
local choice
if $is_installed; then
choice=$(tui_choose_rich "What would you like to do?" \
"${ICON_ARROW}|Update|Check for updates and apply them" \
"${ICON_CHECK}|Doctor|Diagnose and fix problems" \
"${ICON_DOT}|Config|View and edit shell settings" \
"${ICON_STAR}|Theme|Change wallpaper and color scheme" \
"${ICON_DOT}|Extras|Install optional extras (iNiR-Walls / SDDM / YAMIS icons)" \
"${ICON_INFO}|Info|System and shell details dashboard" \
"${ICON_DOT}|Logs|View recent runtime logs" \
"${ICON_DOT}|Migrate|Review and apply config migrations" \
"${ICON_DOT}|Backup|Create a manual snapshot" \
"${ICON_DOT}|Rollback|Restore a previous snapshot" \
"${ICON_DOT}|My Changes|View your preserved modifications" \
"${ICON_DOT}|Reinstall|Full reinstall from scratch" \
"${ICON_CROSS}|Uninstall|Remove iNiR from the system" \
"${ICON_CIRCLE}|Help|Show commands and usage" \
"${ICON_CIRCLE}|Exit|")
else
choice=$(tui_choose_rich "What would you like to do?" \
"${ICON_STAR}|Install|Full installation with dependencies" \
"${ICON_CIRCLE}|Help|Show commands and usage" \
"${ICON_CIRCLE}|Exit|")
fi
case "$choice" in
Install) run_install ;;
Reinstall) IS_UPDATE=true run_install ;;
Update) run_update ;;
Theme) run_theme ;;
Extras) run_extras ;;
Config) run_config ;;
Info) show_info; read -rp "Press Enter to continue..." ;;
Migrate) run_migrate ;;
Doctor) run_doctor ;;
Backup) run_backup ;;
Rollback) run_rollback ;;
"My Changes") run_my_changes ;;
Logs) run_logs ;;
Uninstall) run_uninstall ;;
Help) show_help; read -rp "Press Enter to continue..." ;;
Exit|"") return 1 ;;
*) return 1 ;;
esac
return 0
}
###############################################################################
# Status Command
###############################################################################
show_status_boot_timing() {
local cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/inir/last-boot.json"
if [[ ! -s "$cache_file" ]]; then
return 0
fi
# Phase timestamps (ms since epoch) — written by shell.qml at deferred phase end.
local component_ms config_ms entry_ms deferred_ms
component_ms=$(jq -r '.componentCompletedAt // 0' "$cache_file" 2>/dev/null)
config_ms=$(jq -r '.configReadyAt // 0' "$cache_file" 2>/dev/null)
entry_ms=$(jq -r '.shellEntryAt // 0' "$cache_file" 2>/dev/null)
deferred_ms=$(jq -r '.deferredReadyAt // 0' "$cache_file" 2>/dev/null)
[[ -z "$component_ms" || "$component_ms" == "0" ]] && return 0
# Process & service start — these often dominate perceived startup time.
local service_start_ms=0 qs_start_ms=0
if command -v systemctl >/dev/null 2>&1; then
local exec_start
exec_start=$(systemctl --user show inir.service -p ExecMainStartTimestamp --value 2>/dev/null)
if [[ -n "$exec_start" && "$exec_start" != "n/a" ]]; then
# systemctl prints "Tue 2026-05-19 11:38:37 -03"; date -d understands it.
service_start_ms=$(date -d "$exec_start" +%s%3N 2>/dev/null || echo 0)
fi
fi
# qs process start time (best-effort: read /proc/<pid>/stat starttime if running)
local qs_pid
qs_pid=$(pgrep -u "$USER" -fn '/usr/bin/qs.*shell\.qml|/usr/bin/qs -n -p' 2>/dev/null | head -1)
[[ -z "$qs_pid" ]] && qs_pid=$(pgrep -u "$USER" -fn 'qs -n' 2>/dev/null | head -1)
if [[ -n "$qs_pid" && -r "/proc/$qs_pid/stat" ]]; then
# field 22 = starttime in clock ticks since boot
local starttime_ticks btime hz
starttime_ticks=$(awk '{print $22}' "/proc/$qs_pid/stat")
btime=$(awk '/^btime / {print $2}' /proc/stat)
hz=$(getconf CLK_TCK)
if [[ -n "$starttime_ticks" && -n "$btime" && -n "$hz" && "$hz" -gt 0 ]]; then
qs_start_ms=$(( btime * 1000 + (starttime_ticks * 1000 / hz) ))
fi
fi
tui_title "Last Boot Timing"
# Format helper: render a delta in ms or s.
_fmt_ms() {
local ms=$1
if [[ "$ms" -lt 0 ]]; then printf -- '—'; return; fi
if [[ "$ms" -ge 1000 ]]; then
printf '%d.%02ds' "$((ms / 1000))" "$(((ms % 1000) / 10))"
else
printf '%dms' "$ms"
fi
}
# Build a single timeline anchored at the earliest known timestamp.
local origin=$service_start_ms
if [[ "$origin" == "0" || "$origin" -gt "$qs_start_ms" && "$qs_start_ms" -gt 0 ]]; then
origin=$qs_start_ms
fi
if [[ "$origin" == "0" || "$origin" -gt "$component_ms" ]]; then
origin=$component_ms
fi
tui_table_header "Phase" "Elapsed from start" 22 28
if [[ "$service_start_ms" -gt 0 ]]; then
tui_table_row "systemd ExecStart" "$(_fmt_ms 0) (T+0)" 22 28
fi
if [[ "$qs_start_ms" -gt 0 && "$service_start_ms" -gt 0 ]]; then
tui_table_row "qs process started" "$(_fmt_ms $((qs_start_ms - origin)))" 22 28
fi
tui_table_row "QML evaluated" "$(_fmt_ms $((component_ms - origin)))" 22 28
[[ "$config_ms" -gt 0 ]] && tui_table_row "Config ready" "$(_fmt_ms $((config_ms - origin)))" 22 28
[[ "$entry_ms" -gt 0 ]] && tui_table_row "Bar visible" "$(_fmt_ms $((entry_ms - origin)))" 22 28
[[ "$deferred_ms" -gt 0 ]] && tui_table_row "Services warm" "$(_fmt_ms $((deferred_ms - origin)))" 22 28
tui_table_footer 22 28
# Triage hints based on which phase ate the time. Thresholds chosen empirically:
# > 5s on cold boot is probably user-data driven (icon cache, network), > 10s is
# almost certainly something wrong (Qt ABI mismatch, env race, slow disk).
local total_ms=$((deferred_ms > 0 ? deferred_ms - origin : 0))
if [[ "$total_ms" -gt 10000 ]]; then
echo ""
tui_check_warn "Boot took $(_fmt_ms $total_ms) — unusually slow."
tui_info " Common culprits: Qt/Quickshell ABI mismatch, missing WAYLAND_DISPLAY env, slow icon cache, network-bound services on first run."
tui_info " Run 'inir doctor' to auto-detect, or share the table above when filing an issue."
elif [[ "$total_ms" -gt 5000 ]]; then
echo ""
tui_check_skip "Boot took $(_fmt_ms $total_ms) — a bit slow on first run; subsequent boots should be faster."
fi
}
show_status_environment() {
# Versions and system info — the things we always end up asking users for
# in support threads. Print once so they can paste their `inir status` output.
tui_title "System & Quickshell"
tui_table_header "Property" "Value" 22 42
# Distro
local distro="unknown"
if [[ -r /etc/os-release ]]; then
# shellcheck disable=SC1091
local pretty
pretty=$(. /etc/os-release && printf '%s' "${PRETTY_NAME:-${NAME:-unknown}}")
[[ -n "$pretty" ]] && distro="$pretty"
fi
tui_table_row "Distro" "$distro" 22 42
# Kernel
local kernel
kernel="$(uname -srm 2>/dev/null || echo unknown)"
tui_table_row "Kernel" "$kernel" 22 42
# Compositor + version
local compositor="unknown" comp_ver=""
if [[ -n "${NIRI_SOCKET:-}" ]] && command -v niri >/dev/null 2>&1; then
compositor="niri"
comp_ver="$(niri --version 2>/dev/null | grep -oP '\d+\.\d+(\.\d+)?' | head -1)"
elif [[ -n "${HYPRLAND_INSTANCE_SIGNATURE:-}" ]] && command -v Hyprland >/dev/null 2>&1; then
compositor="hyprland"
comp_ver="$(Hyprland --version 2>/dev/null | grep -oP 'v\d+\.\d+(\.\d+)?' | head -1 | tr -d 'v')"
elif command -v niri >/dev/null 2>&1 && niri msg --json version >/dev/null 2>&1; then
compositor="niri (offline)"
fi
[[ -n "$comp_ver" ]] && compositor="${compositor} ${comp_ver}"
tui_table_row "Compositor" "$compositor" 22 42
# Panel family
local panel_family="ii"
local user_cfg="$HOME/.config/illogical-impulse/config.json"
if [[ -r "$user_cfg" ]] && command -v jq >/dev/null 2>&1; then
local pf
pf="$(jq -r '.panelFamily // "ii"' "$user_cfg" 2>/dev/null)"
[[ -n "$pf" && "$pf" != "null" ]] && panel_family="$pf"
fi
tui_table_row "Panel Family" "$panel_family" 22 42
# Quickshell binary + version + revision + distributor
local qs_path qs_version_line
qs_path="$(command -v qs 2>/dev/null || command -v quickshell 2>/dev/null || true)"
if [[ -n "$qs_path" ]]; then
qs_version_line="$($qs_path --version 2>&1 | head -1 | tr -d '\r')"
# Strip ANSI just in case
qs_version_line="$(printf '%s' "$qs_version_line" | sed 's/\x1b\[[0-9;]*m//g')"
tui_table_row "Quickshell" "${qs_version_line:-unknown}" 22 42
else
tui_table_row "Quickshell" "not installed" 22 42
fi
# Quickshell package origin. We want to tell users if their binary came from
# a repo (in which case the maintainer rebuilds on Qt updates) or from AUR
# (in which case THEY have to rebuild on Qt updates). Force LANG=C so we don't
# depend on the user's locale (Spanish pacman prints 'Versión' / 'Nada').
if command -v pacman >/dev/null 2>&1; then
local qs_pkg
for cand in quickshell-git quickshell-bin quickshell; do
if pacman -Qi "$cand" &>/dev/null; then
local ver origin=""
ver="$(LANG=C pacman -Qi "$cand" 2>/dev/null | awk -F': +' '/^Version/ {print $2; exit}')"
if pacman -Qmq "$cand" &>/dev/null; then
origin="AUR / locally built"
else
local repo
repo="$(LANG=C pacman -Si "$cand" 2>/dev/null | awk -F': +' '/^Repository/ {print $2; exit}')"
if [[ -n "$repo" ]]; then
origin="repo: ${repo}"
else
origin="repo"
fi
fi
qs_pkg="${cand} ${ver} (${origin})"
break
fi
done
[[ -n "$qs_pkg" ]] && tui_table_row "QS Package" "$qs_pkg" 22 42
fi
# Qt build-time vs runtime (the ABI mismatch witness)
if [[ -n "$qs_path" ]] && command -v strings >/dev/null 2>&1; then
local buildtime_qt runtime_qt
buildtime_qt="$(strings "$qs_path" 2>/dev/null | grep -P '^6\.\d+\.\d+$' | head -1)"
if [[ -L /usr/lib/libQt6Core.so.6 ]]; then
runtime_qt="$(readlink -f /usr/lib/libQt6Core.so.6 2>/dev/null | grep -oP '[0-9]+\.[0-9]+\.[0-9]+$')"
fi
[[ -z "$runtime_qt" ]] && command -v pkg-config >/dev/null 2>&1 && \
runtime_qt="$(pkg-config --modversion Qt6Core 2>/dev/null)"
local qt_display="build=${buildtime_qt:-?} runtime=${runtime_qt:-?}"
if [[ -n "$buildtime_qt" && -n "$runtime_qt" && "$buildtime_qt" != "$runtime_qt" ]]; then
qt_display="${qt_display} ⚠ ABI mismatch"
fi
tui_table_row "Qt" "$qt_display" 22 42
fi
# Active session details
local session_type="${XDG_SESSION_TYPE:-?}"
local wayland_disp="${WAYLAND_DISPLAY:-(unset)}"
tui_table_row "Session" "$session_type ($wayland_disp)" 22 42
# Config namespace location — reminds users where the user config lives
if [[ -f "$user_cfg" ]]; then
tui_table_row "User Config" "$user_cfg" 22 42
else
tui_table_row "User Config" "(missing) ${user_cfg}" 22 42
fi
tui_table_footer 22 42
}
show_status() {
local installed_ver=$(get_installed_version)
local installed_commit=$(get_installed_commit)
local installed_mode=$(get_installed_install_mode)
local update_strategy=$(get_installed_update_strategy)
local installed_repo_path=$(get_installed_repo_path)
local update_hint=$(get_installed_package_update_hint)
local installed_version_file=$(get_installed_version_file)
local repo_ver
local repo_commit
local runtime_dir=$(get_runtime_shell_dir)
local runtime_version_file=""
local running_output
local runtime_dir_display="${runtime_dir:-"(missing)"}"
local repo_path_display="$installed_repo_path"
local branch_display="$(setup_current_branch)"
local tracked_branch="$(setup_tracked_branch)"
local remote_state="$(setup_remote_state_summary)"
local runtime_state="$(setup_runtime_change_summary)"
local preserved_mods="$(setup_preserved_mods_summary)"
if [[ -n "$runtime_dir" ]]; then
runtime_version_file="$(get_runtime_version_file)"
fi
if [[ -n "$repo_path_display" ]]; then
repo_path_display="$(realpath "$repo_path_display" 2>/dev/null || printf '%s' "$repo_path_display")"
fi
if [[ -n "$installed_repo_path" && -f "${installed_repo_path}/VERSION" ]]; then
repo_ver="$(head -1 "${installed_repo_path}/VERSION" | tr -d '[:space:]')"
repo_commit="$(git -C "$installed_repo_path" rev-parse --short HEAD 2>/dev/null || echo "unknown")"
else
repo_ver=$(get_repo_version)
repo_commit=$(get_repo_commit)
fi
tui_hero_card "Status" \
"What is installed, what is running, and whether this checkout still matches reality." \
"If any of this looks cursed, run ./setup doctor before you start randomly editing files."
tui_table_header "Property" "Value" 14 36
tui_table_row "Version" "$installed_ver" 14 36
tui_table_row "Commit" "$installed_commit" 14 36
tui_table_row "Install Mode" "$installed_mode" 14 36
tui_table_row "Updates" "$update_strategy" 14 36
tui_table_row "Branch" "$branch_display" 14 36
tui_table_row "Tracks" "origin/${tracked_branch}" 14 36
tui_table_row "Remote State" "$remote_state" 14 36
tui_table_row "Runtime State" "$runtime_state" 14 36
tui_table_row "Runtime Path" "$runtime_dir_display" 14 36
tui_table_row "Launcher" "inir run" 14 36
[[ -n "$repo_path_display" ]] && tui_table_row "Repo Path" "$repo_path_display" 14 36
if [[ "$update_strategy" == "package-manager" ]]; then
[[ -n "$update_hint" ]] && tui_table_row "Update Cmd" "$update_hint" 14 36
tui_table_row "Workspace Ver" "$repo_ver" 14 36
tui_table_row "Workspace SHA" "$repo_commit" 14 36
else
tui_table_row "Repo Version" "$repo_ver" 14 36
tui_table_row "Repo Commit" "$repo_commit" 14 36
fi
tui_table_footer 14 36
if [[ "$update_strategy" == "package-manager" ]]; then
echo ""
tui_info "This installation is externally managed. './setup update' will not sync repo files into the runtime."
fi
show_status_environment
tui_title "Health Checks"
# Check shell status (resolve symlinks so qs -p matches the running instance)
if [[ -n "$runtime_dir" && -f "$runtime_dir/shell.qml" ]]; then
local resolved_runtime_dir
resolved_runtime_dir="$(readlink -f "$runtime_dir" 2>/dev/null || printf '%s' "$runtime_dir")"
running_output="$(qs -p "$resolved_runtime_dir" list 2>/dev/null || true)"
if [[ -n "$running_output" && "$running_output" != No\ running\ instances* ]]; then
tui_check_ok "Shell is running"
else
tui_check_warn "Shell is not running"
fi
else
tui_check_warn "Runtime payload missing"
fi
local launcher_path
launcher_path="$(command -v inir 2>/dev/null || true)"
if [[ -n "$launcher_path" || -x "${REPO_ROOT}/scripts/inir" ]]; then
tui_check_ok "Launcher available${launcher_path:+: $launcher_path}"
else
tui_check_warn "Launcher not available in PATH"
fi
local service_path="${XDG_CONFIG_HOME}/systemd/user/inir.service"
local service_links
service_links="$(setup_service_link_summary)"
if [[ -f "$service_path" ]]; then
tui_check_ok "User service installed (${service_links})"
else
tui_check_warn "User service not installed"
fi
case "$remote_state" in
"up to date") tui_check_ok "Repo remote state: ${remote_state}" ;;
"update available"|"ahead of remote"|"offline or missing remote") tui_check_warn "Repo remote state: ${remote_state}" ;;
"diverged") tui_check_fail "Repo remote state: ${remote_state}" ;;
esac
if [[ -f "$runtime_version_file" ]]; then
tui_check_ok "Runtime metadata present"
elif [[ "$installed_mode" == "repo-link" && -n "$installed_version_file" ]] && version_file_has_core_metadata "$installed_version_file"; then
tui_check_ok "Repo-link metadata present via config tracking"
else
tui_check_warn "Runtime metadata missing"
fi
# Check Niri
if [[ -n "$NIRI_SOCKET" ]]; then
tui_check_ok "Niri compositor detected"
else
tui_check_warn "Not running in Niri session"
fi
# Pending migrations
local pending=$(count_pending_migrations 2>/dev/null || echo "0")
if [[ "$pending" -gt 0 ]]; then
tui_check_warn "$pending pending migration(s)"
tui_info "Run './setup migrate' to review"
else
tui_check_ok "No pending migrations"
fi
if [[ "$runtime_state" == "clean" || "$runtime_state" == "externally managed" ]]; then
tui_check_ok "Runtime payload state: ${runtime_state}"
else
tui_check_warn "Runtime payload state: ${runtime_state}"
fi
# Snapshots
local snapshot_count=$(list_snapshots 2>/dev/null | wc -l)
if [[ "$snapshot_count" -gt 0 ]]; then
tui_check_ok "$snapshot_count snapshot(s) available"
else
tui_check_skip "No snapshots"
fi
if [[ "$preserved_mods" == "0 backups" ]]; then
tui_check_skip "Preserved modifications: ${preserved_mods}"
else
tui_check_warn "Preserved modifications: ${preserved_mods}"
fi
# Last boot timing breakdown — helps users self-triage "my shell takes 15s to start".
# Pulls T0 from systemd, T1 from `qs list`, T2-T5 from ~/.cache/inir/last-boot.json
# (written by shell.qml at end of deferred phase).
show_status_boot_timing
echo ""
}