summaryrefslogtreecommitdiffstats
path: root/core/rootfs/rootfs-stage31/data/inc/network.functions
blob: 94957be205f65a1d7ebb2d54f72f88fd7b6c59a7 (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
#!/bin/ash

wait_for_iface() {
	local DEVICE=$1
	local TIMEOUT="$(( "$2" * 2 ))"
	local state laststate
	echo -n "Waiting for interface $DEVICE: "
	# 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