Skip to content

Commit b26c5c9

Browse files
authored
[core]: add ipv6 configuration support (#5575)
1 parent 5e5c79e commit b26c5c9

File tree

1 file changed

+138
-41
lines changed

1 file changed

+138
-41
lines changed

misc/build.func

Lines changed: 138 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxV
2020
if command -v curl >/dev/null 2>&1; then
2121
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func)
2222
load_functions
23-
#echo "(build.func) Loaded core.func via curl"
2423
elif command -v wget >/dev/null 2>&1; then
2524
source <(wget -qO- https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func)
2625
load_functions
27-
#echo "(build.func) Loaded core.func via wget"
2826
fi
2927
# This function enables error handling in the script by setting options and defining a trap for the ERR signal.
3028
catch_errors() {
@@ -189,10 +187,12 @@ base_settings() {
189187
HN=$NSAPP
190188
BRG="vmbr0"
191189
NET="dhcp"
190+
IPV6_METHOD="none"
191+
IPV6_STATIC=""
192192
GATE=""
193193
APT_CACHER=""
194194
APT_CACHER_IP=""
195-
DISABLEIP6="no"
195+
#DISABLEIP6="no"
196196
MTU=""
197197
SD=""
198198
NS=""
@@ -531,43 +531,130 @@ advanced_settings() {
531531
fi
532532
fi
533533

534+
# IPv4 methods: dhcp, static, none
534535
while true; do
535-
NET=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Static IPv4 CIDR Address (/24)" 8 58 dhcp --title "IP ADDRESS" 3>&1 1>&2 2>&3)
536+
IPV4_METHOD=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
537+
--title "IPv4 Address Management" \
538+
--menu "Select IPv4 Address Assignment Method:" 12 60 2 \
539+
"dhcp" "Automatic (DHCP, recommended)" \
540+
"static" "Static (manual entry)" \
541+
3>&1 1>&2 2>&3)
542+
536543
exit_status=$?
537-
if [ $exit_status -eq 0 ]; then
538-
if [ "$NET" = "dhcp" ]; then
539-
echo -e "${NETWORK}${BOLD}${DGN}IP Address: ${BGN}$NET${CL}"
540-
break
541-
else
542-
if [[ "$NET" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}/([0-9]|[1-2][0-9]|3[0-2])$ ]]; then
543-
echo -e "${NETWORK}${BOLD}${DGN}IP Address: ${BGN}$NET${CL}"
544+
if [ $exit_status -ne 0 ]; then
545+
exit_script
546+
fi
547+
548+
case "$IPV4_METHOD" in
549+
dhcp)
550+
NET="dhcp"
551+
GATE=""
552+
echo -e "${NETWORK}${BOLD}${DGN}IPv4: DHCP${CL}"
553+
break
554+
;;
555+
static)
556+
# Static: call and validate CIDR address
557+
while true; do
558+
NET=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
559+
--inputbox "Enter Static IPv4 CIDR Address (e.g. 192.168.100.50/24)" 8 58 "" \
560+
--title "IPv4 ADDRESS" 3>&1 1>&2 2>&3)
561+
if [ -z "$NET" ]; then
562+
whiptail --msgbox "IPv4 address must not be empty." 8 58
563+
continue
564+
elif [[ "$NET" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}/([0-9]|[1-2][0-9]|3[0-2])$ ]]; then
565+
echo -e "${NETWORK}${BOLD}${DGN}IPv4 Address: ${BGN}$NET${CL}"
544566
break
545567
else
546-
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "$NET is an invalid IPv4 CIDR address. Please enter a valid IPv4 CIDR address or 'dhcp'" 8 58
568+
whiptail --msgbox "$NET is not a valid IPv4 CIDR address. Please enter a correct value!" 8 58
547569
fi
548-
fi
549-
else
550-
exit_script
551-
fi
570+
done
571+
572+
# call and validate Gateway
573+
while true; do
574+
GATE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
575+
--inputbox "Enter Gateway IP address for static IPv4" 8 58 "" \
576+
--title "Gateway IP" 3>&1 1>&2 2>&3)
577+
if [ -z "$GATE1" ]; then
578+
whiptail --msgbox "Gateway IP address cannot be empty." 8 58
579+
elif [[ ! "$GATE1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
580+
whiptail --msgbox "Invalid Gateway IP address format." 8 58
581+
else
582+
GATE=",gw=$GATE1"
583+
echo -e "${GATEWAY}${BOLD}${DGN}Gateway IP Address: ${BGN}$GATE1${CL}"
584+
break
585+
fi
586+
done
587+
break
588+
;;
589+
esac
552590
done
553591

554-
if [ "$NET" != "dhcp" ]; then
555-
while true; do
556-
GATE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Enter gateway IP address" 8 58 --title "Gateway IP" 3>&1 1>&2 2>&3)
557-
if [ -z "$GATE1" ]; then
558-
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Gateway IP address cannot be empty" 8 58
559-
elif [[ ! "$GATE1" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
560-
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox "Invalid IP address format" 8 58
561-
else
562-
GATE=",gw=$GATE1"
563-
echo -e "${GATEWAY}${BOLD}${DGN}Gateway IP Address: ${BGN}$GATE1${CL}"
564-
break
565-
fi
566-
done
567-
else
568-
GATE=""
569-
echo -e "${GATEWAY}${BOLD}${DGN}Gateway IP Address: ${BGN}Default${CL}"
570-
fi
592+
# IPv6 Address Management selection
593+
while true; do
594+
IPV6_METHOD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --menu \
595+
"Select IPv6 Address Management Type:" 15 58 4 \
596+
"auto" "SLAAC/AUTO (recommended, default)" \
597+
"dhcp" "DHCPv6" \
598+
"static" "Static (manual entry)" \
599+
"none" "Disabled" \
600+
--default-item "auto" 3>&1 1>&2 2>&3)
601+
[ $? -ne 0 ] && exit_script
602+
603+
case "$IPV6_METHOD" in
604+
auto)
605+
echo -e "${NETWORK}${BOLD}${DGN}IPv6: ${BGN}SLAAC/AUTO${CL}"
606+
IPV6_ADDR=""
607+
IPV6_GATE=""
608+
break
609+
;;
610+
dhcp)
611+
echo -e "${NETWORK}${BOLD}${DGN}IPv6: ${BGN}DHCPv6${CL}"
612+
IPV6_ADDR="dhcp"
613+
IPV6_GATE=""
614+
break
615+
;;
616+
static)
617+
# Ask for static IPv6 address (CIDR notation, e.g., 2001:db8::1234/64)
618+
while true; do
619+
IPV6_ADDR=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox \
620+
"Set a static IPv6 CIDR address (e.g., 2001:db8::1234/64)" 8 58 "" \
621+
--title "IPv6 STATIC ADDRESS" 3>&1 1>&2 2>&3) || exit_script
622+
if [[ "$IPV6_ADDR" =~ ^([0-9a-fA-F:]+:+)+[0-9a-fA-F]+(/[0-9]{1,3})$ ]]; then
623+
echo -e "${NETWORK}${BOLD}${DGN}IPv6 Address: ${BGN}$IPV6_ADDR${CL}"
624+
break
625+
else
626+
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox \
627+
"$IPV6_ADDR is an invalid IPv6 CIDR address. Please enter a valid IPv6 CIDR address (e.g., 2001:db8::1234/64)" 8 58
628+
fi
629+
done
630+
# Optional: ask for IPv6 gateway for static config
631+
while true; do
632+
IPV6_GATE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox \
633+
"Enter IPv6 gateway address (optional, leave blank for none)" 8 58 "" --title "IPv6 GATEWAY" 3>&1 1>&2 2>&3)
634+
if [ -z "$IPV6_GATE" ]; then
635+
IPV6_GATE=""
636+
break
637+
elif [[ "$IPV6_GATE" =~ ^([0-9a-fA-F:]+:+)+[0-9a-fA-F]+$ ]]; then
638+
break
639+
else
640+
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox \
641+
"Invalid IPv6 gateway format." 8 58
642+
643+
fi
644+
done
645+
break
646+
;;
647+
none)
648+
echo -e "${NETWORK}${BOLD}${DGN}IPv6: ${BGN}Disabled${CL}"
649+
IPV6_ADDR="none"
650+
IPV6_GATE=""
651+
break
652+
;;
653+
*)
654+
exit_script
655+
;;
656+
esac
657+
done
571658

