#!/bin/sh
#
# (C) Copyright 2002, 2006-2007 Axis Communications AB, LUND, SWEDEN
# This file is released under the GPL v2.

# Note: any runfile on any interface _will do_. Is this the intended behaviour?

run_dir=/var/run/init.d
max_wait=300
wait=0

. /etc/init.d/functions.sh

case "$1" in
	start)
		begin "Waiting for a network interface"

		[ -d $run_dir ] || end 1 "$0: $run_dir directory missing!"

		slept=n
		while [ $wait -lt $max_wait ]; do
			if_runfiles=$(find $run_dir -type f -name 'net.*') || :
			if [ "$if_runfiles" ]; then
				for if_runfile in $if_runfiles; do
					read configured < $if_runfile
					if [ "$configured" = 1 ]; then
						[ $slept != y ] || echo
						information "${if_runfile##*.} is up"
						end 0
						exit 0
					fi
				done
			fi
			sleep 1
			slept=y
			wait=$(($wait + 1))
			echo -n .
		done
		;;
	stop)
		;;
	*)
		error "Usage: $0 start|stop"
		;;
esac

exit 0
