-
Notifications
You must be signed in to change notification settings - Fork 1
/
dhcpfallback
executable file
·68 lines (51 loc) · 1.5 KB
/
dhcpfallback
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh /etc/rc.common
START=95
USE_PROCD=1
wait_for_lan_ipaddr() {
. /lib/functions/network.sh
echo "Waiting for LAN IP address..."
for loop_idx in $(seq 1 5); do
network_flush_cache
network_get_ipaddr LAN_IPADDR lan
if [ -n "${LAN_IPADDR}" ]; then
echo "LAN IP address found."
return 0
fi
sleep 5
done
echo "LAN IP address timeout."
return 1
}
start_service() {
if wait_for_lan_ipaddr; then
echo -e "\nLAN IP address [$(uci get network.lan.proto)]: ${LAN_IPADDR}\n" > /dev/console
echo "LAN IP configuration complete, not falling back to static IP."
return 0
fi
echo "LAN DHCP failed, falling back to static IP..."
uci set network.lan.proto='static'
uci set network.lan.ipaddr='192.168.200.1' # TODO: get this from config
uci commit network
uci set dhcp.lan.proxy='0'
uci rename dhcp.@dnsmasq[0].pxe_prompt=_pxe_prompt
uci rename dhcp.@dnsmasq[0].pxe_service=_pxe_service
uci commit dhcp
/etc/init.d/network restart
/etc/init.d/dnsmasq restart
echo -e "\nLAN IP address [static]: $(uci get network.lan.ipaddr)\n" > /dev/console
}
stop_service() {
if [ "$(uci get network.lan.proto)" = 'dhcp' ]; then
return 0
fi
echo "Removing LAN static IP and restoring DHCP configuration..."
uci set network.lan.proto='dhcp'
uci delete network.lan.ipaddr
uci commit network
uci set dhcp.lan.proxy='1'
uci rename dhcp.@dnsmasq[0]._pxe_prompt=pxe_prompt
uci rename dhcp.@dnsmasq[0]._pxe_service=pxe_service
uci commit dhcp
/etc/init.d/network restart
/etc/init.d/dnsmasq restart
}