contrib/meshwizard: Check if luci/luci-splash is installed before trying to setup it
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / setup_network.sh
1 # setup entry in /etc/config/network for a interface
2 # Argument $1: network interface
3
4 net="$1"
5 . /etc/functions.sh
6 . $dir/functions.sh
7
8 # Delete the network interface section for $net
9 if [ "$cleanup" == 1 ]; then
10 section_cleanup network.$netrenamed
11 fi
12
13 # Setup a (new) interface section for $net
14
15 ipaddr=$(uci get meshwizard.netconfig.$net\_ip4addr)
16 [ -z "$ipaddr" ] && msg_missing_value meshwizard $net\_ip4addr
17 [ -z "$interface_netmask" ] && interface netmask="255.255.0.0"
18
19 uci batch << EOF
20 set network.$netrenamed="interface"
21 set network.$netrenamed.proto="static"
22 set network.$netrenamed.ipaddr="$ipaddr"
23 set network.$netrenamed.netmask="$interface_netmask"
24 set network.$netrenamed.dns="$interface_dns"
25 EOF
26
27 uci_commitverbose "Setup interface $netrenamed" network
28
29 # setup dhcp alias/interface
30
31 net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
32 if [ "$net_dhcp" == 1 ]; then
33
34 # Load meshwizard_settings
35 dhcprange="$(uci -q get meshwizard.netconfig.${net}_dhcprange)"
36 interface_ip="$(uci -q get meshwizard.netconfig.${net}_ip4addr)"
37 vap=$(uci -q get meshwizard.netconfig.${net}_vap)
38
39 # Clean/rename config
40 handle_dhcpalias() {
41 config_get interface "$1" interface
42 if [ "$interface" == "$netrenamed" ]; then
43 if [ "$cleanup" == 1 ]; then
44 section_cleanup network.$1
45 else
46 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
47 section_rename network $1 ${netrenamed}dhcp
48 fi
49 fi
50 fi
51 }
52 config_load network
53 config_foreach handle_dhcpalias alias
54
55 # Get IP/netmask and start-ip for $net dhcp
56 # If no dhcprange is given in /etc/config/meshwizard we autogenerate one
57
58 if [ -z "$dhcprange" ]; then
59 dhcprange="$($dir/helpers/gen_dhcp_ip.sh $interface_ip)/24"
60 uci set meshwizard.netconfig.${net}_dhcprange="$dhcprange"
61 fi
62 eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange 1 0)
63
64 # setup wifi-dhcp interface or alias
65
66 # Setup alias for $net
67
68 if [ "$vap" == 1 ]; then
69 uci set network.${netrenamed}dhcp=interface
70 else
71 uci set network.${netrenamed}dhcp=alias
72 uci set network.${netrenamed}dhcp.interface="$netrenamed"
73 fi
74
75 uci batch << EOF
76 set network.${netrenamed}dhcp.proto=static
77 set network.${netrenamed}dhcp.ipaddr="$START"
78 set network.${netrenamed}dhcp.netmask="$NETMASK"
79 EOF
80
81 fi
82
83 uci_commitverbose "Setup interface for ${netrenamed}dhcp" network