github.com/uvalib/orcid-access-ws@v0.0.0-20250612130209-7d062dbabf9d/pipeline/wait_for_version.sh (about)

     1  #
     2  # wait for a version response that reports the expected (supplied) version
     3  #
     4  
     5  #set -x
     6  
     7  # validate input paremeters
     8  if [ $# -ne 3 ]; then
     9     echo "use: $(basename $0) <endpoint> <expected version> <timeout (in seconds)>"
    10     exit 1
    11  fi
    12  
    13  # for clarity
    14  ENDPOINT=$1
    15  shift
    16  EXPECTED_VERSION=$1
    17  shift
    18  TIMEOUT=$1
    19  
    20  # verify curl is available
    21  CURL_TOOL=curl
    22  which $CURL_TOOL > /dev/null 2>&1
    23  if [ $? -ne 0 ]; then
    24     echo "ERROR: $CURL_TOOL is not available in this environment"
    25     exit 1
    26  fi
    27  
    28  # verify awk is available
    29  AWK_TOOL=awk
    30  which $AWK_TOOL > /dev/null 2>&1
    31  if [ $? -ne 0 ]; then
    32     echo "ERROR: $AWK_TOOL is not available in this environment"
    33     exit 1
    34  fi
    35  
    36  # calculate start and end times
    37  START_TIME=$(date +%s)
    38  END_TIME=$(expr $START_TIME + $TIMEOUT)
    39  
    40  # loop until timeout
    41  while true; do
    42  
    43     VERSION=$($CURL_TOOL $ENDPOINT/version 2>/dev/null | $AWK_TOOL -F\" '{print $4}')
    44  
    45     # if we did not get a version, tag as unknown
    46     if [ -z "$VERSION" ]; then
    47        VERSION="unknown"
    48     fi
    49  
    50     # did we get the right version
    51     if [ "$VERSION" = "$EXPECTED_VERSION" ]; then
    52        echo "Reported version: $VERSION, done waiting"
    53        exit 0
    54     fi
    55  
    56     echo "Reported version: $VERSION, waiting for: $EXPECTED_VERSION"
    57  
    58     # check for timeout
    59     NOW_TIME=$(date +%s)
    60     if [ $NOW_TIME -ge $END_TIME ]; then
    61        echo "ERROR: timed out waiting for correct version to be reportd"
    62        exit 1
    63     fi
    64  
    65     sleep 5
    66  done
    67  
    68  # never get here
    69  
    70  #
    71  # end of file
    72  #