Repository navigation
Expand file tree
/
Copy pathbuild-menu.sh
More file actions
executable file
·3405 lines (3308 loc) · 217 KB
/
Copy pathbuild-menu.sh
File metadata and controls
executable file
·3405 lines (3308 loc) · 217 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
# build-menu.sh — a console (ncurses/whiptail) front door for the image build.
#
# WHAT IT IS
# An interactive terminal menu that drives the SAME `make` targets the rest of
# the repo uses (build-all / rpi / x86 / omnibus / frite / clean / rebuild). It
# adds nothing to the build engine — it just makes the knobs discoverable and
# shows live progress. Because it dispatches through `make`, it works for BOTH
# build paths with no extra logic: the default Docker builder image AND the
# local NATIVE=1 Gentoo path (a single in-menu toggle flips NATIVE).
#
# THREE THINGS THE USER ASKED FOR, AND HOW THEY ARE MET
# 1. "progress indicators" — a live monitor screen parses the build
# log for emerge's "(X of Y)" package
# counter and the per-role banners, and
# draws progress bars + a log tail.
# 2. "quit without stopping builds" — every build is launched DETACHED via
# `setsid nohup ... </dev/null &`, in its
# own session. Quitting the menu (or even
# closing the terminal) leaves it running.
# 3. "brought up again with current — on start the menu detects a build that
# progress" is still running (its own, OR one you
# launched by hand) and drops straight
# into the live monitor for it.
#
# RENDERER
# Uses whiptail (newt/ncurses) when a real TTY + whiptail are present; otherwise
# falls back to a plain numbered-prompt menu so it still works inside the minimal
# Docker builder image or a dumb terminal (set NO_TUI=1 to force the fallback).
# The live monitor is plain ANSI either way (so it can offer "press q to leave
# the build running", which a whiptail gauge cannot).
#
# RUN IT
# ./scripts/build-menu.sh # or: make menu
#
# It is interactive, so it deliberately does NOT use `set -e`: a TUI runs many
# commands that return non-zero benignly (whiptail Cancel = 1, grep no-match = 1,
# a `read` timeout > 128). We keep -u/pipefail and handle every error explicitly.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
# First-run bootstrap (issue #49): sourcing only defines functions; the call sits
# in main() so `source`-ing this file for tests stays side-effect-free.
# shellcheck source=scripts/_first-run-lib.sh
. "${SCRIPT_DIR}/_first-run-lib.sh"
# ── Colours (only when stderr is a TTY, matching scripts/_download-lib.sh) ──────
if [ -t 2 ]; then
C_RED=$'\033[31m'; C_GRN=$'\033[32m'; C_YEL=$'\033[33m'; C_CYN=$'\033[36m'
C_BLD=$'\033[1m'; C_DIM=$'\033[2m'; C_RST=$'\033[0m'
else
C_RED=''; C_GRN=''; C_YEL=''; C_CYN=''; C_BLD=''; C_DIM=''; C_RST=''
fi
say() { printf '%s[build-menu]%s %s\n' "${C_GRN}" "${C_RST}" "$*" >&2; }
warn() { printf '%s[build-menu] WARN:%s %s\n' "${C_YEL}" "${C_RST}" "$*" >&2; }
die() { printf '%s[build-menu] ERROR:%s %s\n' "${C_RED}" "${C_RST}" "$*" >&2; exit 1; }
# Only draw UTF-8 box-art when the locale is actually UTF-8 (the minimal Docker
# builder image runs in C/POSIX, where box chars render as mojibake).
case "${LC_ALL:-${LC_CTYPE:-${LANG:-}}}" in *[Uu][Tt][Ff]*) UTF8=1 ;; *) UTF8=0 ;; esac
# The Docker builder image tag (matches the Makefile's IMAGE), used to spot a
# docker-path build whose in-container scripts are invisible to host pgrep.
BUILDER_IMAGE="${IMAGE:-hugmesh-builder}"
# ── Persistent state (user-writable; WORK_DIR/out is often root-owned) ──────────
# Build state + saved menu options live here so a relaunch remembers your choices
# AND can re-attach to a running build. Kept OUT of WORK_DIR on purpose: a NATIVE
# build chowns WORK_DIR to root, which would make a state dir under it unwritable.
STATE_DIR="${SNAP_MENU_STATE:-${XDG_STATE_HOME:-${HOME}/.local/state}/hugmesh-build-menu}"
mkdir -p "${STATE_DIR}" 2>/dev/null || STATE_DIR="$(mktemp -d)"
PID_FILE="${STATE_DIR}/current.pid"
META_FILE="${STATE_DIR}/current.meta"
CONF_FILE="${STATE_DIR}/menu.conf"
# ── Build option defaults (overridable in the Options screen; persisted) ────────
OPT_WORK_DIR="${WORK_DIR:-${REPO_DIR}/out}"
OPT_JOBS="${JOBS:-$(nproc 2>/dev/null || echo 4)}"
OPT_ENV="test" # test | prod (baked build environment)
OPT_PATH="docker" # docker | native (native => make ... NATIVE=1)
OPT_BRAND="" # brands/<name>.conf
OPT_DOMAIN="" # overrides the brand's cluster domain
OPT_RESUME="no" # yes => reuse existing sysroots (RESUME=true)
OPT_OMNIBUS="no" # yes => add the x86 omnibus role (X86_OMNIBUS=1)
OPT_FRITE_FLEET="no" # yes => fleet-build Frite too (full-fleet build only; FRITE=1)
OPT_JETSON_FLEET="no" # yes => fleet-build Jetson too (full-fleet build only; JETSON=1)
OPT_ORANGEPI5_FLEET="no" # yes => fleet-build Orange Pi 5 too (full-fleet build only; ORANGEPI5=1)
OPT_PENTEST="no" # yes => run the OWASP pen-test after the build (PENTEST=1)
OPT_IMGFLAGS="" # e.g. --no-iso (img only) / --no-img (iso only)
OPT_DISTDIR="" # shared READ-ONLY distfiles cache dir (--distdir); arch-independent sources reused fleet-wide (shared-binpkg Lane 3). Empty = private per-build.
# ── Edge-AI inference service (GPU cluster roles: backend-gpu / omnibus / edge-ai) ─
OPT_X86_EDGE_AI="no" # yes => add the edge-ai service to backend-gpu/omnibus (edge-ai role always has it)
OPT_EDGE_AI_RUNTIME="ollama" # edge-ai inference runtime (ollama | vllm)
OPT_EDGE_AI_MODELS="" # comma list of models to PRELOAD (empty = builder default)
OPT_EDGE_AI_MODEL_DEFAULT="" # default model when an OpenAI request omits one (empty = builder default)
OPT_X86_EDGE_AI_ANALYSIS="no" # yes => also bake the edge-ai-analysis task API (image/log verdicts; separate image)
# edge-ai-tts is CPU-only + self-contained (NO edge-ai dependency, unlike
# edge-ai-analysis) — it is its own independent toggle, wired alongside Tor /
# Character Studio below (not gated to the GPU-target case).
OPT_EDGE_AI_TTS="no" # yes => --with-edge-ai-tts: Piper TTS + viseme timeline (VN voice, separate image)
# ── Tor v3 onion (hidden) service — node-scoped optional, DEFAULT-OFF ──────────
OPT_TOR_ONION="no" # yes => --with-tor: expose the in-cluster fe-gateway as a v3 .onion
# ── Thin-desktop stream host (Sunshine, §8b) — client desktops, DEFAULT-OFF ────
OPT_SUNSHINE="no" # yes => --with-sunshine: Sunshine + mesh fence + session autostart (tailnet client desktops; builder warn-drops elsewhere)
# Mesh-node identity provider (I6). casdoor = built-in default (emits NOTHING —
# argv byte-identical); entra|aws|oidc = external OIDC (issuer/client/jwks are
# PUBLIC identifiers, safe to persist; client SECRETS are never a flag here).
OPT_IDP="casdoor"
OPT_IDP_ISSUER=""
OPT_IDP_CLIENT_ID=""
OPT_IDP_JWKS=""
# ── Character Studio (VN) frontend remote — OPTIONAL, DEFAULT-OFF (admin gate) ──
OPT_CHARACTER_STUDIO="no" # yes => --with-character-studio: VN character-studio remote at /character-studio
# ── Character Forge (3D) multi-app slug — OPTIONAL, DEFAULT-OFF (admin gate) ────
OPT_CHARACTER_FORGE="no" # yes => --with-character-forge: 3D character maker (BFF db+api + remote at /character-forge)
# ── OPTIONAL services catalog (cluster roles; specs/cluster/optional-services.yaml) ─
# Comma list of user-level slugs {akkoma,tuwunel,phpbb,games,owncast,tube,
# character-studio,character-forge}. Empty = builder default (akkoma tuwunel
# phpbb); the literal 'none' = EXPLICITLY none (=> --optional-services ""). The
# checklist supersedes the lone character-studio/character-forge toggles above —
# they are kept in sync both ways.
OPT_SERVICES=""
# ── MANAGED backing services (I8/M2; specs/cluster/backing-services.yaml) ────────
# SPACE-separated `id=endpoint` tokens (mirrors the builders' MANAGED_SERVICES env,
# so a kafka broker-list endpoint keeps its literal commas). EMPTY = every backing
# service self-hosted = the byte-identical default (casdoor-style: adds NOTHING).
# Composed into bf as a repeatable `--managed-service id=endpoint`. Only TIER-1/2 ids
# may be repointed; TIER-3 ids are refused (shown read-only). Endpoints are non-secret
# coordinates (persisted); creds ride the KEYS USB via ESO/Vault, never here.
OPT_MANAGED_SERVICES=""
MANAGED_TIER12_IDS=(velero-objectstore smtp kafka clickhouse federation-bundles \
postgres-admin-bff postgres-user-bff postgres-mod-bff \
postgres-forum-bff postgres-wiki-bff postgres-casdoor)
MANAGED_TIER3_IDS=(cassandra harbor vault-kv vault-pki)
# ── Installer front-ends offered on the live ISO (--installer-ui) ───────────────
OPT_INSTALLER_UI="" # cli | ncurses | calamares | all (empty = builder default)
# ── Extra builder flags — the verbatim escape hatch (all-options-in-all-menus) ──
# Appended AS-IS after --role on x86-*/jetson-* targets (via STANDALONE_FLAGS) and
# onto IMG_FLAGS for the other single-role targets, so ANY builder flag the menu
# has no widget for stays reachable.
OPT_EXTRA_FLAGS=""
# ── Advanced branding OVERRIDES (on top of the brand profile / --theme preset) ──
OPT_BR_WALLPAPER="" # --wallpaper FILE
OPT_BR_GRUB_BG="" # --grub-background FILE
OPT_BR_LOGIN_BG="" # --login-background FILE
OPT_BR_LOGO="" # --brand-logo FILE
OPT_BR_ACCENT="" # --accent-color '#RRGGBB'
OPT_BR_SCHEME="" # --color-scheme FILE.colors
# ── Home provisioning (standalone/client desktop roles) ─────────────────────────
OPT_HOME_MODE="" # --home-mode create|adopt|archive|restore (empty = builder default)
OPT_HOME_DEVICE="" # --home-device LABEL=…|UUID=…|/dev/… (adopt)
OPT_HOME_BACKUP="" # --home-backup FILE|auto (restore)
OPT_HOME_ENCRYPTED="no" # yes => --home-encrypted (per-user eCryptfs on top of LUKS2)
OPT_HOME_SEED="" # --home-seed-code repos|stack|mesh (empty/none = builder default: none)
OPT_HOME_ARCHIVE="" # --include-home-archive FILE (scripts/archive-home.sh tarball)
OPT_FRITE_BOARD="la-frite"
OPT_FRITE_FLAVOR="both"
OPT_FRITE_DESKTOP="light" # light (LEAN LXDE desktop) | none (headless base)
# ── RPi board axis (build-rpi5-stage4.sh --board; ONE builder, all 3 boards) ──
OPT_RPI_BOARD="rpi5" # rpi5 (DEFAULT, BCM2712/Cortex-A76) | rpi4 (BCM2711/Cortex-A72) | rpi3 (BCM2837/Cortex-A53, desktop-only)
# ── Jetson Orin (arm64 Tegra234; EXPERIMENTAL — hardware validation pending) ────
OPT_JETSON_BOARD="orin-nano" # orin-nano | orin-nano-4gb | orin-nx-8gb | orin-nx-16gb
OPT_JETSON_KFLAVOR="mainline" # mainline (buildable; NO CUDA) — the ONLY offered flavour
# l4t is NOT offered: build-jetson-stage4.sh exits 1 on it by design. It is listed in
# the Jetson kernel menu with this reason and can never be selected (the Studio shows
# it greyed with the same reason, KERNEL_FLAVOR_REFUSED in core/config.py).
JETSON_L4T_REASON="not offered: the builder exits non-zero on it by design. NVIDIA's L4T kernel and CUDA userspace are EULA-gated downloads it does not fetch; flash them out of band (specs-jetson/installer/TEGRAFLASH.md). mainline builds, without CUDA."
# ── Orange Pi 5 (arm64 Rockchip RK3588/RK3588S; EXPERIMENTAL — hardware
# validation pending) ────────────────────────────────────────────────────────
OPT_ORANGEPI5_BOARD="orange-pi-5-plus" # orange-pi-5-plus (DEFAULT) | orange-pi-5
OPT_ORANGEPI5_FLAVOR="both" # both (DEFAULT) | live | installer
# ── Orange Pi Zero 2 (arm64 Allwinner H616 HEADLESS APPLIANCE; EXPERIMENTAL —
# hardware validation pending). No board axis (one board) and no --desktop
# toggle (no desktop mode, ever — see specs-orangepi-zero2/README.md) — just
# --flavor. ───────────────────────────────────────────────────────────────
OPT_ORANGEPIZERO2_FLAVOR="both" # both (DEFAULT) | live | installer
# ── Orange Pi Zero 2W (arm64 Allwinner H618 HEADLESS APPLIANCE; EXPERIMENTAL —
# hardware validation pending). Same single-board/flavor-only shape as the
# Zero 2 (its H616 template sibling — see specs-orangepi-zero2w/README.md). ──
OPT_ORANGEPIZERO2W_FLAVOR="both" # both (DEFAULT) | live | installer
# ── Orange Pi Zero 3 (arm64 Allwinner H618 HEADLESS APPLIANCE; EXPERIMENTAL —
# hardware validation pending). Same single-board/flavor-only shape as the
# Zero 2W (its same-SoC H618 template — see specs-orangepi-zero3/README.md). ──
OPT_ORANGEPIZERO3_FLAVOR="both" # both (DEFAULT) | live | installer
# ── Orange Pi 3 LTS (arm64 Allwinner H6 HEADLESS APPLIANCE; EXPERIMENTAL —
# hardware validation pending). Same single-board/flavor-only shape as the
# Zero 2 (its sunxi template — see specs-orangepi3-lts/README.md; boots the
# PLAIN OPi3's mainline DTB/defconfig, USB-Ethernet-first). ─────────────────
OPT_ORANGEPI3LTS_FLAVOR="both" # both (DEFAULT) | live | installer
# ── Orange Pi 4 LTS (arm64 Rockchip RK3399 LIGHT DESKTOP; EXPERIMENTAL —
# hardware validation pending). Single-board/flavor-only shape like the
# appliances above, but this board IS a desktop client (enabled Mali-T860 +
# HDMI in the mainline DTB it boots — see specs-orangepi4-lts/README.md). ──
OPT_ORANGEPI4LTS_FLAVOR="both" # both (DEFAULT) | live | installer
# GB of RAM on the Pi / Orange Pi board a NODE image is for (--ram-gb via RAM_GB).
# "" = not stated (fine for pki/backend/frontend); omnibus REQUIRES it (16 GB+).
OPT_RAM_GB=""
# ── Standalone hardened NVIDIA desktop options (NON-secret; persisted) ──────────
OPT_SA_GPU="all-free" # all-free|nvidia-free|nvidia|amd-free|amd-pro|intel-free|intel-pro
OPT_SA_STEAM="native" # native | flatpak | none
OPT_SA_MEDIA="yes" # yes => media-data auto-detect (/media Vaults+Steam)
OPT_SA_USER="snap" # local login user name
OPT_SA_KEYFILE="none" # none | boot | login (extra unlock factor: keyfile)
OPT_SA_YUBIKEY="none" # none | boot | login (extra unlock factor: FIDO2)
OPT_SA_THEME="dark" # branding theme preset (none | light | dark | purple | grey)
OPT_SA_PROXY="yes" # Squid+Privoxy+Firefox proxy stack (desktops; default on)
OPT_SA_SNORT="yes" # Snort IDS (default on)
OPT_SA_AIDE="no" # AIDE file-integrity IDS (opt-in)
OPT_SA_KBUILTIN="no" # compile most of the kernel built-in (=y) vs modules
OPT_SA_EGRESS="" # egress VPN conf path (wg .conf / .ovpn); empty = none
OPT_SA_MEDIA_LABEL="" # --media-label: match the data device by FS LABEL (empty = content-scan)
# SECRETS are deliberately NOT persisted (never written to ${CONF_FILE}); they are
# prompted fresh each build and live only in these shell vars for the run.
SA_LOCAL_PASS="" # local user password (plaintext, hashed by the builder)
SA_LUKS_PASS="" # LUKS root-unlock passphrase (build-time only)
# Same masked/non-persisted contract as SA_LOCAL_PASS/SA_LUKS_PASS above, for the
# 5 platforms that gained --standalone in the standalone-ARM track (rpi5 desktop,
# frite, jetson desktop, orangepi5, orangepizero2) — none of them has a dedicated
# standalone_screen() of its own, so without this the ONLY reachable path for
# these secrets would be the unmasked, persisted "Extra builder flags" field
# (see arm_secrets_prompt() / _arm_standalone_flags() below).
ARM_LOCAL_PASS=""
ARM_LUKS_PASS=""
OPT_ROOT_LOGIN="no" # no (DEFAULT, hardened) | prohibit-password | yes (PERMIT_ROOT_LOGIN)
# Restore saved options from a previous session (best-effort; ignore a bad file).
# shellcheck disable=SC1090
[ -f "${CONF_FILE}" ] && source "${CONF_FILE}" 2>/dev/null || true
# A menu.conf saved before l4t stopped being offered may still name it; the fleet path
# would pass it straight to make, so it falls back to the one flavour that builds.
[ "${OPT_JETSON_KFLAVOR}" = mainline ] || OPT_JETSON_KFLAVOR="mainline"
save_conf() {
{
printf 'OPT_WORK_DIR=%q\n' "${OPT_WORK_DIR}"
printf 'OPT_JOBS=%q\n' "${OPT_JOBS}"
printf 'OPT_ENV=%q\n' "${OPT_ENV}"
printf 'OPT_PATH=%q\n' "${OPT_PATH}"
printf 'OPT_BRAND=%q\n' "${OPT_BRAND}"
printf 'OPT_DOMAIN=%q\n' "${OPT_DOMAIN}"
printf 'OPT_RESUME=%q\n' "${OPT_RESUME}"
printf 'OPT_OMNIBUS=%q\n' "${OPT_OMNIBUS}"
printf 'OPT_FRITE_FLEET=%q\n' "${OPT_FRITE_FLEET}"
printf 'OPT_JETSON_FLEET=%q\n' "${OPT_JETSON_FLEET}"
printf 'OPT_ORANGEPI5_FLEET=%q\n' "${OPT_ORANGEPI5_FLEET}"
printf 'OPT_PENTEST=%q\n' "${OPT_PENTEST}"
printf 'OPT_IMGFLAGS=%q\n' "${OPT_IMGFLAGS}"
printf 'OPT_DISTDIR=%q\n' "${OPT_DISTDIR}"
printf 'OPT_X86_EDGE_AI=%q\n' "${OPT_X86_EDGE_AI}"
printf 'OPT_EDGE_AI_RUNTIME=%q\n' "${OPT_EDGE_AI_RUNTIME}"
printf 'OPT_EDGE_AI_MODELS=%q\n' "${OPT_EDGE_AI_MODELS}"
printf 'OPT_EDGE_AI_MODEL_DEFAULT=%q\n' "${OPT_EDGE_AI_MODEL_DEFAULT}"
printf 'OPT_X86_EDGE_AI_ANALYSIS=%q\n' "${OPT_X86_EDGE_AI_ANALYSIS}"
printf 'OPT_EDGE_AI_TTS=%q\n' "${OPT_EDGE_AI_TTS}"
printf 'OPT_TOR_ONION=%q\n' "${OPT_TOR_ONION}"
printf 'OPT_SUNSHINE=%q\n' "${OPT_SUNSHINE}"
printf 'OPT_IDP=%q\n' "${OPT_IDP}"
printf 'OPT_IDP_ISSUER=%q\n' "${OPT_IDP_ISSUER}"
printf 'OPT_IDP_CLIENT_ID=%q\n' "${OPT_IDP_CLIENT_ID}"
printf 'OPT_IDP_JWKS=%q\n' "${OPT_IDP_JWKS}"
printf 'OPT_CHARACTER_STUDIO=%q\n' "${OPT_CHARACTER_STUDIO}"
printf 'OPT_CHARACTER_FORGE=%q\n' "${OPT_CHARACTER_FORGE}"
printf 'OPT_SERVICES=%q\n' "${OPT_SERVICES}"
printf 'OPT_MANAGED_SERVICES=%q\n' "${OPT_MANAGED_SERVICES}"
printf 'OPT_INSTALLER_UI=%q\n' "${OPT_INSTALLER_UI}"
printf 'OPT_EXTRA_FLAGS=%q\n' "${OPT_EXTRA_FLAGS}"
printf 'OPT_BR_WALLPAPER=%q\n' "${OPT_BR_WALLPAPER}"
printf 'OPT_BR_GRUB_BG=%q\n' "${OPT_BR_GRUB_BG}"
printf 'OPT_BR_LOGIN_BG=%q\n' "${OPT_BR_LOGIN_BG}"
printf 'OPT_BR_LOGO=%q\n' "${OPT_BR_LOGO}"
printf 'OPT_BR_ACCENT=%q\n' "${OPT_BR_ACCENT}"
printf 'OPT_BR_SCHEME=%q\n' "${OPT_BR_SCHEME}"
printf 'OPT_HOME_MODE=%q\n' "${OPT_HOME_MODE}"
printf 'OPT_HOME_DEVICE=%q\n' "${OPT_HOME_DEVICE}"
printf 'OPT_HOME_BACKUP=%q\n' "${OPT_HOME_BACKUP}"
printf 'OPT_HOME_ENCRYPTED=%q\n' "${OPT_HOME_ENCRYPTED}"
printf 'OPT_HOME_SEED=%q\n' "${OPT_HOME_SEED}"
printf 'OPT_HOME_ARCHIVE=%q\n' "${OPT_HOME_ARCHIVE}"
printf 'OPT_FRITE_BOARD=%q\n' "${OPT_FRITE_BOARD}"
printf 'OPT_FRITE_FLAVOR=%q\n' "${OPT_FRITE_FLAVOR}"
printf 'OPT_FRITE_DESKTOP=%q\n' "${OPT_FRITE_DESKTOP}"
printf 'OPT_RPI_BOARD=%q\n' "${OPT_RPI_BOARD}"
printf 'OPT_JETSON_BOARD=%q\n' "${OPT_JETSON_BOARD}"
printf 'OPT_JETSON_KFLAVOR=%q\n' "${OPT_JETSON_KFLAVOR}"
printf 'OPT_ORANGEPI5_BOARD=%q\n' "${OPT_ORANGEPI5_BOARD}"
printf 'OPT_ORANGEPI5_FLAVOR=%q\n' "${OPT_ORANGEPI5_FLAVOR}"
printf 'OPT_ORANGEPIZERO2_FLAVOR=%q\n' "${OPT_ORANGEPIZERO2_FLAVOR}"
printf 'OPT_ORANGEPIZERO2W_FLAVOR=%q\n' "${OPT_ORANGEPIZERO2W_FLAVOR}"
printf 'OPT_ORANGEPIZERO3_FLAVOR=%q\n' "${OPT_ORANGEPIZERO3_FLAVOR}"
printf 'OPT_ORANGEPI3LTS_FLAVOR=%q\n' "${OPT_ORANGEPI3LTS_FLAVOR}"
printf 'OPT_ORANGEPI4LTS_FLAVOR=%q\n' "${OPT_ORANGEPI4LTS_FLAVOR}"
printf 'OPT_RAM_GB=%q\n' "${OPT_RAM_GB}"
# Standalone-desktop NON-secret options (passwords are NEVER persisted).
printf 'OPT_SA_GPU=%q\n' "${OPT_SA_GPU}"
printf 'OPT_SA_STEAM=%q\n' "${OPT_SA_STEAM}"
printf 'OPT_SA_MEDIA=%q\n' "${OPT_SA_MEDIA}"
printf 'OPT_SA_USER=%q\n' "${OPT_SA_USER}"
printf 'OPT_SA_KEYFILE=%q\n' "${OPT_SA_KEYFILE}"
printf 'OPT_SA_YUBIKEY=%q\n' "${OPT_SA_YUBIKEY}"
printf 'OPT_SA_THEME=%q\n' "${OPT_SA_THEME}"
printf 'OPT_SA_PROXY=%q\n' "${OPT_SA_PROXY}"
printf 'OPT_SA_SNORT=%q\n' "${OPT_SA_SNORT}"
printf 'OPT_SA_AIDE=%q\n' "${OPT_SA_AIDE}"
printf 'OPT_SA_KBUILTIN=%q\n' "${OPT_SA_KBUILTIN}"
printf 'OPT_SA_EGRESS=%q\n' "${OPT_SA_EGRESS}"
printf 'OPT_SA_MEDIA_LABEL=%q\n' "${OPT_SA_MEDIA_LABEL}"
printf 'OPT_ROOT_LOGIN=%q\n' "${OPT_ROOT_LOGIN}"
} > "${CONF_FILE}" 2>/dev/null || true
}
# ── UI abstraction: whiptail when we can, a text prompt when we cannot ──────────
# Decide ONCE whether the rich renderer is usable: a real interactive TTY, a sane
# TERM, whiptail on PATH, and NO_TUI not set.
HAVE_TUI=0
if [ -z "${NO_TUI:-}" ] && [ -t 0 ] && [ -t 1 ] \
&& [ "${TERM:-dumb}" != dumb ] && command -v whiptail >/dev/null 2>&1; then
HAVE_TUI=1
fi
WT_TITLE="HugMesh Image Builder"
# _u STRING… — return STRING with the handful of non-ASCII glyphs the menu labels
# use (em/en dash, ellipsis, guillemets, arrows, star, box-art, bullets) folded to
# ASCII WHEN the locale/terminal is not UTF-8 (UTF8=0). In a UTF-8 locale the string
# passes through byte-for-byte. Pure bash ${//} substitution (no sed/iconv/locale
# dependency), so it is correct even under C/POSIX where a multibyte glyph would
# otherwise reach whiptail (and the text fallback) as mojibake. Applied at the ui_*
# choke points below to every DISPLAYED string — never to a menu TAG (return value).
_u() {
local s="$*"
[ "${UTF8}" = 1 ] && { printf '%s' "${s}"; return 0; }
s="${s//★/*}"; s="${s//●/*}"; s="${s//•/*}"; s="${s//▶/>}"; s="${s//⚙/*}"
s="${s//‹/<}"; s="${s//›/>}"; s="${s//→/->}"; s="${s//←/<-}"
s="${s//—/-}"; s="${s//–/-}"; s="${s//…/...}"
s="${s//═/=}"; s="${s//─/-}"
s="${s//║/|}"; s="${s//╔/+}"; s="${s//╗/+}"; s="${s//╚/+}"; s="${s//╝/+}"
s="${s//“/\"}"; s="${s//”/\"}"; s="${s//‘/\'}"; s="${s//’/\'}"
printf '%s' "${s}"
}
# _u_items ARGS… — transliterate ONLY the label of each (tag,label[,state]) group
# for the menu/checklist text builders. STRIDE (2 for menu, 3 for checklist) is read
# from _U_STRIDE. Emits the rewritten args NUL-safe via a global array _U_OUT so tags
# (the return values) are never altered — only what the user SEES.
_u_items() {
_U_OUT=()
local n=0 stride="${_U_STRIDE:-2}"
local a
for a in "$@"; do
if [ "$((n % stride))" -eq 1 ]; then _U_OUT+=("$(_u "${a}")"); else _U_OUT+=("${a}"); fi
n=$((n + 1))
done
}
# ui_menu TITLE PROMPT tag1 item1 tag2 item2 ... -> echoes chosen tag, rc=1 on cancel
ui_menu() {
local title="$1" prompt="$2"; shift 2
title="$(_u "${title}")"; prompt="$(_u "${prompt}")"
_U_STRIDE=2 _u_items "$@"; set -- "${_U_OUT[@]}"
if [ "${HAVE_TUI}" = 1 ]; then
whiptail --title "${WT_TITLE} — ${title}" --notags --menu "${prompt}" \
22 78 12 "$@" 3>&1 1>&2 2>&3
return $?
fi
# Text fallback: number the (tag,item) pairs and read a choice.
local -a tags=() items=(); local i
while [ "$#" -ge 2 ]; do tags+=("$1"); items+=("$2"); shift 2; done
printf '\n%s== %s ==%s\n' "${C_BLD}" "${title}" "${C_RST}" >&2
printf '%b\n' "${prompt}" >&2
for i in "${!items[@]}"; do printf ' %2d) %s\n' "$((i+1))" "${items[$i]}" >&2; done
printf ' q) back / cancel\n' >&2
# Loop on INVALID input (a typo must not be mistaken for Cancel, which would
# quit the program from the main menu); only 'q' / empty returns the cancel rc.
local choice
while true; do
read -r -p "choice: " choice </dev/tty || return 1
{ [ "${choice}" = q ] || [ -z "${choice}" ]; } && return 1
if [[ "${choice}" =~ ^[0-9]+$ ]] && [ "${choice}" -ge 1 ] && [ "${choice}" -le "${#tags[@]}" ]; then
printf '%s' "${tags[$((choice-1))]}"; return 0
fi
warn "invalid choice — enter 1-${#tags[@]} or q"
done
}
# jetson_kernel_menu — pick the Jetson --kernel-flavor. Only mainline is offered. The
# l4t row is listed with its reason (the builder exits non-zero on it by design) under
# a tag that is not a flavour, and choosing it explains why and asks again, so
# OPT_JETSON_KFLAVOR can never become l4t here. rc=1 on back/cancel.
jetson_kernel_menu() {
local kflavor
while true; do
kflavor="$(ui_menu "Jetson kernel" "Kernel route (--kernel-flavor; current: ${OPT_JETSON_KFLAVOR}):" \
mainline "mainline — gentoo-sources, buildable (DEFAULT; NO CUDA)" \
l4t-not-offered "l4t — not offered: exits non-zero by design (select for why)" \
back "‹ back")" || return 1
case "${kflavor}" in
mainline) OPT_JETSON_KFLAVOR=mainline; return 0 ;;
l4t-not-offered) ui_msg "l4t is not offered" "l4t ${JETSON_L4T_REASON}" ;;
*) return 1 ;;
esac
done
}
# ui_checklist TITLE PROMPT tag1 item1 on|off tag2 item2 on|off ...
# -> echoes the CHOSEN tags space-separated (may be empty), rc=1 on cancel.
# The multi-select analogue of ui_menu (whiptail --checklist / a text toggle loop).
ui_checklist() {
local title="$1" prompt="$2"; shift 2
title="$(_u "${title}")"; prompt="$(_u "${prompt}")"
_U_STRIDE=3 _u_items "$@"; set -- "${_U_OUT[@]}"
if [ "${HAVE_TUI}" = 1 ]; then
local out
out="$(whiptail --title "${WT_TITLE} — ${title}" --notags --separate-output \
--checklist "${prompt}" 22 78 10 "$@" 3>&1 1>&2 2>&3)" || return 1
# --separate-output = one tag per line; join to one space-separated row.
printf '%s' "${out}" | tr '\n' ' ' | sed -E 's/ +$//'
return 0
fi
# Text fallback: [x]/[ ] rows; a number toggles, 'd'/empty = done, 'q' = cancel.
local -a tags=() items=() states=(); local i
while [ "$#" -ge 3 ]; do tags+=("$1"); items+=("$2"); states+=("$3"); shift 3; done
local choice
while true; do
printf '\n%s== %s ==%s\n' "${C_BLD}" "${title}" "${C_RST}" >&2
printf '%b\n' "${prompt}" >&2
for i in "${!items[@]}"; do
printf ' %2d) [%s] %s\n' "$((i+1))" "$([ "${states[$i]}" = on ] && echo x || echo ' ')" "${items[$i]}" >&2
done
printf ' d) done (keep this selection) q) cancel\n' >&2
read -r -p "toggle: " choice </dev/tty || return 1
[ "${choice}" = q ] && return 1
if [ "${choice}" = d ] || [ -z "${choice}" ]; then
local out=""
for i in "${!tags[@]}"; do [ "${states[$i]}" = on ] && out+="${tags[$i]} "; done
printf '%s' "${out% }"; return 0
fi
if [[ "${choice}" =~ ^[0-9]+$ ]] && [ "${choice}" -ge 1 ] && [ "${choice}" -le "${#tags[@]}" ]; then
i=$((choice-1))
states[$i]="$([ "${states[$i]}" = on ] && echo off || echo on)"
else
warn "invalid choice — enter 1-${#tags[@]}, d or q"
fi
done
}
# ui_yesno TITLE TEXT -> rc 0 = yes, 1 = no
ui_yesno() {
local title="$1" text="$2"
title="$(_u "${title}")"; text="$(_u "${text}")"
if [ "${HAVE_TUI}" = 1 ]; then
whiptail --title "${WT_TITLE} — ${title}" --yesno "${text}" 14 78
return $?
fi
printf '\n%b\n' "${text}" >&2 # %b so embedded \n render as line breaks
local a; read -r -p "[y/N]: " a </dev/tty || return 1
[[ "${a}" =~ ^[Yy] ]]
}
# ui_input TITLE TEXT DEFAULT -> echoes the entered value (default on empty/cancel)
ui_input() {
local title="$1" text="$2" def="$3" val
title="$(_u "${title}")"; text="$(_u "${text}")"
if [ "${HAVE_TUI}" = 1 ]; then
val="$(whiptail --title "${WT_TITLE} — ${title}" --inputbox "${text}" 12 78 "${def}" 3>&1 1>&2 2>&3)" \
|| { printf '%s' "${def}"; return 0; }
printf '%s' "${val}"; return 0
fi
read -r -e -i "${def}" -p "${text}: " val </dev/tty || val="${def}"
printf '%s' "${val:-${def}}"
}
# ui_password TITLE TEXT [DEFAULT] -> echoes the entered secret (hidden input).
# On cancel, returns DEFAULT (same return-only contract as ui_input) instead of
# wiping it — the box itself is never pre-filled with the secret, only the
# returned value falls back. Never logged, never persisted by the caller. Empty
# result (submitted, not cancelled) is a valid "skip".
ui_password() {
local title="$1" text="$2" def="${3:-}" val
title="$(_u "${title}")"; text="$(_u "${text}")"
if [ "${HAVE_TUI}" = 1 ]; then
val="$(whiptail --title "${WT_TITLE} — ${title}" --passwordbox "${text}" 12 78 3>&1 1>&2 2>&3)" \
|| { printf '%s' "${def}"; return 0; }
printf '%s' "${val}"; return 0
fi
read -r -s -p "${text}: " val </dev/tty || val="${def}"
printf '\n' >&2
printf '%s' "${val:-${def}}"
}
# ui_password_confirmed TITLE TEXT [DEFAULT] -> a LOGIN password, typed twice.
# A single masked entry bakes a typo in silently: the image then refuses the
# password the operator believes they set. On a mismatch nothing changes (DEFAULT
# is returned) and the operator is told so. Cancel on either box = DEFAULT.
ui_password_confirmed() {
local title="$1" text="$2" def="${3:-}" p1 p2 none=$'\001'
p1="$(ui_password "${title}" "${text}" "${none}")"
[ "${p1}" = "${none}" ] && { printf '%s' "${def}"; return 0; }
p2="$(ui_password "${title}" "Type the same password again to confirm" "${none}")"
[ "${p2}" = "${none}" ] && { printf '%s' "${def}"; return 0; }
if [ "${p1}" != "${p2}" ]; then
ui_msg "${title}" "The two passwords did not match. Nothing was changed." >&2
printf '%s' "${def}"; return 0
fi
printf '%s' "${p1}"
}
# arm_secrets_prompt LABEL [required] — masked, non-persisted --local-pass/--luks-pass
# entry point for the 8 platforms whose --standalone posture has no dedicated
# screen of its own (rpi5 desktop / frite / jetson desktop / orangepi5 /
# orangepizero2 / orangepizero2w / orangepizero3 / orangepi3-lts / orangepi4-lts — unlike x86, which has standalone_screen()). Without this,
# the only way to set these secrets on those platforms is typing them into
# the unmasked, persisted "Extra builder flags" field — see
# _arm_standalone_flags() for how these fold into STANDALONE_FLAGS instead.
#
# "required" (the DESKTOP images: rpi5/jetson desktop, frite with a desktop,
# orangepi5, orangepi4-lts): the login password is the local account the desktop
# greeter logs in with on every image (standalone, tailnet-only and mesh — first
# boot applies it either way), so a blank one is refused the way standalone_screen
# refuses it; returns 1 (the caller does not build) when the operator leaves
# without one. The headless appliances keep blank = a one-time password on their
# serial console, which IS their login surface.
arm_secrets_prompt() {
local label="$1" required="${2:-}" choice unset_txt
unset_txt='(unset -> random at first boot)'
[ "${required}" = required ] && unset_txt='(unset — REQUIRED to build)'
while :; do
choice="$(ui_menu "${label}: login & secrets" "The Login Password is the local account's desktop login (first boot applies it on standalone, tailnet-only and mesh images). Masked input; never saved to ${CONF_FILE}." \
pass "Local password ..... $([ -n "${ARM_LOCAL_PASS}" ] && echo '(set)' || echo "${unset_txt}")" \
luks "Unattended LUKS pass $([ -n "${ARM_LUKS_PASS}" ] && echo '(set — advanced)' || echo '(prompts at build/install — recommended)')" \
done "‹ done")" || choice=done
case "${choice}" in
pass) ARM_LOCAL_PASS="$(ui_password_confirmed "Password" "Local login password$([ "${required}" = required ] && echo ' (you log in with this at the desktop greeter; hashed at build time, never saved)' || echo ' (blank = random one-time at first boot, shown once on the console)')" "${ARM_LOCAL_PASS}")" ;;
luks) ARM_LUKS_PASS="$(ui_password "Unattended LUKS" "Bake an unattended LUKS passphrase (ADVANCED; blank = prompt at build/install)" "${ARM_LUKS_PASS}")" ;;
*)
if [ "${required}" = required ] && [ -z "${ARM_LOCAL_PASS}" ]; then
ui_msg "Login required" "Set the 'Local password' before building ${label}: it is the account you log in with at the desktop greeter. Without it the image's only login is a one-time password printed to a console that sits behind the greeter."
ui_yesno "Login required" "Go back and set the password? (No = do not build)" || return 1
continue
fi
return 0 ;;
esac
done
}
# ui_msg TITLE TEXT -> informational box / printout
ui_msg() {
local title="$1" text="$2"
title="$(_u "${title}")"; text="$(_u "${text}")"
if [ "${HAVE_TUI}" = 1 ]; then
whiptail --title "${WT_TITLE} — ${title}" --scrolltext --msgbox "${text}" 22 78
else
printf '\n%s== %s ==%s\n' "${C_BLD}" "${title}" "${C_RST}" >&2
printf '%b\n' "${text}" >&2 # %b so embedded \n render as line breaks
read -r -p "press Enter…" _ </dev/tty || true
fi
}
# ── Detached-build state helpers ────────────────────────────────────────────────
# A build is OURS-and-running when the recorded PID is still alive AND still looks
# like our build (PID-reuse guard: after the build ends the OS can hand that number
# to an unrelated process; a bare `kill -0` would then report a phantom build and,
# worse, make Stop target a stranger).
menu_build_pid() { [ -f "${PID_FILE}" ] && cat "${PID_FILE}" 2>/dev/null || true; }
menu_build_alive() {
local p; p="$(menu_build_pid)"
[ -n "${p}" ] || return 1
kill -0 "${p}" 2>/dev/null || { rm -f "${PID_FILE}"; return 1; }
local cmd=""
[ -r "/proc/${p}/cmdline" ] && cmd="$(tr '\0' ' ' < "/proc/${p}/cmdline" 2>/dev/null)"
case "${cmd}" in
*make*|*docker*|*setsid*|*build-all-roles*|*stage4*) return 0 ;;
"") return 0 ;; # cmdline unreadable (root-owned build) but alive — trust it
*) rm -f "${PID_FILE}"; return 1 ;; # reused PID — drop the stale record
esac
}
# Detect ANY image build on this host — including one launched by hand outside this
# menu — so "bring it up with current progress" works regardless of who started it.
# Native: the host-side build scripts are visible. Docker: the build runs in the
# container's PID namespace (invisible to host pgrep), so fall back to the host-side
# `docker run <builder image>` wrapper (still a real, monitorable PID). Echoes a
# PID, or nothing.
foreign_build_pid() {
local p
p="$(pgrep -f 'build-all-roles\.sh|build-(rpi5|x86-host|frite|jetson|orangepi5|orangepi-zero2|orangepi-zero2w|orangepi-zero3|orangepi3-lts|orangepi4-lts)-stage4\.sh' 2>/dev/null | head -n1)"
[ -z "${p}" ] && p="$(pgrep -f "docker run.*${BUILDER_IMAGE}" 2>/dev/null | head -n1)"
printf '%s' "${p}"
}
# True if the recorded PID is alive OR any orchestrator/stage4 build is still
# running — used to VERIFY a stop actually worked (kill's rc lies on partial kills).
_pid_or_build_alive() {
local p="$1"
{ [ -n "${p}" ] && kill -0 "${p}" 2>/dev/null; } && return 0
[ -n "$(foreign_build_pid)" ]
}
# Pick the most relevant live log to monitor. Prefer the log of a build we
# launched; else fall back to the builders' own combined log, or a hand-launched
# run's redirect (the WORK_DIR/build.log the stage4 scripts tee into, or the
# common ~/snap-build.log redirect). Newest wins.
active_log() {
local m=""; [ -f "${META_FILE}" ] && m="$(grep -m1 '^log=' "${META_FILE}" 2>/dev/null | cut -d= -f2-)"
local -a cands=()
[ -n "${m}" ] && cands+=("${m}")
cands+=("${OPT_WORK_DIR}/build.log" "${HOME}/snap-build.log")
local best="" f
for f in "${cands[@]}"; do
[ -f "${f}" ] || continue
if [ -z "${best}" ] || [ "${f}" -nt "${best}" ]; then best="${f}"; fi
done
printf '%s' "${best}"
}
# _shell_quote VALUE — wrap VALUE in single quotes (escaping any embedded
# single quote as '\'') so it survives being textually re-expanded, UNQUOTED,
# into a Makefile recipe line (which GNU Make hands to a real shell) as ONE
# safe literal argument — regardless of embedded whitespace, $, backticks, or
# ;. Every secret value folded into STANDALONE_FLAGS below MUST go through
# this: without it, a password containing a shell metacharacter is executed as
# shell syntax rather than passed as a literal value (real command injection,
# not just word-splitting — see the Makefile's STANDALONE_FLAGS export comment
# for the OTHER half of this fix, the Docker-dispatch hop's own re-quoting).
_shell_quote() {
printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"
}
# _dq VALUE — VALUE as ONE double-quoted shell word, with \ " $ ` escaped, so a
# free-text value (path / label / issuer with spaces or metacharacters) can be
# spliced into a flag string that a recipe later expands unquoted, without being
# word-split or executed. Double quotes (not single) because they also survive the
# Makefile's own single-quoted IMG_FLAGS='...' Docker hop.
_dq() {
local v="$1"
v="${v//\\/\\\\}"; v="${v//\"/\\\"}"; v="${v//\$/\\\$}"; v="${v//\`/\\\`}"
printf '"%s"' "${v}"
}
# _word VALUE — like _dq but leaves a value made only of shell-safe characters
# untouched (so plain paths/names stay byte-identical on the command line).
_word() {
local v="$1"
# A typed "~/x" used to reach the shell unquoted and expand; keep that.
case "${v}" in "~/"*) v="${HOME}/${v#\~/}" ;; esac
set -- "${v}"
case "$1" in
""|*[!A-Za-z0-9_./:=@%+,-]*) _dq "$1" ;;
*) printf '%s' "$1" ;;
esac
}
# _redacted_run_make ARGS... — echoes a `make`-argv array joined for safe
# display/logging: any element shaped like STANDALONE_FLAGS=...--local-pass...
# or ...--luks-pass... is replaced WHOLESALE with a fixed placeholder. Used by
# launch_build()'s console/log preview; the REAL (unredacted) RUN_MAKE array is
# always what actually gets passed to `make`. Redacts the whole element rather
# than regex-matching a value inside a flattened string: since _shell_quote()
# wraps secrets in single quotes, a multi-word secret contains spaces of its
# own — a token-based regex would only mask the first word and leave the rest
# (plus a dangling quote) printed in the clear.
_redacted_run_make() {
local -a arr=("$@")
local i
for i in "${!arr[@]}"; do
case "${arr[${i}]}" in
STANDALONE_FLAGS=*--local-pass*|STANDALONE_FLAGS=*--luks-pass*)
arr[${i}]="STANDALONE_FLAGS=<redacted>" ;;
esac
done
printf '%s' "${arr[*]}"
}
# _stage_login_pass VALUE — the login password goes to the builder as a FILE
# (--local-pass-file), never as --local-pass on argv: `make … STANDALONE_FLAGS=…`
# and the builder's own argv are world-readable in /proc/<pid>/cmdline for the
# whole build, and the docker hop also leaves them in `docker inspect`. VALUE is
# written 0600 into a 0700 dir under the checkout, and LOGIN_PASS_REL is set to its
# path RELATIVE to the checkout: the same spelling resolves for a native make (cwd =
# the checkout) and inside the builder container (whose /src is the checkout), so
# no extra mount is needed. Runs in the PARENT shell (build_make_cmd), never in a
# $(...) — the dir it records must survive into launch_build, which removes it when
# the detached build ends. Blank VALUE -> LOGIN_PASS_REL="" (no flag).
LOGIN_PASS_DIR=""; LOGIN_PASS_REL=""
_stage_login_pass() {
local v="$1"
LOGIN_PASS_REL=""
[ -n "${v}" ] || return 0
if [ -z "${LOGIN_PASS_DIR}" ] || [ ! -d "${LOGIN_PASS_DIR}" ]; then
( umask 077; mkdir -p "${REPO_DIR}/.hugmesh-secrets" ) || return 1
LOGIN_PASS_DIR="$(umask 077; mktemp -d "${REPO_DIR}/.hugmesh-secrets/login.XXXXXX")" || { LOGIN_PASS_DIR=""; return 1; }
fi
( umask 077; printf '%s' "${v}" > "${LOGIN_PASS_DIR}/local-pass" ) || return 1
LOGIN_PASS_REL=".hugmesh-secrets/${LOGIN_PASS_DIR##*/}/local-pass"
}
# _arm_standalone_flags — compose STANDALONE_FLAGS for the 9 ARM single-role
# targets (rpi-%/frite/jetson-%/orangepi5/orangepizero2/orangepizero2w/
# orangepizero3/orangepi3-lts/orangepi4-lts): folds the masked
# ARM_LOCAL_PASS/ARM_LUKS_PASS secrets in FIRST (each shell-quoted via
# _shell_quote — see there for why), then the freeform "Extra builder flags"
# field LAST so it can still override — mirrors the x86 `bf` string's own
# ordering (STANDALONE_FLAGS block above).
_arm_standalone_flags() {
local bf=""
[ -n "${ARM_LOCAL_PASS}" ] && [ -n "${LOGIN_PASS_REL}" ] && bf+=" --local-pass-file ${LOGIN_PASS_REL}"
[ -n "${ARM_LUKS_PASS}" ] && bf+=" --luks-pass $(_shell_quote "${ARM_LUKS_PASS}")"
# The Desktop options (desktop_screen), before the escape hatch so it can override.
[ -n "${DESKTOP_FLAGS}" ] && bf+=" ${DESKTOP_FLAGS}"
[ -n "${OPT_EXTRA_FLAGS}" ] && bf+=" ${OPT_EXTRA_FLAGS}"
printf '%s' "${bf# }"
}
# ── Desktop step (the Studio's, shared) ─────────────────────────────────────────
# The Desktop options (environment, Steam, window managers and compositors, default
# session, GPU driver, VIDEO_CARDS, login account, extra accounts, apps native or
# Flatpak, Flatpak remotes, Python, portage overlay, the emerge --pretend check) are
# the Studio's Desktop step, read from ONE model: studio/hugmesh_studio/core/
# desktop_spec.py through core/desktop_menu.py (Qt-free, stdlib only), the way
# local_mesh_screen runs core.local_mesh. So this menu offers the same options, greys
# the same ones with the same reasons (Steam/i3/VIDEO_CARDS on an ARM board, ...) and
# emits the same builder flags as the GUI, the text UI and the CLI; nothing about them
# is re-typed here. studio/tests/test_desktop_option_parity.py drives every option
# through this menu too.
#
# The choices live per make target in ${STATE_DIR}/desktop/<target>.json (no secret).
# The extra accounts' first-login passwords are typed masked into DESK_PASSES (memory
# only, never menu.conf) and reach the builder as a 0600 NAME:PASSWORD file beside the
# login password (_stage_desk_passes), never on argv.
DESK_STATE_DIR="${STATE_DIR}/desktop"
declare -A DESK_PASSES=()
DESK_LOCAL_PASS="" # x86 laptop/chromebook/desktop login password (masked, never saved)
DESKTOP_FLAGS=""; DESKTOP_BLOCK=""; DESK_PASS_REL=""
# _desk_target TARGET — is TARGET one the Desktop step knows (a desktop image)?
_desk_target() {
case "$1" in
x86-standalone-thin|x86-standalone-thick|x86-standalone-unaffiliated|x86-laptop|x86-chromebook|x86-desktop) return 0 ;;
rpi-desktop|jetson-desktop|frite|orangepi5|orangepi4-lts) return 0 ;;
esac
return 1
}
_desk_state() { printf '%s/%s.json' "${DESK_STATE_DIR}" "$1"; }
# _desk_unavailable — prints why the Desktop options cannot run here (rc 0), or
# nothing (rc 1) when they can.
_desk_unavailable() {
if ! command -v python3 >/dev/null 2>&1; then
printf '%s' "python3 is required for the Desktop options (they share the Studio's model, studio/hugmesh_studio/core/desktop_spec.py). Install python3, or use 'Extra builder flags'."
return 0
fi
if ! PYTHONPATH="${REPO_DIR}/studio" python3 -c 'import hugmesh_studio.core.desktop_menu' >/dev/null 2>&1; then
printf '%s' "python3 cannot import hugmesh_studio.core.desktop_menu from ${REPO_DIR}/studio, so the Desktop options cannot be read here. Use 'Extra builder flags'."
return 0
fi
return 1
}
# _desk TARGET CMD ARGS... — run the shared model for TARGET. The fields the x86
# standalone screen already owns (GPU driver, Steam, login user) are handed in, and
# left out of its flags, so each flag has ONE owner.
_desk() {
local target="$1"; shift
local -a o=()
case "${target}" in
x86-standalone*) o+=(--owned gpu,steam,user --gpu "${OPT_SA_GPU}" --steam "${OPT_SA_STEAM}" --user "${OPT_SA_USER}") ;;
frite) o+=(--frite-desktop "${OPT_FRITE_DESKTOP}") ;;
esac
case " ${OPT_EXTRA_FLAGS} " in *" --standalone "*) o+=(--standalone) ;; esac
mkdir -p "${DESK_STATE_DIR}" 2>/dev/null || true
( cd "${REPO_DIR}" && PYTHONPATH="${REPO_DIR}/studio" python3 -m hugmesh_studio.core.desktop_menu \
"${target}" "$(_desk_state "${target}")" "$@" "${o[@]}" )
}
# _desk_set TARGET TAG VALUE... — change one option; on a refusal say why (inline in
# the next screen's prompt via DESK_SAID) and return 1.
DESK_SAID=""
_desk_set() {
local target="$1" out rc
out="$(_desk "$@" 2>&1)"; rc=$?
DESK_SAID="${out}"
[ "${rc}" -eq 0 ]
}
# _stage_desk_passes — write the extra accounts' first-login passwords (DESK_PASSES)
# as NAME:PASSWORD lines into a 0600 file in the login-password dir (0700, under the
# checkout so the docker leg sees it at the same relative path). Parent shell only.
_stage_desk_passes() {
DESK_PASS_REL=""
[ "${#DESK_PASSES[@]}" -gt 0 ] || return 0
if [ -z "${LOGIN_PASS_DIR}" ] || [ ! -d "${LOGIN_PASS_DIR}" ]; then
( umask 077; mkdir -p "${REPO_DIR}/.hugmesh-secrets" ) || return 1
LOGIN_PASS_DIR="$(umask 077; mktemp -d "${REPO_DIR}/.hugmesh-secrets/login.XXXXXX")" || { LOGIN_PASS_DIR=""; return 1; }
fi
local n
( umask 077; for n in "${!DESK_PASSES[@]}"; do printf '%s:%s\n' "${n}" "${DESK_PASSES[${n}]}"; done \
> "${LOGIN_PASS_DIR}/extra-local-pass" ) || return 1
DESK_PASS_REL=".hugmesh-secrets/${LOGIN_PASS_DIR##*/}/extra-local-pass"
}
# _desktop_compose TARGET — DESKTOP_FLAGS (the Desktop step's builder flags, one
# shell-quoted string) or DESKTOP_BLOCK (why the build must not start). Nothing runs,
# and nothing changes on the make command line, until the Desktop options were opened
# and changed for TARGET (its state file exists).
_desktop_compose() {
local target="$1" errf out rc
DESKTOP_FLAGS=""; DESKTOP_BLOCK=""
_desk_target "${target}" || return 0
[ -f "$(_desk_state "${target}")" ] || return 0
if DESKTOP_BLOCK="$(_desk_unavailable)"; then
DESKTOP_BLOCK="Desktop options are saved for ${target}, but ${DESKTOP_BLOCK}"
return 0
fi
DESKTOP_BLOCK=""
_stage_desk_passes || { DESKTOP_BLOCK="could not stage the extra accounts' passwords"; return 0; }
errf="$(mktemp "${STATE_DIR}/desk-err.XXXXXX")"
out="$(_desk "${target}" flags --pass-file "${DESK_PASS_REL}" 2>"${errf}")"; rc=$?
if [ "${rc}" -ne 0 ]; then
DESKTOP_BLOCK="$(cat "${errf}")"
[ -n "${DESKTOP_BLOCK}" ] || DESKTOP_BLOCK="the Desktop options could not be read (rc ${rc})"
else
DESKTOP_FLAGS="${out}"
fi
rm -f "${errf}"
# --packages-add is read last-wins by every builder: one in 'Extra builder flags'
# would silently drop the native apps picked here.
case " ${DESKTOP_FLAGS} " in *" --packages-add "*)
case " ${OPT_EXTRA_FLAGS} " in *" --packages-add "*)
DESKTOP_BLOCK="'Extra builder flags' carries --packages-add too, and the builder keeps only the LAST one, so the native apps picked in the Desktop options would be dropped. Move those atoms into the Desktop options (Apps, native -> add by hand), or drop the native apps there." ;;
esac ;;
esac
return 0
}
# desktop_label TARGET — one line for the menu item that opens the Desktop options.
desktop_label() {
local why
if why="$(_desk_unavailable)"; then printf 'Desktop options .... (unavailable: python3)'; return 0; fi
if [ -f "$(_desk_state "$1")" ]; then printf 'Desktop options .... (changed; window managers, apps, accounts, Python, overlay)'
else printf 'Desktop options .... (defaults; window managers, apps, accounts, Python, overlay)'; fi
}
# desktop_screen TARGET LABEL — the Desktop step for one make target.
desktop_screen() {
local target="$1" label="$2" why rows probs choice tag st lbl text
if why="$(_desk_unavailable)"; then ui_msg "Desktop options" "${why}"; return 0; fi
DESK_SAID=""
while :; do
rows="$(_desk "${target}" rows 2>&1)" || { ui_msg "Desktop options" "${rows}"; return 0; }
probs="$(_desk "${target}" problems 2>/dev/null)"
local -a items=()
while IFS=$'\t' read -r tag st lbl text; do
[ -n "${tag}" ] || continue
case "${st}" in
live) items+=("${tag}" "${lbl} ..... ${text}") ;;
info) items+=("${tag}" "${lbl} ..... (information)") ;;
*) items+=("${tag}" "${lbl} ..... (not on this image: select for why)") ;;
esac
done <<< "${rows}"
items+=(done "‹ done")
local prompt="Desktop options for ${label}: the Studio's Desktop step (same options, rules and builder flags)."
[ -n "${DESK_SAID}" ] && prompt+=$'\n'"Last change: ${DESK_SAID}"
[ -n "${probs}" ] && prompt+=$'\n'"${probs}"
choice="$(ui_menu "Desktop — ${label}" "${prompt}" "${items[@]}")" || return 0
DESK_SAID=""
[ "${choice}" = done ] && return 0
st="$(printf '%s\n' "${rows}" | awk -F'\t' -v t="${choice}" '$1 == t { print $2; exit }')"
text="$(printf '%s\n' "${rows}" | awk -F'\t' -v t="${choice}" '$1 == t { print $4; exit }')"
lbl="$(printf '%s\n' "${rows}" | awk -F'\t' -v t="${choice}" '$1 == t { print $3; exit }')"
case "${st}" in
live) _desk_edit "${target}" "${choice}" "${lbl}" ;;
*) ui_msg "${lbl}" "${text}" ;;
esac
done
}
# _desk_choices TARGET TAG — the TAG's choices (VALUE\tLABEL\tSTATE\tREASON lines,
# without the kind line).
_desk_choices() { _desk "$1" choices "$2" 2>/dev/null | tail -n +2; }
# _desk_pick_list TARGET TAG TITLE PROMPT — a checklist over TAG's choices; greyed
# choices are listed in the prompt with their reason, never offered. Prints the pick.
_desk_pick_list() {
local target="$1" tag="$2" title="$3" prompt="$4" v l s r
local -a items=()
while IFS=$'\t' read -r v l s r; do
[ -n "${v}" ] || continue
case "${s}" in
grey) prompt+=$'\n'"Not here: ${l}: ${r}" ;;
*) items+=("${v}" "${l}" "${s}") ;;
esac
done <<< "$(_desk_choices "${target}" "${tag}")"
[ "${#items[@]}" -gt 0 ] || { ui_msg "${title}" "${prompt}"; return 1; }
ui_checklist "${title}" "${prompt}" "${items[@]}"
}
# _desk_pick_one TARGET TAG TITLE PROMPT — a menu over TAG's choices. Prints the pick.
_desk_pick_one() {
local target="$1" tag="$2" title="$3" prompt="$4" v l s r
local -a items=()
while IFS=$'\t' read -r v l s r; do
[ -n "${v}" ] || continue
[ "${s}" = grey ] && { prompt+=$'\n'"Not here: ${l}: ${r}"; continue; }
items+=("${v}" "${l}$([ "${s}" = on ] && echo ' (current)')")
done <<< "$(_desk_choices "${target}" "${tag}")"
[ "${#items[@]}" -gt 0 ] || return 1
ui_menu "${title}" "${prompt}" "${items[@]}"
}
# _desk_edit TARGET TAG LABEL — change one live option.
_desk_edit() {
local target="$1" tag="$2" lbl="$3" kind v sub name pw
kind="$(_desk "${target}" choices "${tag}" 2>/dev/null | head -n 1)"
case "${kind}" in
menu)
v="$(_desk_pick_one "${target}" "${tag}" "${lbl}" "${lbl}:")" || return 0
_desk_set "${target}" set "${tag}" "${v}" || return 0
# The x86 standalone screen owns these two: keep its value in step.
case "${target}:${tag}" in
x86-standalone*:gpu_driver) OPT_SA_GPU="${v}" ;;
x86-standalone*:steam) OPT_SA_STEAM="${v}" ;;
esac ;;
checklist)
v="$(_desk_pick_list "${target}" "${tag}" "${lbl}" "${lbl} (tick what this image carries):")" || return 0
_desk_set "${target}" set "${tag}" ${v} ;;
apps)
sub="$(ui_menu "${lbl}" "${lbl}:" pick "Pick from the catalog" add "Add one by hand ($([ "${tag}" = apps_native ] && echo 'category/name atom' || echo 'REMOTE:app.id'))" rm "Remove one added by hand" back "‹ back")" || return 0
case "${sub}" in
pick) v="$(_desk_pick_list "${target}" "${tag}" "${lbl}" "${lbl}: an app picked here leaves the other delivery.")" || return 0
_desk_set "${target}" set "${tag}" ${v} ;;
add) v="$(ui_input "${lbl}" "$([ "${tag}" = apps_native ] && echo 'Atom (category/name)' || echo 'REMOTE:app.id (e.g. flathub:org.gimp.GIMP)')" "")"
[ -n "${v}" ] && _desk_set "${target}" set "${tag}" add "${v}" ;;
rm) v="$(_desk_pick_one "${target}" "${tag}" "${lbl}" "Remove which?")" || return 0
_desk_set "${target}" set "${tag}" rm "${v}" ;;
esac ;;
python)
sub="$(ui_menu "${lbl}" "Python targets only ever WIDEN the stage3 seed's set:" extra "Extra PYTHON_TARGETS" single "PYTHON_SINGLE_TARGET" back "‹ back")" || return 0
case "${sub}" in
extra) v="$(_desk_pick_list "${target}" python "${lbl}" "Extra PYTHON_TARGETS:")" || return 0
_desk_set "${target}" set python ${v} ;;
single) v="$(ui_menu "${lbl}" "PYTHON_SINGLE_TARGET:" - "the seed's own" python3_12 python3_12 python3_13 python3_13 python3_14 python3_14 python3_15 python3_15)" || return 0
_desk_set "${target}" set python single "${v}" ;;
esac ;;
lines)
sub="$(ui_menu "${lbl}" "${lbl}:" add "Add NAME=https://…flatpakrepo" rm "Remove one" back "‹ back")" || return 0
case "${sub}" in
add) v="$(ui_input "${lbl}" "NAME=https://URL.flatpakrepo" "")"; [ -n "${v}" ] && _desk_set "${target}" set "${tag}" add "${v}" ;;
rm) v="$(_desk_pick_one "${target}" "${tag}" "${lbl}" "Remove which?")" || return 0
_desk_set "${target}" set "${tag}" rm "${v}" ;;
esac ;;
overlay)
sub="$(ui_menu "${lbl}" "One line each; no wildcards, no video_cards_*/python_* flags, only this image's testing keyword:" use "Add a package.use line (ATOM FLAG ...)" kw "Add an accept_keywords line (ATOM ~ARCH)" rm "Remove a line" back "‹ back")" || return 0
case "${sub}" in
use|kw) v="$(ui_input "${lbl}" "$([ "${sub}" = use ] && echo 'package.use line' || echo 'accept_keywords line')" "")"
[ -n "${v}" ] && _desk_set "${target}" set overlay "${sub}" add "${v}" ;;
rm) local -a lines=(); local k l s r i=0
while IFS=$'\t' read -r k l s r; do [ -n "${k}" ] && { lines+=("${k}:${l#* }"); }; done <<< "$(_desk_choices "${target}" overlay)"
[ "${#lines[@]}" -gt 0 ] || return 0
local -a it=(); for i in "${!lines[@]}"; do it+=("${i}" "${lines[${i}]}"); done
v="$(ui_menu "${lbl}" "Remove which line?" "${it[@]}")" || return 0
k="${lines[${v}]%%:*}"; l="${lines[${v}]#*:}"
_desk_set "${target}" set overlay "${k}" rm "${l}" ;;
esac ;;
users)
sub="$(ui_menu "${lbl}" "Extra local accounts: NOT administrators unless you say so; each must choose a new password at first login. Passwords are typed masked and never saved." add "Add an account" pass "Type an account's first-login password again" rm "Remove an account" back "‹ back")" || return 0
case "${sub}" in
add) name="$(ui_input "${lbl}" "Login name (lowercase letters, digits, _ and -)" "")"; [ -n "${name}" ] || return 0
local adm=noadmin; ui_yesno "${lbl}" "Make ${name} an administrator (sudo)? Default: no." && adm=admin
pw="$(ui_password_confirmed "${lbl}" "First-login password for ${name} (hashed at build time, never saved)" "")"
_desk_set "${target}" set extra_users add "${name}" "${adm}" || return 0
[ -n "${pw}" ] && DESK_PASSES["${name}"]="${pw}" ;;
pass) name="$(_desk_pick_one "${target}" extra_users "${lbl}" "Which account?")" || return 0
pw="$(ui_password_confirmed "${lbl}" "First-login password for ${name}" "")"
[ -n "${pw}" ] && DESK_PASSES["${name}"]="${pw}" ;;
rm) name="$(_desk_pick_one "${target}" extra_users "${lbl}" "Remove which?")" || return 0
_desk_set "${target}" set extra_users rm "${name}" && unset 'DESK_PASSES[$name]' ;;
esac
pw="" ;;
account)
local cur; cur="$(_desk_choices "${target}" primary_account | awk -F'\t' '$1 == "name" { print $2 }')"
case "${target}" in x86-standalone*) cur="${OPT_SA_USER}" ;; esac
name="$(ui_input "${lbl}" "Login account name (the desktop greeter's local login)" "${cur}")"; [ -n "${name}" ] || return 0
local adm=noadmin; ui_yesno "${lbl}" "Make ${name} an administrator (sudo)? Default: no." && adm=admin
_desk_set "${target}" set primary_account "${name}" "${adm}" || return 0
case "${target}" in
x86-standalone*) OPT_SA_USER="${name}" ;;
x86-laptop|x86-chromebook|x86-desktop)
DESK_LOCAL_PASS="$(ui_password_confirmed "${lbl}" "Login password for ${name} (blank = keep the KEYS/SSO default; hashed at build time, never saved)" "${DESK_LOCAL_PASS}")" ;;
esac ;;
action)
sub="$(ui_menu "${lbl}" "Runs the builder's own emerge --pretend for this configuration in its container (minutes; one check or build at a time on this machine). Nothing is built or installed." check "Check" apply "Check, and record portage's own suggested lines in the overlay" back "‹ back")" || return 0
[ "${sub}" = back ] && return 0
local -a pa=(pretend --generator-dir "${REPO_DIR}"); [ "${sub}" = apply ] && pa+=(--apply)
local res; res="$(_desk "${target}" "${pa[@]}" 2>&1)"
ui_msg "${lbl}" "${res}" ;;
*) ui_msg "${lbl}" "Nothing to choose here." ;;
esac
return 0
}
# desktop_prebuild TARGET LABEL — the last stop before a desktop target builds: open
# the Desktop options, build, or go back. rc 0 = build.