diff --git a/packages/by-name/azure-no-agent/no-agent.sh b/packages/by-name/azure-no-agent/no-agent.sh index 750cfd28e1..c051bde9f0 100755 --- a/packages/by-name/azure-no-agent/no-agent.sh +++ b/packages/by-name/azure-no-agent/no-agent.sh @@ -1,34 +1,34 @@ #!/bin/bash +# Copyright 2024 Edgeless Systems GmbH +# SPDX-License-Identifier: AGPL-3.0-only attempts=1 -until [ "$attempts" -gt 5 ] -do - echo "obtaining goal state - attempt $attempts" - goalstate=$(curl --fail -v -X 'GET' -H "x-ms-agent-name: azure-vm-register" \ - -H "Content-Type: text/xml;charset=utf-8" \ - -H "x-ms-version: 2012-11-30" \ - "http://168.63.129.16/machine/?comp=goalstate") - # shellcheck disable=SC2181 - if [ $? -eq 0 ] - then - echo "successfully retrieved goal state" - retrieved_goal_state=true - break - fi - sleep 5 - attempts=$((attempts+1)) +until [ "$attempts" -gt 5 ]; do + echo "obtaining goal state - attempt $attempts" + goalstate=$(curl --fail -v -X 'GET' -H "x-ms-agent-name: azure-vm-register" \ + -H "Content-Type: text/xml;charset=utf-8" \ + -H "x-ms-version: 2012-11-30" \ + "http://168.63.129.16/machine/?comp=goalstate") + # shellcheck disable=SC2181 + if [ $? -eq 0 ]; then + echo "successfully retrieved goal state" + retrieved_goal_state=true + break + fi + sleep 5 + attempts=$((attempts + 1)) done -if [ "$retrieved_goal_state" != "true" ] -then - echo "failed to obtain goal state - cannot register this VM" - exit 1 +if [ "$retrieved_goal_state" != "true" ]; then + echo "failed to obtain goal state - cannot register this VM" + exit 1 fi -container_id=$(grep ContainerId <<< "$goalstate" | sed 's/\s*<\/*ContainerId>//g' | sed 's/\r$//') -instance_id=$(grep InstanceId <<< "$goalstate" | sed 's/\s*<\/*InstanceId>//g' | sed 's/\r$//') +container_id=$(grep ContainerId <<<"$goalstate" | sed 's/\s*<\/*ContainerId>//g' | sed 's/\r$//') +instance_id=$(grep InstanceId <<<"$goalstate" | sed 's/\s*<\/*InstanceId>//g' | sed 's/\r$//') -ready_doc=$(cat << EOF +ready_doc=$( + cat < 1 @@ -48,19 +48,17 @@ EOF ) attempts=1 -until [ "$attempts" -gt 5 ] -do - echo "registering with Azure - attempt $attempts" - curl --fail -v -X 'POST' -H "x-ms-agent-name: azure-vm-register" \ - -H "Content-Type: text/xml;charset=utf-8" \ - -H "x-ms-version: 2012-11-30" \ - -d "$ready_doc" \ - "http://168.63.129.16/machine?comp=health" - # shellcheck disable=SC2181 - if [ $? -eq 0 ] - then - echo "successfully register with Azure" - break - fi - sleep 5 # sleep to prevent throttling from wire server +until [ "$attempts" -gt 5 ]; do + echo "registering with Azure - attempt $attempts" + curl --fail -v -X 'POST' -H "x-ms-agent-name: azure-vm-register" \ + -H "Content-Type: text/xml;charset=utf-8" \ + -H "x-ms-version: 2012-11-30" \ + -d "$ready_doc" \ + "http://168.63.129.16/machine?comp=health" + # shellcheck disable=SC2181 + if [ $? -eq 0 ]; then + echo "successfully register with Azure" + break + fi + sleep 5 # sleep to prevent throttling from wire server done