From 49bd845e77d6f5fa52ce827047f6011f2ca2783f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gytis=20Sto=C5=A1kevi=C4=8Dius?= Date: Mon, 7 Apr 2025 11:34:15 +0300 Subject: [PATCH] wait for interface to be up --- src/network.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/network.sh b/src/network.sh index 60dbcf2..e9b82c9 100755 --- a/src/network.sh +++ b/src/network.sh @@ -84,6 +84,21 @@ configure_guest_network_interface() { INTERFACE_NAME="Ethernet $IDX" fi + RETRIES=10 + for i in $(seq 1 $RETRIES); do + OUTPUT=$(python3 /run/qga.py powershell -Command "(\$(Get-NetAdapter -Name '$INTERFACE_NAME').Status)") + STATUS=$(echo "$OUTPUT" | grep -A1 'STDOUT:' | tail -n1 | tr -d '\r' | xargs) + + echo "Status: '$STATUS'" + if [[ "$STATUS" == "Up" ]]; then + echo "Interface '$INTERFACE_NAME' is up!" + break + else + echo "Waiting for interface '$INTERFACE_NAME' to be up... ($i/$RETRIES)" + sleep $SLEEP + fi + done + exit_code=0 python3 /run/qga.py powershell -Command "Set-NetIPInterface -InterfaceAlias '$INTERFACE_NAME' -Dhcp Disabled" || exit_code=$? if [[ $exit_code -ne 0 ]]; then