#!/bin/sh

# This scripts waits until the PXE server responds to ping requests.
# In this way, we make sure network is up.

set -e

PXE_SERVER_IP=$(cat /etc/oci/pxe-server-ip)

TRIALS=300
while ! timeout 2 ping -q -c 1 ${PXE_SERVER_IP} >/dev/null && [ "${TRIALS}" -gt 0 ] ; do
	sleep 1
	TRIALS=$(( ${TRIALS} - 1 ))
done

if [ "${TRIALS}" = 0 ] ; then
	exit 1
else
	exit 0
fi
