-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced.func
More file actions
1287 lines (1202 loc) · 60.7 KB
/
Copy pathadvanced.func
File metadata and controls
1287 lines (1202 loc) · 60.7 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
# Copyright (c) 2021-2026 community-scripts ORG
# License: MIT | https://raw.githubusercontent.com/community-scripts/core/main/LICENSE
# ==============================================================================
# BUILD-UI/ADVANCED.FUNC - ADVANCED INTERACTIVE CONFIGURATION
# ==============================================================================
# Part of the build UI. Load ui/build-ui.func -- it sources every part --
# rather than this file directly; the split is for maintenance only and no
# function name or behaviour changed with it.
# ==============================================================================
[[ -n "${_BUILD_UI_ADVANCED_LOADED:-}" ]] && return 0
_BUILD_UI_ADVANCED_LOADED=1
# ==============================================================================
# SECTION 6: ADVANCED INTERACTIVE CONFIGURATION
# ==============================================================================
# ------------------------------------------------------------------------------
# advanced_settings()
#
# - Interactive wizard-style configuration with BACK navigation
# - State-machine approach: each step can go forward or backward
# - Cancel at Step 1 = Exit Script, Cancel at other steps = Go Back
# - Allows user to customize all container settings
# ------------------------------------------------------------------------------
advanced_settings() {
# Enter alternate screen buffer to prevent flicker between dialogs
tput smcup 2>/dev/null || true
trap 'tput rmcup 2>/dev/null || true' RETURN
# Initialize defaults
if [[ "${var_tags:-}" == *community-script* ]]; then
TAGS="${var_tags:-community-script}"
else
TAGS="community-script${var_tags:+;${var_tags}}"
fi
local STEP=1
local MAX_STEP=31
# Store values for back navigation - inherit from var_* app defaults
local _ct_type="${var_unprivileged:-1}"
local _pw=""
local _pw_display="Automatic Login"
local _ct_id="$NEXTID"
local _hostname="$NSAPP"
local _disk_size="${var_disk:-4}"
local _core_count="${var_cpu:-1}"
local _ram_size="${var_ram:-1024}"
local _bridge="${var_brg:-vmbr0}"
local _sdn_vnet="${var_sdn_vnet:-}"
local _net="${var_net:-dhcp}"
local _gate="${var_gateway:-}"
local _ipv6_method="${var_ipv6_method:-auto}"
local _ipv6_addr=""
local _ipv6_gate=""
local _apt_cacher="${var_apt_cacher:-no}"
local _apt_cacher_ip="${var_apt_cacher_ip:-}"
local _http_proxy="${HTTP_PROXY:-${var_http_proxy:-}}"
local _http_no_proxy="${HTTP_NO_PROXY:-${var_http_no_proxy:-}}"
local _inherit_host_ca="${INHERIT_HOST_CA:-${var_inherit_host_ca:-no}}"
local _mtu="${var_mtu:-}"
local _sd="${var_searchdomain:-}"
local _ns="${var_ns:-}"
local _mac="${var_mac:-}"
local _vlan="${var_vlan:-}"
local _tags="$TAGS"
local _enable_fuse="${var_fuse:-no}"
local _enable_tun="${var_tun:-no}"
local _enable_gpu="${var_gpu:-no}"
local _enable_nesting="${var_nesting:-1}"
local _verbose="${var_verbose:-no}"
local _enable_keyctl="${var_keyctl:-0}"
local _enable_mknod="${var_mknod:-0}"
local _mount_fs="${var_mount_fs:-}"
local _protect_ct="${var_protection:-no}"
local _post_install="${var_post_install:-}"
# Detect host timezone for default (if not set via var_timezone)
local _host_timezone=""
if command -v timedatectl >/dev/null 2>&1; then
_host_timezone=$(timedatectl show --value --property=Timezone 2>/dev/null || echo "")
elif [ -f /etc/timezone ]; then
_host_timezone=$(cat /etc/timezone 2>/dev/null || echo "")
fi
# Map Etc/* timezones to "host" (pct doesn't accept Etc/* zones)
[[ "${_host_timezone:-}" == Etc/* ]] && _host_timezone="host"
local _ct_timezone="${var_timezone:-$_host_timezone}"
[[ "${_ct_timezone:-}" == Etc/* ]] && _ct_timezone="host"
# Helper to show current progress
show_progress() {
local current=$1
local total=$MAX_STEP
echo -e "\n${INFO}${BOLD}${DGN}Step $current of $total${CL}"
}
# Detect available bridges (do this once)
local BRIDGES=""
local BRIDGE_MENU_OPTIONS=()
if declare -f populate_advanced_bridge_menu &>/dev/null; then
populate_advanced_bridge_menu
else
_detect_bridges() {
IFACE_FILEPATH_LIST="/etc/network/interfaces"$'\n'$(find "/etc/network/interfaces.d/" -type f 2>/dev/null)
BRIDGES=""
local OLD_IFS=$IFS
IFS=$'\n'
for iface_filepath in ${IFACE_FILEPATH_LIST}; do
local iface_indexes_tmpfile=$(mktemp -q -u '.iface-XXXX')
(grep -Pn '^\s*iface' "${iface_filepath}" 2>/dev/null | cut -d':' -f1 && wc -l "${iface_filepath}" 2>/dev/null | cut -d' ' -f1) | awk 'FNR==1 {line=$0; next} {print line":"$0-1; line=$0}' >"${iface_indexes_tmpfile}" 2>/dev/null || true
if [ -f "${iface_indexes_tmpfile}" ]; then
while read -r pair; do
local start=$(echo "${pair}" | cut -d':' -f1)
local end=$(echo "${pair}" | cut -d':' -f2)
if awk "NR >= ${start} && NR <= ${end}" "${iface_filepath}" 2>/dev/null | grep -qP '^\s*(bridge[-_](ports|stp|fd|vlan-aware|vids)|ovs_type\s+OVSBridge)\b'; then
local iface_name=$(sed "${start}q;d" "${iface_filepath}" | awk '{print $2}')
BRIDGES="${iface_name}"$'\n'"${BRIDGES}"
fi
done <"${iface_indexes_tmpfile}"
rm -f "${iface_indexes_tmpfile}"
fi
done
IFS=$OLD_IFS
BRIDGES=$(echo "$BRIDGES" | grep -v '^\s*$' | sort | uniq)
# Build bridge menu
BRIDGE_MENU_OPTIONS=()
if [[ -n "$BRIDGES" ]]; then
while IFS= read -r bridge; do
if [[ -n "$bridge" ]]; then
local description=$(grep -A 10 "iface $bridge" /etc/network/interfaces 2>/dev/null | grep '^#' | head -n1 | sed 's/^#\s*//')
BRIDGE_MENU_OPTIONS+=("$bridge" "${description:- }")
fi
done <<<"$BRIDGES"
fi
if [[ -f /etc/pve/sdn/vnets.cfg ]]; then
while IFS= read -r vnet; do
[[ -n "$vnet" ]] && BRIDGE_MENU_OPTIONS+=("sdn:${vnet}" "[SDN] ${vnet}")
done < <(awk '/^vnet:/{print $2}' /etc/pve/sdn/vnets.cfg 2>/dev/null)
fi
}
_detect_bridges
fi
# Main wizard loop
while [ $STEP -le $MAX_STEP ]; do
case $STEP in
# ═══════════════════════════════════════════════════════════════════════════
# STEP 1: Container Type
# ═══════════════════════════════════════════════════════════════════════════
1)
local default_on="ON"
local default_off="OFF"
[[ "$_ct_type" == "0" ]] && {
default_on="OFF"
default_off="ON"
}
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "CONTAINER TYPE" \
--ok-button "Next" --cancel-button "Exit" \
--radiolist "\nChoose container type:\n\nUse SPACE to select, ENTER to confirm." 14 58 2 \
"1" "Unprivileged (recommended)" $default_on \
"0" "Privileged" $default_off \
3>&1 1>&2 2>&3); then
[[ -n "$result" ]] && _ct_type="$result"
((STEP++))
else
exit_script
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 2: Root Password
# ═══════════════════════════════════════════════════════════════════════════
2)
if PW1=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "ROOT PASSWORD" \
--ok-button "Next" --cancel-button "Back" \
--passwordbox "\nSet Root Password (needed for root ssh access)\n\nLeave blank for automatic login (no password)" 12 58 \
3>&1 1>&2 2>&3); then
if [[ -z "$PW1" ]]; then
_pw=""
_pw_display="Automatic Login"
((STEP++))
elif [[ "$PW1" == *" "* ]]; then
whiptail --msgbox "Password cannot contain spaces." 8 58
else
local _pw1_clean="$PW1"
while [[ "$_pw1_clean" == -* ]]; do
_pw1_clean="${_pw1_clean#-}"
done
if [[ -z "$_pw1_clean" ]]; then
whiptail --msgbox "Password cannot be only '-' characters." 8 58
continue
elif ((${#_pw1_clean} < 5)); then
whiptail --msgbox "Password must be at least 5 characters (after removing leading '-')." 8 70
continue
fi
# Verify password
if PW2=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "PASSWORD VERIFICATION" \
--ok-button "Confirm" --cancel-button "Back" \
--passwordbox "\nVerify Root Password" 10 58 \
3>&1 1>&2 2>&3); then
local _pw2_clean="$PW2"
while [[ "$_pw2_clean" == -* ]]; do
_pw2_clean="${_pw2_clean#-}"
done
if [[ "$_pw1_clean" == "$_pw2_clean" ]]; then
_pw="--password $_pw1_clean"
_pw_display="********"
((STEP++))
else
whiptail --msgbox "Passwords do not match. Please try again." 8 58
fi
else
((STEP--))
fi
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 3: Container ID
# ═══════════════════════════════════════════════════════════════════════════
3)
local id_dialog_title="CONTAINER ID"
declare -f lxc_backend_uses_named_containers &>/dev/null && id_dialog_title="CONTAINER NAME"
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "$id_dialog_title" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet ${id_dialog_title}" 10 58 "$_ct_id" \
3>&1 1>&2 2>&3); then
local input_id="${result:-$NEXTID}"
# Validate that ID is numeric (Proxmox) unless backend uses names (Incus)
if ! declare -f lxc_backend_uses_named_containers &>/dev/null; then
if ! [[ "$input_id" =~ ^[0-9]+$ ]]; then
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Invalid ID" --msgbox "Container ID must be numeric." 8 58
continue
fi
fi
# Check if ID is already in use
if ! validate_container_id "$input_id"; then
if whiptail --backtitle "Proxmox VE Helper Scripts" --title "ID Already In Use" \
--yesno "Container/VM ID $input_id is already in use.\n\nWould you like to use the next available ID ($(get_valid_container_id "$input_id"))?" 10 58; then
_ct_id=$(get_valid_container_id "$input_id")
else
continue
fi
else
_ct_id="$input_id"
fi
((STEP++))
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 4: Hostname
# ═══════════════════════════════════════════════════════════════════════════
4)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "HOSTNAME" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet Hostname (or FQDN, e.g. host.example.com)" 10 58 "$_hostname" \
3>&1 1>&2 2>&3); then
local hn_test="${result:-$NSAPP}"
hn_test=$(echo "${hn_test,,}" | tr -d ' ')
if validate_hostname "$hn_test"; then
_hostname="$hn_test"
((STEP++))
else
whiptail --msgbox "Invalid hostname: '$hn_test'\n\nRules:\n- Only lowercase letters, digits, dots and hyphens\n- Labels separated by dots (max 63 chars each)\n- No leading/trailing hyphens or dots\n- No consecutive dots\n- Total max 253 characters" 14 60
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 5: Disk Size
# ═══════════════════════════════════════════════════════════════════════════
5)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "DISK SIZE" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet Disk Size in GB" 10 58 "$_disk_size" \
3>&1 1>&2 2>&3); then
local disk_test="${result:-$var_disk}"
if [[ "$disk_test" =~ ^[1-9][0-9]*$ ]]; then
_disk_size="$disk_test"
((STEP++))
else
whiptail --msgbox "Disk size must be a positive integer!" 8 58
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 6: CPU Cores
# ═══════════════════════════════════════════════════════════════════════════
6)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "CPU CORES" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nAllocate CPU Cores" 10 58 "$_core_count" \
3>&1 1>&2 2>&3); then
local cpu_test="${result:-$var_cpu}"
if [[ "$cpu_test" =~ ^[1-9][0-9]*$ ]]; then
_core_count="$cpu_test"
((STEP++))
else
whiptail --msgbox "CPU core count must be a positive integer!" 8 58
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 7: RAM Size
# ═══════════════════════════════════════════════════════════════════════════
7)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "RAM SIZE" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nAllocate RAM in MiB" 10 58 "$_ram_size" \
3>&1 1>&2 2>&3); then
local ram_test="${result:-$var_ram}"
if [[ "$ram_test" =~ ^[1-9][0-9]*$ ]]; then
_ram_size="$ram_test"
((STEP++))
else
whiptail --msgbox "RAM size must be a positive integer!" 8 58
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 8: Network Bridge
# ═══════════════════════════════════════════════════════════════════════════
8)
if [[ ${#BRIDGE_MENU_OPTIONS[@]} -eq 0 ]]; then
# Validate default bridge exists
if validate_bridge "vmbr0"; then
_bridge="vmbr0"
_sdn_vnet=""
((STEP++))
else
whiptail --msgbox "Default bridge 'vmbr0' not found!\n\nPlease configure a network bridge in Proxmox first." 10 58
msg_error "Default bridge 'vmbr0' not found"
exit 116
fi
else
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "NETWORK BRIDGE" \
--ok-button "Next" --cancel-button "Back" \
--menu "\nSelect network bridge:" 16 58 6 \
"${BRIDGE_MENU_OPTIONS[@]}" \
3>&1 1>&2 2>&3); then
local bridge_test="${result:-vmbr0}"
if [[ "$bridge_test" == "__other__" || "$bridge_test" == -* ]]; then
continue
fi
if [[ "$bridge_test" == sdn:* ]]; then
local vnet_test="${bridge_test#sdn:}"
if validate_sdn_vnet "$vnet_test"; then
_sdn_vnet="$vnet_test"
_bridge="${var_brg:-vmbr0}"
((STEP++))
else
whiptail --msgbox "SDN vnet '$vnet_test' is not configured on this cluster." 8 58
fi
elif validate_bridge "$bridge_test"; then
_bridge="$bridge_test"
_sdn_vnet=""
((STEP++))
else
whiptail --msgbox "Bridge '$bridge_test' is not available or not active." 8 58
fi
else
((STEP--))
fi
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 9: IPv4 Configuration
# ═══════════════════════════════════════════════════════════════════════════
9)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "IPv4 CONFIGURATION" \
--ok-button "Next" --cancel-button "Back" \
--menu "\nSelect IPv4 Address Assignment:" 16 65 3 \
"dhcp" "Automatic (DHCP, recommended)" \
"static" "Static (manual entry)" \
"range" "IP Range Scan (find first free IP)" \
3>&1 1>&2 2>&3); then
if [[ "$result" == "static" ]]; then
# Get static IP
local static_ip
if static_ip=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "STATIC IPv4 ADDRESS" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nEnter Static IPv4 CIDR Address\n(e.g. 192.168.1.100/24)" 12 58 "" \
3>&1 1>&2 2>&3); then
if validate_ip_address "$static_ip"; then
# Get gateway
local gateway_ip
if gateway_ip=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "GATEWAY IP" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nEnter Gateway IP address" 10 58 "" \
3>&1 1>&2 2>&3); then
if validate_gateway_ip "$gateway_ip"; then
# Validate gateway is in same subnet
if validate_gateway_in_subnet "$static_ip" "$gateway_ip"; then
_net="$static_ip"
_gate=",gw=$gateway_ip"
((STEP++))
else
whiptail --msgbox "Gateway is not in the same subnet as the static IP.\n\nStatic IP: $static_ip\nGateway: $gateway_ip" 10 58
fi
else
whiptail --msgbox "Invalid Gateway IP format.\n\nEach octet must be 0-255.\nExample: 192.168.1.1" 10 58
fi
fi
else
whiptail --msgbox "Invalid IPv4 CIDR format.\n\nEach octet must be 0-255.\nCIDR must be 1-32.\nExample: 192.168.1.100/24" 12 58
fi
fi
elif [[ "$result" == "range" ]]; then
# IP Range Scan
local ip_range
if ip_range=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "IP RANGE SCAN" \
--ok-button "Scan" --cancel-button "Back" \
--inputbox "\nEnter IP range to scan for free address\n(e.g. 192.168.1.100/24-192.168.1.200/24)" 12 65 "" \
3>&1 1>&2 2>&3); then
if is_ip_range "$ip_range"; then
# Exit whiptail screen temporarily to show scan progress
clear
header_info
echo -e "${INFO}${BOLD}${DGN}Scanning IP range for free address...${CL}\n"
if resolve_ip_from_range "$ip_range"; then
# Get gateway
local gateway_ip
if gateway_ip=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "GATEWAY IP" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nFound free IP: $NET_RESOLVED\n\nEnter Gateway IP address" 12 58 "" \
3>&1 1>&2 2>&3); then
if validate_gateway_ip "$gateway_ip"; then
# Validate gateway is in same subnet
if validate_gateway_in_subnet "$NET_RESOLVED" "$gateway_ip"; then
_net="$NET_RESOLVED"
_gate=",gw=$gateway_ip"
((STEP++))
else
whiptail --msgbox "Gateway is not in the same subnet as the IP.\n\nIP: $NET_RESOLVED\nGateway: $gateway_ip" 10 58
fi
else
whiptail --msgbox "Invalid Gateway IP format.\n\nEach octet must be 0-255.\nExample: 192.168.1.1" 10 58
fi
fi
else
whiptail --msgbox "No free IP found in the specified range.\nAll IPs responded to ping." 10 58
fi
else
whiptail --msgbox "Invalid IP range format.\n\nExample: 192.168.1.100/24-192.168.1.200/24" 10 58
fi
fi
else
_net="dhcp"
_gate=""
((STEP++))
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 10: IPv6 Configuration
# ═══════════════════════════════════════════════════════════════════════════
10)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "IPv6 CONFIGURATION" \
--ok-button "Next" --cancel-button "Back" \
--menu "\nSelect IPv6 Address Management:" 16 70 5 \
"auto" "SLAAC/AUTO (recommended) - Dynamic IPv6 from network" \
"dhcp" "DHCPv6 - DHCP-assigned IPv6 address" \
"static" "Static - Manual IPv6 address configuration" \
"none" "None - No IPv6 assignment (most containers)" \
"disable" "Fully Disabled - (breaks some services)" \
3>&1 1>&2 2>&3); then
_ipv6_method="$result"
case "$result" in
static)
local ipv6_addr
if ipv6_addr=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
--title "STATIC IPv6 ADDRESS" \
--inputbox "\nEnter IPv6 CIDR address\n(e.g. 2001:db8::1/64)" 12 58 "" \
3>&1 1>&2 2>&3); then
if validate_ipv6_address "$ipv6_addr"; then
_ipv6_addr="$ipv6_addr"
# Optional gateway - loop until valid or empty
local ipv6_gw_valid=false
while [[ "$ipv6_gw_valid" == "false" ]]; do
local ipv6_gw
ipv6_gw=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
--title "IPv6 GATEWAY" \
--inputbox "\nEnter IPv6 gateway (optional, leave blank for none)" 10 58 "" \
3>&1 1>&2 2>&3) || true
# Validate gateway if provided
if [[ -n "$ipv6_gw" ]]; then
if validate_ipv6_address "$ipv6_gw"; then
_ipv6_gate="$ipv6_gw"
ipv6_gw_valid=true
((STEP++))
else
whiptail --msgbox "Invalid IPv6 gateway format.\n\nExample: 2001:db8::1" 8 58
fi
else
_ipv6_gate=""
ipv6_gw_valid=true
((STEP++))
fi
done
else
whiptail --msgbox "Invalid IPv6 CIDR format.\n\nExample: 2001:db8::1/64\nCIDR must be 1-128." 10 58
fi
fi
;;
dhcp)
_ipv6_addr="dhcp"
_ipv6_gate=""
((STEP++))
;;
none)
_ipv6_addr="none"
_ipv6_gate=""
((STEP++))
;;
*)
_ipv6_addr=""
_ipv6_gate=""
((STEP++))
;;
esac
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 11: MTU Size
# ═══════════════════════════════════════════════════════════════════════════
11)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "MTU SIZE" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet Interface MTU Size\n(leave blank for default 1500, common values: 1500, 9000)" 12 62 "" \
3>&1 1>&2 2>&3); then
if validate_mtu "$result"; then
_mtu="$result"
((STEP++))
else
whiptail --msgbox "Invalid MTU size.\n\nMTU must be between 576 and 65535.\nCommon values: 1500 (default), 9000 (jumbo frames)" 10 58
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 12: DNS Search Domain
# ═══════════════════════════════════════════════════════════════════════════
12)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "DNS SEARCH DOMAIN" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet DNS Search Domain\n(leave blank to use host setting)" 12 58 "" \
3>&1 1>&2 2>&3); then
_sd="$result"
((STEP++))
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 13: DNS Server
# ═══════════════════════════════════════════════════════════════════════════
13)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "DNS SERVER" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet DNS Server IP\n(leave blank to use host setting)" 12 58 "" \
3>&1 1>&2 2>&3); then
_ns="$result"
((STEP++))
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 14: MAC Address
# ═══════════════════════════════════════════════════════════════════════════
14)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "MAC ADDRESS" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet MAC Address\n(leave blank for auto-generated, format: XX:XX:XX:XX:XX:XX)" 12 62 "" \
3>&1 1>&2 2>&3); then
if validate_mac_address "$result"; then
_mac="$result"
((STEP++))
else
whiptail --msgbox "Invalid MAC address format.\n\nRequired format: XX:XX:XX:XX:XX:XX\nExample: 02:00:00:00:00:01" 10 58
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 15: VLAN Tag
# ═══════════════════════════════════════════════════════════════════════════
15)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "VLAN TAG" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet VLAN Tag (1-4094)\n(leave blank for no VLAN)" 12 58 "" \
3>&1 1>&2 2>&3); then
if validate_vlan_tag "$result"; then
_vlan="$result"
((STEP++))
else
whiptail --msgbox "Invalid VLAN tag.\n\nVLAN must be a number between 1 and 4094." 8 58
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 16: Tags
# ═══════════════════════════════════════════════════════════════════════════
16)
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "CONTAINER TAGS" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet Custom Tags (semicolon-separated)\n(alphanumeric, hyphens, underscores only)" 12 58 "$_tags" \
3>&1 1>&2 2>&3); then
local tags_test="${result:-}"
tags_test=$(echo "$tags_test" | tr -d '[:space:]')
if validate_tags "$tags_test"; then
_tags="$tags_test"
((STEP++))
else
whiptail --msgbox "Invalid tag format.\n\nTags can only contain:\n- Letters (a-z, A-Z)\n- Numbers (0-9)\n- Hyphens (-)\n- Underscores (_)\n- Semicolons (;) as separator" 14 58
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 17: SSH Settings
# ═══════════════════════════════════════════════════════════════════════════
17)
configure_ssh_settings "Step $STEP/$MAX_STEP"
# configure_ssh_settings handles its own flow, always advance
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 18: FUSE Support
# ═══════════════════════════════════════════════════════════════════════════
18)
local fuse_default_flag="--defaultno"
[[ "$_enable_fuse" == "yes" || "$_enable_fuse" == "1" ]] && fuse_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "FUSE SUPPORT" \
--ok-button "Next" --cancel-button "Back" \
$fuse_default_flag \
--yesno "\nEnable FUSE support?\n\nRequired for: rclone, mergerfs, AppImage, etc.\n\n(App default: ${var_fuse:-no})" 14 58; then
_enable_fuse="yes"
else
if [ $? -eq 1 ]; then
_enable_fuse="no"
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 19: TUN/TAP Support
# ═══════════════════════════════════════════════════════════════════════════
19)
local tun_default_flag="--defaultno"
[[ "$_enable_tun" == "yes" || "$_enable_tun" == "1" ]] && tun_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "TUN/TAP SUPPORT" \
--ok-button "Next" --cancel-button "Back" \
$tun_default_flag \
--yesno "\nEnable TUN/TAP device support?\n\nRequired for: VPN apps (WireGuard, OpenVPN, Tailscale),\nnetwork tunneling, and containerized networking.\n\n(App default: ${var_tun:-no})" 14 62; then
_enable_tun="yes"
else
if [ $? -eq 1 ]; then
_enable_tun="no"
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 20: Nesting Support
# ═══════════════════════════════════════════════════════════════════════════
20)
local nesting_default_flag=""
[[ "$_enable_nesting" == "0" || "$_enable_nesting" == "no" ]] && nesting_default_flag="--defaultno"
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "NESTING SUPPORT" \
--ok-button "Next" --cancel-button "Back" \
$nesting_default_flag \
--yesno "\nEnable Nesting?\n\nRequired for: Docker, LXC inside LXC, Podman,\nand other containerization tools.\n\n(App default: ${var_nesting:-1})" 14 58; then
_enable_nesting="1"
else
if [ $? -eq 1 ]; then
_enable_nesting="0"
if [[ "$var_os" != "alpine" ]]; then
whiptail --backtitle "Proxmox VE Helper Scripts" \
--title "⚠️ NESTING WARNING" \
--msgbox "Modern systemd-based distributions (Debian 13+, Ubuntu 24.04+, etc.) may require nesting to be enabled for proper operation.\n\nWithout nesting, the container may start in a degraded state with failing services (error 243/CREDENTIALS).\n\nIf you experience issues, enable nesting in the container options." 14 68
fi
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 21: GPU Passthrough
# ═══════════════════════════════════════════════════════════════════════════
21)
local gpu_default_flag="--defaultno"
[[ "$_enable_gpu" == "yes" ]] && gpu_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "GPU PASSTHROUGH" \
--ok-button "Next" --cancel-button "Back" \
$gpu_default_flag \
--yesno "\nEnable GPU Passthrough?\n\nAutomatically detects and passes through available GPUs\n(Intel/AMD/NVIDIA) for hardware acceleration.\n\nRecommended for: Media servers, AI/ML, Transcoding\n\n(App default: ${var_gpu:-no})" 16 62; then
_enable_gpu="yes"
else
if [ $? -eq 1 ]; then
_enable_gpu="no"
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 22: Keyctl Support (Docker/systemd)
# ═══════════════════════════════════════════════════════════════════════════
22)
if [[ "$_ct_type" == "1" ]]; then
_enable_keyctl="1"
((STEP++))
continue
fi
local keyctl_default_flag="--defaultno"
[[ "$_enable_keyctl" == "1" ]] && keyctl_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "KEYCTL SUPPORT" \
--ok-button "Next" --cancel-button "Back" \
$keyctl_default_flag \
--yesno "\nEnable Keyctl support?\n\nRequired for: Docker containers, systemd-networkd,\nand kernel keyring operations.\n\nNote: Automatically enabled for unprivileged containers.\n\n(App default: ${var_keyctl:-0})" 16 62; then
_enable_keyctl="1"
else
if [ $? -eq 1 ]; then
_enable_keyctl="0"
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 23: APT Cacher Proxy
# ═══════════════════════════════════════════════════════════════════════════
23)
local apt_cacher_default_flag="--defaultno"
[[ "$_apt_cacher" == "yes" ]] && apt_cacher_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "APT CACHER PROXY" \
--ok-button "Next" --cancel-button "Back" \
$apt_cacher_default_flag \
--yesno "\nUse APT Cacher-NG proxy?\n\nSpeeds up package downloads by caching them locally.\nRequires apt-cacher-ng running on your network.\n\n(App default: ${var_apt_cacher:-no})" 14 62; then
_apt_cacher="yes"
# Ask for IP if enabled
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "APT CACHER IP" \
--inputbox "\nEnter APT Cacher-NG IP or URL:\n(e.g. 192.168.1.10, http://host, https://host:443)" 12 62 "$_apt_cacher_ip" \
3>&1 1>&2 2>&3); then
_apt_cacher_ip="$result"
fi
else
if [ $? -eq 1 ]; then
_apt_cacher="no"
_apt_cacher_ip=""
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 24: HTTP/HTTPS Proxy
# ═══════════════════════════════════════════════════════════════════════════
24)
local http_proxy_default_flag="--defaultno"
[[ -n "$_http_proxy" ]] && http_proxy_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "HTTP/HTTPS PROXY" \
--ok-button "Next" --cancel-button "Back" \
$http_proxy_default_flag \
--yesno "\nUse HTTP/HTTPS proxy?\n\nRequired when internet access must go through a proxy server.\n(e.g. corporate networks)\n\n(App default: ${var_http_proxy:-none})" 14 62; then
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "HTTP PROXY URL" \
--inputbox "\nEnter HTTP proxy URL:\n(e.g. http://proxy.local:8080)" 12 62 "$_http_proxy" \
3>&1 1>&2 2>&3); then
_http_proxy="$result"
local _no_proxy_default="${_http_no_proxy:-localhost,127.0.0.1,.local}"
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "NO_PROXY EXCEPTIONS" \
--inputbox "\nEnter NO_PROXY exceptions (comma-separated):\nLeave empty for defaults." 12 62 "$_no_proxy_default" \
3>&1 1>&2 2>&3); then
_http_no_proxy="$result"
fi
fi
else
if [ $? -eq 1 ]; then
_http_proxy=""
_http_no_proxy=""
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 25: Host CA Inheritance
# ═══════════════════════════════════════════════════════════════════════════
25)
local host_ca_count=0
local host_ca_dir="/usr/local/share/ca-certificates"
local cert
shopt -s nullglob
for cert in "$host_ca_dir"/*.crt; do
host_ca_count=$((host_ca_count + 1))
done
shopt -u nullglob
if [[ $host_ca_count -eq 0 ]]; then
_inherit_host_ca="no"
((STEP++))
continue
fi
local host_ca_default_flag="--defaultno"
[[ "$_inherit_host_ca" == "yes" ]] && host_ca_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "HOST CA INHERITANCE" \
--ok-button "Next" --cancel-button "Back" \
$host_ca_default_flag \
--yesno "\nInherit host CA certificates into this container?\n\nDetected on host: ${host_ca_count} certificate(s) in:\n${host_ca_dir}\n\nRecommended for private PKI / TLS-inspection environments.\n\n(App default: ${var_inherit_host_ca:-no})" 16 72; then
_inherit_host_ca="yes"
else
if [ $? -eq 1 ]; then
_inherit_host_ca="no"
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 26: Container Timezone
# ═══════════════════════════════════════════════════════════════════════════
26)
local tz_hint="$_ct_timezone"
[[ -z "$tz_hint" ]] && tz_hint="(empty - will use host timezone)"
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "CONTAINER TIMEZONE" \
--ok-button "Next" --cancel-button "Back" \
--inputbox "\nSet container timezone.\n\nExamples: Europe/Berlin, America/New_York, Asia/Tokyo\n\nHost timezone: ${_host_timezone:-unknown}\n\nLeave empty to inherit from host." 16 62 "$_ct_timezone" \
3>&1 1>&2 2>&3); then
local tz_test="$result"
[[ "${tz_test:-}" == Etc/* ]] && tz_test="host" # pct doesn't accept Etc/* zones
if validate_timezone "$tz_test"; then
_ct_timezone="$tz_test"
((STEP++))
else
whiptail --msgbox "Invalid timezone: '$result'\n\nTimezone must exist in /usr/share/zoneinfo/\n\nExamples:\n- Europe/Berlin\n- America/New_York\n- Asia/Tokyo\n- UTC" 14 58
fi
else
((STEP--))
fi
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 27: Container Protection
# ═══════════════════════════════════════════════════════════════════════════
27)
local protect_default_flag="--defaultno"
[[ "$_protect_ct" == "yes" || "$_protect_ct" == "1" ]] && protect_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "CONTAINER PROTECTION" \
--ok-button "Next" --cancel-button "Back" \
$protect_default_flag \
--yesno "\nEnable Container Protection?\n\nPrevents accidental deletion of this container.\nYou must disable protection before removing.\n\n(App default: ${var_protection:-no})" 14 62; then
_protect_ct="yes"
else
if [ $? -eq 1 ]; then
_protect_ct="no"
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 28: Device Node Creation (mknod)
# ═══════════════════════════════════════════════════════════════════════════
28)
local mknod_default_flag="--defaultno"
[[ "$_enable_mknod" == "1" ]] && mknod_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "DEVICE NODE CREATION" \
--ok-button "Next" --cancel-button "Back" \
$mknod_default_flag \
--yesno "\nAllow device node creation (mknod)?\n\nRequired for: Creating device files inside container.\nExperimental feature (requires kernel 5.3+).\n\n(App default: ${var_mknod:-0})" 14 62; then
_enable_mknod="1"
else
if [ $? -eq 1 ]; then
_enable_mknod="0"
else