summaryrefslogtreecommitdiffstats
path: root/core/modules/slx-network-configs-targets/data/opt/openslx/scripts/systemd-wait_online
blob: 86aa3da267b95ab5ed8014f8e28c89a96a606080 (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
#!/bin/ash

# Wait until we have a nameserver in resolv.conf
# and we have a gateway configured

w=0
while ! grep -q ^nameserver /etc/resolv.conf && [ "$w" -lt 10 ]; do
	let w++
	sleep 1
done
ns=$w

# We don't consider a missing nameserver fatal, but a missing gateway, if no proxy is set
. /etc/profile
while [ -z "$http_proxy" ] && [ -z "$ALL_PROXY" ] && ! ip route show | grep -q ^default; do
	[ "$w" -gt 12 ] && exit 1 # Give up - not online
	let w++
	sleep 1
	. /etc/profile
done
gw=$(( w - ns ))

if [ "$ns" -gt 2 ] || [ "$gw" -gt 2 ]; then
	echo "Waited $ns seconds for DNS, $gw seconds for default gateway/proxy"
fi

exit 0