summaryrefslogtreecommitdiffstats
path: root/core/rootfs/rootfs-stage31/data/inc/network.functions
blob: 853c0cb37c9c1ef034327c272272023c75c82dcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/ash

wait_for_iface() {
	local DEVICE=$1
	local TIMEOUT=10
	local state laststate
	[ -n "$2" ] && TIMEOUT="$2"
	echo -n "Waiting ${TIMEOUT}s for interface $DEVICE: "
	TIMEOUT="$(( TIMEOUT * 2 ))"
	# Some systems don't have operstate. Seems to be hardware dependent
	[ -e "/sys/class/net/${DEVICE}/operstate" ] || sleep 1
	if [ -e "/sys/class/net/${DEVICE}/operstate" ]; then
		while true; do
			# check linkstate
			state="$(cat "/sys/class/net/${DEVICE}/operstate")"
			[ "$state" != "$laststate" ] && echo -n "[$state]"
			laststate="$state"
			[ "$state" = "up" ] && break
			TIMEOUT=$(( TIMEOUT - 1 )) # don't wait forever, the pcnet iface of vmware will never be "up" although it's working
			if [ "$TIMEOUT" -le 0 ];then
				echo -n "TIMEOUT"
				break
			fi
			# else
			echo -n "."
			usleep 500000
		done
	else
		# we really don't have a operstate .. then just wait a sec and hope for the best.
		sleep 1
		echo -n "... no operstate, let's hope for the best..."
	fi
	echo
}
true