summaryrefslogtreecommitdiffstats
path: root/core/rootfs/rootfs-stage31/data/inc/setup_network_retry
blob: 7692370316aec2a64fa0050f508dede732cd5032 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/ash

source /run/network.conf

for i in 1 2 3 4 5 6 7 8; do
	echo "<$i> Try to fix broken network"
	echo -n "Take interface $IFACE down .. "

	ip link set dev "$BRIDGE" down
	ip link set dev "$IFACE" down
	usleep 100000

	echo "and up again.."
	ip link set dev "$IFACE" up
	usleep 100000

	wait_for_iface "$IFACE" "$(( 15 + i * 2 ))"
	retval=$?
	ip link set dev "$BRIDGE" up
	if [ "$retval" -eq 0 ] && [ "$i" -ge 4 ] && [ -n "$CLIENTIP" ] && [ -n "$GATEWAY" ]; then
		echo "....."
		usleep 100000
		echo "Checking if static IP config works...."
		if ping -c1 -w2 "$GATEWAY" &> /dev/null || ping -c1 -w2 "$SERVERIP" &> /dev/null; then
			echo "apparently so."
			echo "Trying to boot without DHCP config (DNS, Hostname, ...), YMMV!"
			sleep 3
			RET=0
			break
		fi
		echo "...nope..."
	fi
	wait_for_iface "$BRIDGE" 10
	usleep 100000

	udhcpc $PARAM -O ntpsrv -O domain -O search -t "$(( 2 + i / 2 ))" -T "$(( 4 + i ))" -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" \
		|| udhcpc $PARAM -O ntpsrv -O domain -O search -t "$(( 2 + i / 2 ))" -T "$(( 4 + i ))" -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE"
	RET="$?"

	if [ "$RET" -eq 0 ]; then
		echo "Finally fixed IP config. Continue boot."
		break
	fi
done

[ $RET -gt 0 ] && drop_shell "Something is really broken.. Please check your network cable and reset your computer.
$(ip a)
$(ip r s)"

# create correct return value
[ $RET -eq 0 ]