Repository navigation
Expand file tree
/
Copy pathinstall_linux.sh
More file actions
executable file
·10019 lines (9564 loc) · 407 KB
/
Copy pathinstall_linux.sh
File metadata and controls
executable file
·10019 lines (9564 loc) · 407 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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status, and let a
# failure anywhere in a pipeline fail the whole pipeline.
set -e
set -o pipefail
# --help / --version must work anywhere (docs, packaging, CI); everything
# else needs a Termux environment.
if [ -z "$PREFIX" ]; then
case "${1:-}" in
-h|--help|-V|--version) ;;
*)
echo "Error: This script must be run inside Termux."
exit 1
;;
esac
fi
# Directory containing this script (lib/ lives next to it).
LFA_DIR="$(cd "$(dirname "$0")" && pwd)"
LFA_VERSION="1.7.1"
LFA_RUNTIME="$PREFIX/lib/linux-for-android"
LFA_PREFS="$HOME/.config/linux-for-android/preferences.conf"
LFA_CLI_MODE="${LFA_CLI_MODE:-0}"
LFA_ASSUME_YES="${LFA_ASSUME_YES:-0}"
CLI_INSTANCE="${CLI_INSTANCE:-}"
# ------------------------------------------------------------
# Interrupt safety and temporary artifacts.
# The guest setup script carries the install passwords (obfuscated) and is
# staged in $PREFIX/tmp, which every distro shares as /tmp. Track everything
# written there and remove it on every exit path, including Ctrl-C and a
# failed install (a stray copy used to survive forever).
# ------------------------------------------------------------
LFA_TMP_ARTIFACTS=()
lfa_track_tmp() { LFA_TMP_ARTIFACTS+=("$1"); }
lfa_cleanup() {
[ "${LFA_KEEP_SETUP_SCRIPT:-0}" = "1" ] && return 0
local _f
for _f in ${LFA_TMP_ARTIFACTS[@]+"${LFA_TMP_ARTIFACTS[@]}"}; do
rm -f "$_f" 2>/dev/null || true
done
}
trap lfa_cleanup EXIT INT TERM
# ============================================================
# Interactive UI (npm-style)
# Arrow keys / Enter / space work on a real terminal. When
# stdin is piped (CI, `curl | bash`, tests) the installer falls back to
# plain numbered prompts so automation keeps working.
# ============================================================
UI_TTY=0
if [ -t 0 ] && [ -t 1 ]; then UI_TTY=1; fi
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-dumb}" != "dumb" ]; then
C_RESET=$'\033[0m'; C_BOLD=$'\033[1m'; C_DIM=$'\033[2m'
C_RED=$'\033[31m'; C_GREEN=$'\033[32m'; C_YELLOW=$'\033[33m'
C_BLUE=$'\033[34m'; C_MAGENTA=$'\033[35m'; C_CYAN=$'\033[36m'
C_WHITE=$'\033[97m'; C_GRAY=$'\033[90m'
C_BGREEN=$'\033[1;32m'; C_BCYAN=$'\033[1;36m'; C_BRED=$'\033[1;31m'
else
C_RESET=""; C_BOLD=""; C_DIM=""
C_RED=""; C_GREEN=""; C_YELLOW=""; C_BLUE=""; C_MAGENTA=""
C_CYAN=""; C_WHITE=""; C_GRAY=""; C_BGREEN=""; C_BCYAN=""; C_BRED=""
fi
export C_RESET C_BOLD C_DIM C_RED C_GREEN C_YELLOW C_BLUE C_MAGENTA \
C_CYAN C_WHITE C_GRAY C_BGREEN C_BCYAN C_BRED
ui_clear() {
if [ "$UI_TTY" = "1" ]; then printf '\033[2J\033[H'; fi
}
ui_rule() {
printf '%s──────────────────────────────────────────────%s\n' "$C_GRAY" "$C_RESET"
}
ui_banner() {
printf '\n %sLinux for Android%s %s· installer · v%s%s\n' \
"$C_BCYAN" "$C_RESET" "$C_DIM" "$LFA_VERSION" "$C_RESET"
ui_rule
}
# Success, warning and error notices also go to Android through Termux:API.
# The helper is defined later in the file; the guard keeps early calls safe.
ui_ok() {
printf ' %s✓%s %s\n' "$C_BGREEN" "$C_RESET" "$*"
command -v lfa_notify_android >/dev/null 2>&1 && \
lfa_notify_android "Linux for Android" "$*" "lfa-ok" || true
}
ui_warn() {
printf ' %s!%s %s\n' "$C_YELLOW" "$C_RESET" "$*"
command -v lfa_notify_android >/dev/null 2>&1 && \
lfa_notify_android "Linux for Android warning" "$*" "lfa-warn" || true
}
ui_err() {
printf ' %s✗%s %s\n' "$C_BRED" "$C_RESET" "$*"
command -v lfa_notify_android >/dev/null 2>&1 && \
lfa_notify_android "Linux for Android error" "$*" "lfa-error" || true
}
# ui_select <title> <default-key> <key|label|description>...
# Result: UI_SELECTED (the key). Returns 1 on 'q' (back/abort).
ui_select() {
local _title="$1" _def="$2"; shift 2
local -a _items=("$@")
local _n=$# _i=0 _sel=0 _picked=0 _k _l _d _ans _key _typed=""
local _note="${UI_NOTE:-}"
UI_NOTE=""
for _i in "${!_items[@]}"; do
[ "${_items[$_i]%%|*}" = "$_def" ] && _sel=$_i
done
if [ "$UI_TTY" != "1" ]; then
ui_banner
printf '\n %s%s%s\n' "$C_BOLD" "$_title" "$C_RESET"
[ -n "$_note" ] && printf ' %s%s%s\n' "$C_GRAY" "$_note" "$C_RESET"
printf '\n'
for _i in "${!_items[@]}"; do
IFS='|' read -r _k _l _d <<< "${_items[$_i]}"
printf ' %s) %s' "$_k" "$_l"
[ -n "$_d" ] && printf ' (%s)' "$_d"
printf '\n'
done
while :; do
printf 'Select (default %s): ' "$_def"
if ! IFS= read -r _ans; then
printf '\n'
return 1
fi
[ -z "$_ans" ] && _ans="$_def"
for _i in "${!_items[@]}"; do
IFS='|' read -r _k _l _d <<< "${_items[$_i]}"
if [ "$_k" = "$_ans" ]; then UI_SELECTED="$_k"; return 0; fi
done
echo "Invalid choice"
done
fi
while :; do
ui_clear
ui_banner
printf '\n %s%s%s\n' "$C_BOLD$C_WHITE" "$_title" "$C_RESET"
[ -n "$_note" ] && printf ' %s%s%s\n' "$C_GRAY" "$_note" "$C_RESET"
printf '\n'
for _i in "${!_items[@]}"; do
IFS='|' read -r _k _l _d <<< "${_items[$_i]}"
if [ "$_i" -eq "$_sel" ]; then
printf ' %s❯ %s)%s %s%s%s\n' "$C_BCYAN" "$_k" "$C_RESET" "$C_BOLD" "$_l" "$C_RESET"
[ -n "$_d" ] && printf ' %s%s%s\n' "$C_GRAY" "$_d" "$C_RESET"
else
printf ' %s%s)%s %s%s%s\n' "$C_GRAY" "$_k" "$C_RESET" "$C_DIM" "$_l" "$C_RESET"
[ -n "$_d" ] && printf ' %s%s%s\n' "$C_GRAY" "$_d" "$C_RESET"
fi
done
printf '\n %s↑/↓ move · Enter select · q back%s' "$C_DIM" "$C_RESET"
[ -n "$_typed" ] && printf ' %s[%s]%s' "$C_CYAN" "$_typed" "$C_RESET"
printf '\n'
IFS= read -rsn1 _key || true
case "$_key" in
"") break ;;
q|Q) return 1 ;;
$'\033')
_typed=""
IFS= read -rsn2 -t 0.05 _key || true
case "$_key" in
'[A'|'OA') _sel=$((_sel-1)) ;;
'[B'|'OB') _sel=$((_sel+1)) ;;
esac
[ "$_sel" -lt 0 ] && _sel=$((_n-1))
[ "$_sel" -ge "$_n" ] && _sel=0
;;
[0-9])
# Type "10" and press Enter. A single digit only moves the
# highlight (no surprise selection before Enter).
_typed="${_typed}${_key}"
_picked=0
for _i in "${!_items[@]}"; do
if [ "${_items[$_i]%%|*}" = "$_typed" ]; then _sel=$_i; _picked=1; break; fi
done
if [ "$_picked" != "1" ] && [ "${#_typed}" -gt 1 ]; then
_typed="$_key"
for _i in "${!_items[@]}"; do
if [ "${_items[$_i]%%|*}" = "$_typed" ]; then _sel=$_i; break; fi
done
fi
;;
esac
done
IFS='|' read -r _k _l _d <<< "${_items[$_sel]}"
UI_SELECTED="$_k"
return 0
}
# ui_confirm <question> <y|n default>. Returns 0 for yes, 1 for no.
ui_confirm() {
local _q="$1" _def="$2" _ans _sel _i _key
local _keep="${UI_NO_CLEAR:-0}"
UI_NO_CLEAR=0
if [ "$LFA_ASSUME_YES" = "1" ]; then
printf '%s [yes]\n' "$_q"
return 0
fi
if [ "$UI_TTY" != "1" ]; then
local _hint='y/N'
[ "$_def" = "y" ] && _hint='Y/n'
while :; do
printf '%s [%s]: ' "$_q" "$_hint"
if ! IFS= read -r _ans; then
printf '\n'
return 1
fi
_ans="${_ans:-$_def}"
case "$_ans" in
[Yy]|1|yes|YES) return 0 ;;
[Nn]|2|no|NO) return 1 ;;
*) echo "Invalid choice" ;;
esac
done
fi
_sel=0
[ "$_def" = "n" ] && _sel=1
while :; do
if [ "$_keep" != "1" ]; then
ui_clear
ui_banner
fi
printf '\n %s%s%s\n\n' "$C_BOLD$C_WHITE" "$_q" "$C_RESET"
for _i in 0 1; do
if [ "$_i" -eq "$_sel" ]; then
[ "$_i" = 0 ] && printf ' %s❯ Yes%s\n' "$C_BCYAN" "$C_RESET" || printf ' %s❯ No%s\n' "$C_BCYAN" "$C_RESET"
else
[ "$_i" = 0 ] && printf ' %sYes%s\n' "$C_DIM" "$C_RESET" || printf ' %sNo%s\n' "$C_DIM" "$C_RESET"
fi
done
printf '\n %s←/→ or ↑/↓ choose · Enter confirm · y/n shortcut%s\n' "$C_DIM" "$C_RESET"
IFS= read -rsn1 _key || true
case "$_key" in
"") break ;;
y|Y) _sel=0; break ;;
n|N) _sel=1; break ;;
$'\033')
IFS= read -rsn2 -t 0.05 _key || true
case "$_key" in
'[A'|'OA'|'[D'|'OD') _sel=0 ;;
'[B'|'OB'|'[C'|'OC') _sel=1 ;;
esac
;;
esac
done
[ "$_sel" = "0" ]
}
# ui_multi <title> <key|label|description>...
# Result: UI_MULTI (space-separated selected keys; empty = none).
ui_multi() {
local _title="$1"; shift
local -a _items=("$@") _chosen=()
local _n=$# _i=0 _sel=0 _k _l _d _ans _bad _key _mark _c _picked
if [ "$UI_TTY" != "1" ]; then
printf '\n%s\n' "$_title"
for _i in "${!_items[@]}"; do
IFS='|' read -r _k _l _d <<< "${_items[$_i]}"
printf ' %s) %s' "$_k" "$_l"
[ -n "$_d" ] && printf ' (%s)' "$_d"
printf '\n'
done
while :; do
printf 'Selection (numbers separated by spaces, Enter to skip): '
if ! IFS= read -r _ans; then
printf '\n'
return 1
fi
_ans="$(echo "${_ans:-}" | xargs)"
if [ -z "$_ans" ]; then UI_MULTI=""; return 0; fi
if echo "$_ans" | grep -Eq '^[0-9 ]+$'; then
_bad=""
for _c in $_ans; do
if ! { [ "$_c" -ge 1 ] 2>/dev/null && [ "$_c" -le 14 ] 2>/dev/null; }; then
_bad="$_bad $_c"
fi
done
if [ -z "$_bad" ]; then UI_MULTI="$_ans"; return 0; fi
echo "Invalid numbers:$_bad — use 1-14 separated by spaces."
else
echo "Use numbers 1-14 separated by spaces (or Enter to skip)."
fi
done
fi
while :; do
ui_clear
ui_banner
printf '\n %s%s%s\n\n' "$C_BOLD$C_WHITE" "$_title" "$C_RESET"
for _i in "${!_items[@]}"; do
IFS='|' read -r _k _l _d <<< "${_items[$_i]}"
_mark=" "
case " ${_chosen[*]} " in *" $_k "*) _mark="x" ;; esac
if [ "$_i" -eq "$_sel" ]; then
printf ' %s❯ [%s] %s) %s%s%s\n' "$C_BCYAN" "$_mark" "$_k" "$C_BOLD" "$_l" "$C_RESET"
[ -n "$_d" ] && printf ' %s%s%s\n' "$C_GRAY" "$_d" "$C_RESET"
else
printf ' %s[%s]%s %s%s)%s %s%s%s\n' "$C_GREEN" "$_mark" "$C_RESET" "$C_GRAY" "$_k" "$C_RESET" "$C_DIM" "$_l" "$C_RESET"
fi
done
printf '\n %s↑/↓ move · space toggle · a all · n none · Enter done%s\n' "$C_DIM" "$C_RESET"
_picked=0
IFS= read -rsn1 _key || true
case "$_key" in
"") break ;;
q|Q) return 1 ;;
' ')
IFS='|' read -r _k _l _d <<< "${_items[$_sel]}"
case " ${_chosen[*]} " in
*" $_k "*)
local -a _next=()
for _c in "${_chosen[@]}"; do [ "$_c" != "$_k" ] && _next+=("$_c"); done
_chosen=("${_next[@]}")
;;
*) _chosen+=("$_k") ;;
esac
;;
a|A)
_chosen=()
for _i in "${!_items[@]}"; do _chosen+=("${_items[$_i]%%|*}"); done
;;
n|N) _chosen=() ;;
$'\033')
IFS= read -rsn2 -t 0.05 _key || true
case "$_key" in
'[A'|'OA') _sel=$((_sel-1)) ;;
'[B'|'OB') _sel=$((_sel+1)) ;;
esac
[ "$_sel" -lt 0 ] && _sel=$((_n-1))
[ "$_sel" -ge "$_n" ] && _sel=0
;;
esac
done
UI_MULTI="${_chosen[*]}"
return 0
}
LFA_NONINTERACTIVE="${LFA_NONINTERACTIVE:-0}"
ui_pause() {
[ "$LFA_NONINTERACTIVE" = "1" ] && return 0
printf '\n %sPress Enter to continue...%s' "$C_DIM" "$C_RESET"
IFS= read -r _ || true
}
# ============================================================
# Universal Android compatibility layer (Android 5 -> 15)
# Oppo A37fw (Android 5.1.1, SDK 22, 32-bit ARM) has a frozen
# Termux repo where 'proot-distro' / 'virglrenderer-android'
# do not exist as packages. Detect legacy devices and fall
# back gracefully instead of aborting (set -e).
# ============================================================
detect_environment() {
ANDROID_SDK=0
if command -v getprop >/dev/null 2>&1; then
ANDROID_SDK=$(getprop ro.build.version.sdk 2>/dev/null || echo 0)
fi
# Strip anything non-numeric (some ROMs return extra text)
ANDROID_SDK=$(echo "$ANDROID_SDK" | tr -cd '0-9')
if [ -z "$ANDROID_SDK" ]; then ANDROID_SDK=0; fi
ARCH=$(uname -m 2>/dev/null || echo unknown)
IS_LEGACY=0
# Termux current builds require Android 7+ (SDK 24).
# Anything below that uses archived repos with missing packages.
if [ "$ANDROID_SDK" -gt 0 ] && [ "$ANDROID_SDK" -lt 24 ]; then
IS_LEGACY=1
fi
# Termux:X11 and GNOME need Android 8 (SDK 26). That is a different
# cutoff from the legacy Termux repo cutoff above: Android 7.0/7.1
# (SDK 24/25) use modern Termux packages but still cannot run X11.
X11_SUPPORTED=0
if [ "$ANDROID_SDK" = "0" ] || [ "$ANDROID_SDK" -ge 26 ]; then
X11_SUPPORTED=1
fi
# Non-Android shells (PC debugging) report SDK 0 -> treat as modern
# so script syntax can still be tested, but say so instead of silently
# behaving differently.
if [ "$ANDROID_SDK" = "0" ] && [ "${LFA_SDK_WARNED:-0}" != "1" ]; then
echo "[!] Could not read the Android version (getprop unavailable)."
echo " Legacy-device handling is disabled for this run."
LFA_SDK_WARNED=1
fi
IS_32BIT_ARM=0
case "$ARCH" in
armv7*|armv6*|armhf|arm)
IS_32BIT_ARM=1
;;
esac
}
print_device_info() {
detect_environment
echo "[*] Device detected: arch=$ARCH | android_sdk=$ANDROID_SDK | legacy=$IS_LEGACY"
if [ "$IS_LEGACY" = "1" ]; then
echo "----------------------------------------------------------------"
echo " LEGACY MODE: Android 5/6 detected (SDK $ANDROID_SDK)."
echo " - Termux:X11 and VirGL GPU acceleration are NOT available."
echo " VNC (software rendering) will be used automatically."
echo " - 'proot-distro' package may be missing. The script will"
echo " try to install it from source (pure bash + proot)."
echo " - STRONGLY recommended: Alpine Linux (musl, option 8)."
echo " glibc distros (Ubuntu/Debian/Fedora/...) fail on the"
echo " 3.10 kernel at the first guest command (verified)."
echo " 32-bit ARM note: Alpine/Ubuntu/Debian/Kali have arm builds;"
echo " Fedora / openSUSE / Void / Arch may lack 32-bit images."
echo "----------------------------------------------------------------"
elif [ "$X11_SUPPORTED" != "1" ]; then
echo "----------------------------------------------------------------"
echo " X11 UNAVAILABLE: Android 7.0/7.1 detected (SDK $ANDROID_SDK)."
echo " - Termux packages are modern, so the normal install path is used."
echo " - Termux:X11 and GNOME require Android 8 (SDK 26) or newer."
echo " VNC (software rendering) will be used automatically."
echo "----------------------------------------------------------------"
fi
}
# Install proot-distro from GitHub when 'pkg install proot-distro'
# fails (typical on Android 5.1.1 archived repos).
# Install proot-distro v4.2.0 from source — the LAST shell-based release.
# Upstream HEAD (v5+) is a Python rewrite needing modern Python/pip plus
# Docker-registry installs, unsuitable for Android 5/6. v4.2.0 is pure
# bash + proot, supports --override-alias and all classic rootfs tarballs.
# Its install.sh also performs the @TERMUX_PREFIX@ substitution that a
# naive 'cp proot-distro.sh' would skip (which yields a broken install
# whose 'list' is empty and every install fails with "unknown distribution").
PD_LEGACY_TAG="v4.2.0"
install_proot_distro_from_source() {
echo "[*] Installing proot-distro $PD_LEGACY_TAG from source (legacy fallback)..."
# set +e: every step here is best-effort, checked manually
set +e
pkg install -y proot wget tar 2>/dev/null || true
if ! command -v proot >/dev/null 2>&1; then
echo "ERROR: 'proot' itself could not be installed."
echo "Your Termux repo seems unreachable. Try:"
echo " 1) Use F-Droid Termux 0.118 (last build with Android 5 support)"
echo " 2) Run 'termux-change-repo' and pick a working mirror"
echo " 3) Then re-run this script."
set -e
return 1
fi
mkdir -p "$PREFIX/tmp"
SRC_DIR="$PREFIX/tmp/proot-distro-4.2.0-src"
rm -rf "$SRC_DIR"
if command -v git >/dev/null 2>&1; then
git clone --depth 1 --branch "$PD_LEGACY_TAG" https://github.com/termux/proot-distro "$SRC_DIR" 2>/dev/null || rm -rf "$SRC_DIR"
fi
# Fallback if git missing/failed: fetch the pinned tag tarball via wget
if [ ! -f "$SRC_DIR/install.sh" ]; then
rm -rf "$SRC_DIR"
mkdir -p "$SRC_DIR"
if wget -qO "$PREFIX/tmp/pd-4.2.0.tar.gz" "https://github.com/termux/proot-distro/archive/refs/tags/${PD_LEGACY_TAG}.tar.gz" 2>/dev/null; then
tar -xzf "$PREFIX/tmp/pd-4.2.0.tar.gz" -C "$PREFIX/tmp" 2>/dev/null || true
cp -r "$PREFIX/tmp"/proot-distro-4.2.0/* "$SRC_DIR"/ 2>/dev/null || true
fi
fi
# No published checksum exists for GitHub tag archives (they are not
# byte-stable), so validate the tree instead of trusting the download.
if [ -f "$SRC_DIR/proot-distro.sh" ] && ! grep -q "$PD_LEGACY_TAG\|4\.2\.0" "$SRC_DIR/proot-distro.sh" 2>/dev/null; then
echo "[!] proot-distro source does not look like $PD_LEGACY_TAG; refusing to install it."
rm -rf "$SRC_DIR"
fi
if [ -f "$SRC_DIR/install.sh" ]; then
# install.sh respects TERMUX_PREFIX/TERMUX_ANDROID_HOME from env,
# so this also works on Termux forks with non-standard paths.
( cd "$SRC_DIR" && TERMUX_PREFIX="$PREFIX" TERMUX_ANDROID_HOME="$HOME" bash install.sh ) 2>/dev/null || \
( cd "$SRC_DIR" && TERMUX_PREFIX="$PREFIX" TERMUX_ANDROID_HOME="$HOME" bash install.sh )
mkdir -p "$PREFIX/var/lib/proot-distro/installed-rootfs" "$PREFIX/var/lib/proot-distro/dl-cache"
hash -r 2>/dev/null || true
if command -v proot-distro >/dev/null 2>&1; then
echo "[*] proot-distro $PD_LEGACY_TAG installed to $PREFIX/bin/proot-distro"
set -e
return 0
fi
fi
echo "ERROR: Could not fetch proot-distro $PD_LEGACY_TAG sources (no network?)."
set -e
return 1
}
# `producer | grep -q` is unsafe with `set -o pipefail`: grep exits at the
# first match, the producer dies with SIGPIPE (141), and the pipeline is
# reported as failed even though the match succeeded. This helper keeps the
# text in a variable and uses bash's own regex engine instead.
lfa_match() { # $1 text, $2 extended regex (case-insensitive)
local _t="$1" _p="$2" _rc
shopt -s nocasematch
[[ "$_t" =~ $_p ]]; _rc=$?
shopt -u nocasematch
return $_rc
}
# Verify the installed proot-distro actually knows distro $1.
# Frozen Android 5 repos ship a pre---override-alias proot-distro build
# whose plugin dir can be empty -> every install fails with
# "unknown distribution 'debian'". Repair from pinned sources then.
# On modern devices the pkg build is authoritative: never overwrite it,
# just show 'proot-distro list' and stop.
verify_proot_distro_plugin() {
WANT="$1"
# proot-distro v5+ installs OCI images directly. Its `list` command only
# shows created containers, not available distro plugins, so checking it
# would reject every not-yet-installed image (e.g. alpine:latest).
if command -v proot-distro >/dev/null 2>&1 && \
lfa_match "$(proot-distro install --help 2>&1)" '(IMAGE:TAG|Docker image|registry)'; then
return 0
fi
# NOTE: proot-distro prints EVERYTHING (including 'list' results)
# to stderr via msg(), so capture 2>&1 here, not 2>/dev/null.
set +e
if command -v proot-distro >/dev/null 2>&1 && \
lfa_match "$(proot-distro list 2>&1)" "(^|[^[:alnum:]_])$WANT([^[:alnum:]_]|$)"; then
set -e
return 0
fi
if [ "$IS_LEGACY" != "1" ]; then
echo "ERROR: your proot-distro knows no '$WANT' distribution."
echo "Available distributions:"
proot-distro list 2>&1 || true
set -e
return 1
fi
echo "[!] proot-distro has no '$WANT' plugin (stale pre-$PD_LEGACY_TAG pkg build?). Repairing from $PD_LEGACY_TAG sources..."
install_proot_distro_from_source || { set -e; return 1; }
if lfa_match "$(proot-distro list 2>&1)" "(^|[^[:alnum:]_])$WANT([^[:alnum:]_]|$)"; then
set -e
return 0
fi
echo "ERROR: '$WANT' still unknown after repair. Supported names:"
proot-distro list 2>&1 || true
set -e
return 1
}
# Resilient dependency installer. Never aborts the whole script
# on one missing optional package (old behavior with 'set -e' did).
ensure_dependencies() {
NEED_X11="$1" # "1" if user chose Termux:X11, else "0"
set +e # do NOT exit on single pkg failure here
echo "[*] Updating Termux packages (best effort)..."
pkg update -y 2>/dev/null || true
# NOTE: 'pkg upgrade' on EOL Android 5 repos can break things;
# run it but never abort on failure.
pkg upgrade -y 2>/dev/null || true
echo "[*] Installing core dependencies (proot, wget, curl, pulseaudio)..."
# NOTE: v4.2.0 proot-distro downloads rootfs with 'curl' (not wget)
# and needs coreutils/findutils/gawk tools, so install them explicitly:
# a bare Termux bootstrap on old Android may miss some.
pkg install -y proot wget curl pulseaudio 2>/dev/null || true
pkg install -y coreutils findutils gawk 2>/dev/null || true
# 'proot-distro' may not exist on SDK 22 repos -> source fallback
if ! command -v proot-distro >/dev/null 2>&1; then
pkg install -y proot-distro 2>/dev/null || true
fi
if ! command -v proot-distro >/dev/null 2>&1; then
install_proot_distro_from_source || {
echo "FATAL: proot-distro unavailable. Cannot continue."
set -e
exit 1
}
fi
# virglrenderer-android = optional GPU accel, Android 7+ only.
# Missing on Android 5 -> silently skip, VNC will be used.
# NEED_VIRGL (from guided setup) can disable it on modern devices too.
if [ "$IS_LEGACY" = "1" ]; then
echo "[*] Skipping virglrenderer-android (not available on Android 5/6)."
elif [ "${NEED_VIRGL:-1}" = "1" ]; then
echo "[*] Installing VirGL (optional, for GPU acceleration)..."
pkg install -y virglrenderer-android 2>/dev/null || echo "[!] virglrenderer-android unavailable, continuing without GPU acceleration."
else
echo "[*] VirGL disabled by setup choice."
fi
if [ "$NEED_X11" = "1" ]; then
if ! x11_supported; then
echo "[!] Termux:X11 requires Android 8+ (SDK 26). Cannot install on this device."
else
echo "[*] Installing Termux:X11 backend..."
pkg install -y x11-repo 2>/dev/null || true
pkg install -y termux-x11-nightly 2>/dev/null || echo "[!] termux-x11-nightly install failed. Use VNC instead."
fi
fi
set -e
}
# login flags for proot-distro: v4 login passes --sysvipc by default,
# but the frozen Android 5 proot (5.1.x) has no such option, so EVERY
# login dies with "unknown option '--sysvipc'". Opt out when needed.
# Detection is file-based (no execution), safe on modern builds too:
# v5+ pkg builds keep working untouched.
pd_login_flags() {
if command -v proot >/dev/null 2>&1 && ! lfa_match "$(proot --help 2>&1)" 'sysvipc'; then
if [ -f "$PREFIX/bin/proot-distro" ] && grep -q "no-sysvipc" "$PREFIX/bin/proot-distro" 2>/dev/null; then
echo "--no-sysvipc"
fi
fi
}
# v4 shell builds (legacy fallback) vs v5 Python builds have different
# backup/restore CLI: v4 'restore' takes a tarball PATH and restores the
# embedded instance name; only v5 understands '--input <file>' + rename.
pd_is_v4() {
# v4.2 source builds keep the legacy plugin layout; v5+ installs OCI
# images and restores from a single archive argument (`restore FILE`).
[ -f "$PREFIX/bin/proot-distro" ] || return 1
grep -q "DISTRO_PLUGINS_DIR" "$PREFIX/bin/proot-distro" 2>/dev/null && return 0
lfa_match "$(proot-distro restore --help 2>&1)" 'BACKUP_FILE'
}
# Legacy devices need the bullseye plug-in (shipped in ./plugins), which
# neither the frozen pkg build nor a clean v4.2.0 source install provides.
deploy_legacy_plugins() {
[ "$IS_LEGACY" = "1" ] || return 0
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
if [ -f "$SCRIPT_DIR/plugins/bullseye.sh" ]; then
mkdir -p "$PREFIX/etc/proot-distro"
cp "$SCRIPT_DIR/plugins/bullseye.sh" "$PREFIX/etc/proot-distro/bullseye.sh"
chmod 600 "$PREFIX/etc/proot-distro/bullseye.sh" 2>/dev/null || true
else
echo "[!] Warning: plugins/bullseye.sh not found next to the script;"
echo " legacy Debian installs will fail. Re-clone the repository."
fi
}
# ============================================================
# Desktop / display-server questions.
# Guided setup and the install wizard used to carry two copies of these
# menus; adding GNOME meant editing both. One implementation now.
# ============================================================
ask_desktop_environment() { # $1 = suggestion label, $2 = default index
local _suggest="${1:-XFCE4}" _def="${2:-1}"
local -a _items=(
"1|XFCE4|light, familiar, great on phones"
"2|LXDE|ultra light, minimal"
"3|MATE|classic GNOME 2 feel"
"4|None (CLI only)|terminal only - lightest and fastest"
)
gnome_available && _items+=("5|GNOME (experimental)|BETA - may crash; read the warning")
ui_select "Choose Desktop Environment (suggested: $_suggest)" "$_def" "${_items[@]}" || return 1
case "$UI_SELECTED" in
1) DE="xfce4" ;;
2) DE="lxde" ;;
3) DE="mate" ;;
4) DE="none" ;;
5) DE="gnome" ;;
esac
if [ "$DE" = "gnome" ] && ! gnome_experimental_warning; then
echo "[*] Falling back to XFCE4."
DE="xfce4"
fi
return 0
}
ask_display_server() { # $1 = default index (1=x11, 2=vnc)
local _def="${1:-1}"
ui_select "Choose Display Server" "$_def" \
"1|Termux:X11|hardware acceleration, faster, smoother" \
"2|VNC|software rendering, works everywhere, slower" \
"3|Both|install both; choose one each time you start" || return 1
case "$UI_SELECTED" in
1) SERVER="x11" ;;
2) SERVER="vnc" ;;
3) SERVER="both" ;;
esac
if [ "$DE" = "gnome" ] && { [ "$SERVER" = "x11" ] || [ "$SERVER" = "both" ]; }; then
echo "[!] GNOME over Termux:X11 is known to crash the app often."
echo " VNC is more stable for GNOME - Both keeps VNC available too."
fi
return 0
}
# Termux:X11 requires Android 8 (SDK 26). Keep this separate from
# IS_LEGACY, which describes the Termux package/repo cutoff (SDK 24).
x11_supported() {
[ "${X11_SUPPORTED:-0}" = "1" ]
}
# Both backends share one config value. These helpers keep the package,
# password, launcher and verification paths from drifting when "both" is set.
server_has_x11() {
case "${SERVER:-none}" in x11|both) return 0 ;; esac
return 1
}
server_has_vnc() {
case "${SERVER:-none}" in vnc|both) return 0 ;; esac
return 1
}
# Guest binaries are often absolute symlinks (vncserver -> /etc/alternatives/
# vncserver). Checking them from the host follows the link into the host's
# /etc and reports a false "missing package"; accept the link itself.
guest_has_path() {
[ -e "$1" ] || [ -L "$1" ]
}
# ============================================================
# Guided setup questionnaire (integrated first screen).
# Asks everything up front, saves answers to setup.conf for unattended
# re-runs, then hands off to install_linux() with SETUP_ANSWERED=1 so no
# question is asked twice. Passwords are base64-encoded (obfuscation, not
# encryption) in a mode-0600 file; treat that file as a secret.
# ============================================================
SETUP_CONF="$HOME/.config/linux-for-android/setup.conf"
# Wallpaper mode: light (default) or dark. Guided setup asks for GUI
# installs; CLI-only installs keep the default and skip wallpaper setup.
COLOR_MODE="light"
# Which backend Termux:Boot should start when "both" is installed. Empty
# means "not chosen yet"; the installer fills it before writing the script.
AUTOSTART_SERVER=""
b64enc() {
printf '%s' "$1" | base64 2>/dev/null | tr -d '\n'
}
setup_read_secret() {
# $1 = var name to fill, $2 = prompt, $3 = default (used on empty)
local __prompt="$2" __dflt="$3" __val=""
if [ -t 0 ]; then
printf '%s' "$__prompt" >&2
IFS= read -rs __val || true
printf '\n' >&2
else
IFS= read -r __val || true
fi
[ -z "$__val" ] && __val="$__dflt"
printf -v "$1" '%s' "$__val"
}
setup_confirm_secret() {
# Like setup_read_secret, but asks twice on a real terminal. There is no
# password-reset path inside the guest, so a typo is unrecoverable.
# When stdin is piped (tests/CI) it asks once, as before.
local __var="$1" __prompt="$2" __dflt="$3" __a="" __b=""
if [ ! -t 0 ]; then
setup_read_secret "$__var" "$__prompt" "$__dflt"
return 0
fi
while true; do
setup_read_secret __a "$__prompt" "$__dflt"
setup_read_secret __b " Repeat to confirm: " "$__a"
[ "$__a" = "$__b" ] && break
echo "[!] Passwords do not match, try again."
done
printf -v "$__var" '%s' "$__a"
}
setup_guess_timezone() {
local _tz=""
_tz=$(getprop persist.sys.timezone 2>/dev/null || true)
case "$_tz" in
""|*[!A-Za-z0-9_+./-]*|*..*|/*|*/) _tz="UTC" ;;
esac
printf '%s' "${_tz:-UTC}"
}
# Rough free-space requirement (MB) for an install of this shape.
setup_required_mb() {
if [ "${DE:-none}" = "gnome" ]; then
printf '3500'
elif [ "${DE:-none}" != "none" ]; then
printf '2500'
else
printf '900'
fi
}
# shellcheck disable=SC2120 # $1 is optional (defaults to $PREFIX)
lfa_free_mb() {
local _path="${1:-$PREFIX}" _kb _blocks _bsize _human _val
# GNU/BusyBox df: 1024-byte blocks in column 4.
_kb=$(df -Pk "$_path" 2>/dev/null | awk 'NR==2 {print $4}')
case "$_kb" in ''|*[!0-9]*) _kb="" ;; esac
if [ -n "$_kb" ]; then printf '%s' $((_kb / 1024)); return 0; fi
# Android 5 toybox df ignores -Pk and prints human units (3.6G). Prefer
# stat -f, which gives exact blocks, then fall back to the human value.
_blocks=$(stat -f "$_path" 2>/dev/null | awk '/Available:/ {print $2}')
_bsize=$(stat -f "$_path" 2>/dev/null | sed -n 's/.*Fundamental block size:[[:space:]]*\([0-9][0-9]*\).*/\1/p')
case "${_blocks}${_bsize}" in
''|*[!0-9]*) ;;
*) printf '%s' $((_blocks * _bsize / 1024 / 1024)); return 0 ;;
esac
_human=$(df "$_path" 2>/dev/null | awk 'NR==2 {print $4}')
_val="${_human%[GgMmTt]}"
case "$_human" in
*[Gg]) printf '%s' "$(awk -v v="$_val" 'BEGIN {printf "%d", v * 1024}')" ;;
*[Mm]) printf '%s' "$(awk -v v="$_val" 'BEGIN {printf "%d", v}')" ;;
*[Tt]) printf '%s' "$(awk -v v="$_val" 'BEGIN {printf "%d", v * 1024 * 1024}')" ;;
*) printf '%s' "$_human" ;;
esac
}
# Refuse to start a multi-gigabyte install on a nearly full device: it would
# die halfway through apt and leave a half-configured rootfs behind.
lfa_check_disk_space() {
local _need _have
_need="$(setup_required_mb)"
_have="$(lfa_free_mb)"
case "$_have" in ''|*[!0-9]*) return 0 ;; esac
if [ "$_have" -lt "$_need" ]; then
echo ""
echo "[!] Not enough free space: this install needs about ${_need} MB,"
echo " and only ${_have} MB is free on the Termux filesystem."
echo " Remove another distro or clear Downloads, then re-run."
return 1
fi
echo "[*] Free space check: ${_have} MB available, ${_need} MB needed."
return 0
}
setup_ram_mb() {
local _m=""
_m=$(free -m 2>/dev/null | awk '/^Mem:/ {print $2}')
case "$_m" in
''|*[!0-9]*) _m=2048 ;;
esac
printf '%s' "$_m"
}
# ============================================================
# GNOME (experimental / beta)
# ============================================================
# gnome-session cannot work under proot: there is no systemd user session and
# no logind seat, so it hands gnome-shell an "Oh no! Something has gone
# wrong" screen. The community workaround is to skip gnome-session entirely
# and run `gnome-shell --x11` directly inside a D-Bus session. That produces a
# real GNOME Shell desktop, but the session services normally started by
# gnome-session never run, so parts of the desktop are missing or unstable.
gnome_distro_supported() {
case "${DISTRO:-}" in
ubuntu|debian|kali|archlinux|fedora|opensuse) return 0 ;;
*) return 1 ;;
esac
}
gnome_available() {
x11_supported || return 1
gnome_distro_supported
}
gnome_experimental_warning() {
echo ""
echo "${C_YELLOW}${C_BOLD}================================================================${C_RESET}"
echo "${C_YELLOW}${C_BOLD} GNOME - EXPERIMENTAL / BETA - READ THIS FIRST${C_RESET}"
echo "${C_YELLOW}${C_BOLD}================================================================${C_RESET}"
echo ""
echo " This is a real GNOME Shell (40+), not GNOME Flashback. It is NOT a"
echo " supported desktop and it will misbehave. Install it only to try it."
echo ""
echo "${C_BOLD} How it works${C_RESET}"
echo " A normal GNOME session starts gnome-session, which needs systemd and"
echo " logind. Neither exists inside proot. So this option skips"
echo " gnome-session completely and launches 'gnome-shell --x11' directly"
echo " in a D-Bus session."
echo ""
echo "${C_BOLD} What will be missing or broken${C_RESET}"
echo " - Login/logout menu, session saving and session restore"
echo " - Screen locking, idle blanking, suspend/inhibit"
echo " - Some panel/dock entries and the app grid at first login"
echo " - GNOME Settings (gnome-control-center) may crash, especially the"
echo " Sound panel. The usual 'fix' wipes ~/.cache ~/.config ~/.local,"
echo " which also wipes your settings."
echo " - Portals, auto-mount, polkit prompts, UPower/brightness, and"
echo " notifications are partial or absent"
echo " - Extensions that need root or Android files do not work"
echo " - Touch input often only works in mouse mode"
echo " - Video playback is roughly 1-7 FPS (software rendering)"
echo " - Termux:X11 crashes the session often; VNC is more stable, so"
echo " VNC is pre-selected here"
echo " - A package upgrade that updates systemd/gdm can break the session."
echo " If that happens, run menu 0 (Doctor) and start it again."
echo ""
echo "${C_BOLD} Requirements${C_RESET}"
echo " - Android 8+ (no Android 5/6, no Alpine, no Void)"
echo " - 3 GB RAM minimum, 4 GB+ recommended (it is heavy)"
echo " - about 2.5-3 GB of free storage"
echo ""
echo "${C_YELLOW} Bug reports for this desktop are accepted as experimental only.${C_RESET}"
echo ""
if ! ui_confirm "I understand this is experimental and may crash - continue with GNOME?" n; then
echo ""
echo "[*] GNOME cancelled."
return 1
fi
echo ""
echo "[*] GNOME selected (experimental). VNC is recommended; you can still"
echo " choose Termux:X11 in the next step, but it is less stable."
return 0
}
setup_save() {
mkdir -p "$(dirname "$SETUP_CONF")"
cat > "$SETUP_CONF" <<EOF
# Linux-for-Android setup answers (reused on re-install, chmod 600).
# Passwords are base64-encoded (reversible) - the file mode is what protects
# them, so keep it 0600 and never copy it around.
DISTRO="$DISTRO"
DE="$DE"
SERVER="$SERVER"
RESOLUTION="$RESOLUTION"
COLOR_MODE="$COLOR_MODE"
APP_CHOICES="$APP_CHOICES"
INSTANCE_NAME="$INSTANCE_NAME"
SETUP_USER="$SETUP_USER"
SETUP_USER_B64="$SETUP_USER_B64"
SETUP_ROOT_B64="$SETUP_ROOT_B64"
TIMEZONE="$TIMEZONE"
HOSTNAME="$HOSTNAME"
PSTYLE="$PSTYLE"
NEED_VIRGL="$NEED_VIRGL"
AUTOSTART_SERVER="$AUTOSTART_SERVER"
DO_AUTOSTART="$DO_AUTOSTART"
DO_STORAGE="$DO_STORAGE"
DO_SSH="$DO_SSH"
DO_WIDGET="$DO_WIDGET"
EOF
chmod 600 "$SETUP_CONF" 2>/dev/null || true
echo "[*] Answers saved to $SETUP_CONF (reused automatically next time)."
}
setup_summary() {
printf '\n %sSetup Summary%s\n' "$C_BOLD$C_WHITE" "$C_RESET"
ui_rule
printf ' %s%-13s%s %s\n' "$C_GRAY" "Distribution" "$C_RESET" "$DISTRO"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Desktop" "$C_RESET" "$DE"
[ "$DE" != "none" ] && printf ' %s%-13s%s %s\n' "$C_GRAY" "Wallpaper" "$C_RESET" "$COLOR_MODE"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Server" "$C_RESET" "$SERVER"
server_has_vnc && printf ' %s%-13s%s %s\n' "$C_GRAY" "Resolution" "$C_RESET" "$RESOLUTION"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Software" "$C_RESET" "${APP_CHOICES:-none}"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Instance" "$C_RESET" "${INSTANCE_NAME:-(auto)}"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Username" "$C_RESET" "$SETUP_USER"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Password" "$C_RESET" "****"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Root passwd" "$C_RESET" "****"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Timezone" "$C_RESET" "$TIMEZONE"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Hostname" "$C_RESET" "$HOSTNAME"
printf ' %s%-13s%s %s\n' "$C_GRAY" "HW accel" "$C_RESET" "$([ "$NEED_VIRGL" = "1" ] && echo on || echo off)"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Prompt style" "$C_RESET" "$PSTYLE"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Autostart" "$C_RESET" "$([ "$DO_AUTOSTART" = "1" ] && echo "yes (${AUTOSTART_SERVER:-$SERVER})" || echo no)"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Storage perm" "$C_RESET" "$([ "$DO_STORAGE" = "1" ] && echo yes || echo no)"
printf ' %s%-13s%s %s\n' "$C_GRAY" "SSH server" "$C_RESET" "$([ "$DO_SSH" = "1" ] && echo yes || echo no)"
printf ' %s%-13s%s %s\n' "$C_GRAY" "Widget hint" "$C_RESET" "$([ "$DO_WIDGET" = "1" ] && echo yes || echo no)"
ui_rule
}
setup_quick() {
echo "[*] Quick setup: taking every default."
if [ "$IS_LEGACY" = "1" ]; then DISTRO="alpine"; else DISTRO="debian"; fi
if [ "$IS_LEGACY" = "1" ] || [ "$(setup_ram_mb)" -le 2048 ]; then DE="none"; else DE="xfce4"; fi
if [ "$DE" = "none" ]; then SERVER="none"; elif ! x11_supported; then SERVER="vnc"; else SERVER="x11"; fi
RESOLUTION="1280x720"
COLOR_MODE="light"
APP_CHOICES=""
INSTANCE_NAME=""
SETUP_USER="user"
SETUP_USER_B64="$(b64enc root)"
SETUP_ROOT_B64="$(b64enc root)"
TIMEZONE="$(setup_guess_timezone)"
HOSTNAME="localhost"
PSTYLE="minimal"
if [ "$IS_LEGACY" = "1" ]; then NEED_VIRGL=0; else NEED_VIRGL=1; fi
AUTOSTART_SERVER="$SERVER"
DO_AUTOSTART=0
DO_STORAGE=1
DO_SSH=0
DO_WIDGET=0
SETUP_ANSWERED=1
setup_summary
setup_save
install_linux
}
setup_guided() {
echo ""
echo "========================================="
echo " Guided Setup (Enter = default) "
echo "========================================="
# 1. Distro
local _dd _ddef
if [ "$IS_LEGACY" = "1" ]; then _dd="Alpine"; _ddef=8; else _dd="Debian"; _ddef=2; fi
while true; do
if ! ui_select "Choose Linux Distribution (recommended here: $_dd)" "$_ddef" \
"1|Ubuntu|24.04 LTS · APT · widest app support" \
"2|Debian|stable · APT · rock solid" \
"3|Kali Linux|APT · security tools" \
"4|Fedora|DNF · bleeding edge" \
"5|OpenSUSE|Zypper · enterprise" \
"6|Void Linux|XBPS · lightweight, rolling" \
"7|Arch Linux|Pacman · rolling (may be unstable on ARM64)" \
"8|Alpine Linux|APK · musl · best for Android 5/6 + low RAM"; then
show_menu