#!/bin/sh

# The timeout can be set in the environment or the
# first parameter.

COUNTER=0

if [ $# -gt 1 ]; then
    echo "usage: $0 [timeout]"
    exit 1
fi

[ $# -eq 1 ] && TIMEOUT=$1

# Set the default TIMEOUT
: ${TIMEOUT:=60}

# Wait for the radio to be ready before continuing
while [ $COUNTER -lt $TIMEOUT ]; do
  TYPE=$(radio-query --type)
  MODEL=$(radio-query --model)
  if [ $? == 0 ]; then
    echo "Cellular radio is ready."
    exit 0
  fi
  let COUNTER=COUNTER+1

  echo "Waiting for radio to come up in order to identify type ..."

  sleep 1
done

echo "Cellular radio is not ready."
exit 1
