Refactor network string construction in build_container
Some checks failed
Bump build.func Revision / bump-revision (push) Has been cancelled

Improves readability and flexibility by building the NET_STRING variable incrementally, using parameter expansion to include only set values for MAC, GATE, VLAN, and MTU. This change makes the network configuration more robust and easier to maintain.
This commit is contained in:
CanbiZ 2025-09-22 11:34:44 +02:00
parent 2db707079b
commit 6373e16d44

View File

@ -2108,7 +2108,12 @@ start() {
build_container() {
# if [ "$VERBOSE" == "yes" ]; then set -x; fi
NET_STRING="-net0 name=eth0,bridge=${BRG:-vmbr0}${MAC:-},ip=${NET:-dhcp}${GATE:-}${VLAN:-}${MTU:-}"
NET_STRING="-net0 name=eth0,bridge=${BRG:-vmbr0}"
NET_STRING+="${MAC:+,hwaddr=$MAC}"
NET_STRING+=",ip=${NET:-dhcp}"
NET_STRING+="${GATE:+,gw=$GATE}"
NET_STRING+="${VLAN:+,tag=$VLAN}"
NET_STRING+="${MTU:+,mtu=$MTU}"
case "$IPV6_METHOD" in
auto) NET_STRING="$NET_STRING,ip6=auto" ;;
dhcp) NET_STRING="$NET_STRING,ip6=dhcp" ;;