572659
if [ "$var_os" == "alpine" ]; then
573660
APT_CACHER=""
@@ -581,12 +668,12 @@ advanced_settings() {
581668
fi
582669
fi
583670

584-
if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then
585-
DISABLEIP6="yes"
586-
else
587-
DISABLEIP6="no"
588-
fi
589-
echo -e "${DISABLEIPV6}${BOLD}${DGN}Disable IPv6: ${BGN}$DISABLEIP6${CL}"
671+
# if (whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then
672+
# DISABLEIP6="yes"
673+
# else
674+
# DISABLEIP6="no"
675+
# fi
676+
# echo -e "${DISABLEIPV6}${BOLD}${DGN}Disable IPv6: ${BGN}$DISABLEIP6${CL}"
590677

591678
if MTU1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Interface MTU Size (leave blank for default [The MTU of your selected vmbr, default is 1500])" 8 58 --title "MTU SIZE" 3>&1 1>&2 2>&3); then
592679
if [ -z "$MTU1" ]; then
@@ -941,6 +1028,16 @@ start() {
9411028
build_container() {
9421029
# if [ "$VERBOSE" == "yes" ]; then set -x; fi
9431030

1031+
NET_STRING="-net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN$MTU"
1032+
case "$IPV6_METHOD" in
1033+
auto) NET_STRING="$NET_STRING,ip6=auto" ;;
1034+
dhcp) NET_STRING="$NET_STRING,ip6=dhcp" ;;
1035+
static)
1036+
NET_STRING="$NET_STRING,ip6=$IPV6_ADDR"
1037+
[ -n "$IPV6_GATE" ] && NET_STRING="$NET_STRING,gw6=$IPV6_GATE"
1038+
;;
1039+
none) ;;
1040+
esac
9441041
if [ "$CT_TYPE" == "1" ]; then
9451042
FEATURES="keyctl=1,nesting=1"
9461043
else
@@ -968,7 +1065,7 @@ build_container() {
9681065
export CACHER="$APT_CACHER"
9691066
export CACHER_IP="$APT_CACHER_IP"
9701067
export tz="$timezone"
971-
export DISABLEIPV6="$DISABLEIP6"
1068+
#export DISABLEIPV6="$DISABLEIP6"
9721069
export APPLICATION="$APP"
9731070
export app="$NSAPP"
9741071
export PASSWORD="$PW"
@@ -988,7 +1085,7 @@ build_container() {
9881085
-tags $TAGS
9891086
$SD
9901087
$NS
991-
-net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN$MTU
1088+
$NET_STRING
9921089
-onboot 1
9931090
-cores $CORE_COUNT
9941091
-memory $RAM_SIZE

0 commit comments

Comments
 (0)