diff --git a/src/network.sh b/src/network.sh index ea2e5a7d..3be31985 100644 --- a/src/network.sh +++ b/src/network.sh @@ -644,12 +644,17 @@ getInfo() { fi GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1) - IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1) - IP6="" + { IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1); rc=$?; } 2>/dev/null || : + + if (( rc != 0 )) && [[ "$DHCP" != [Yy1]* ]]; then + error "Could not determine container IP address!" && exit 26 + fi + IP6="" # shellcheck disable=SC2143 if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then - IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up) + { IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up); rc=$?; } 2>/dev/null || : + (( rc != 0 )) && IP6="" [ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1) fi