contrib/meshwizard: Better formatting
[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 # Setup a (new) interface section for $net
9
10 ipaddr=$(uci get meshwizard.netconfig.$net\_ip4addr)
11 [ -z "$ipaddr" ] && msg_missing_value meshwizard $net\_ip4addr
12 [ -z "$interface_netmask" ] && interface netmask="255.255.0.0"
13
14 uci batch << EOF
15 set network.$netrenamed="interface"
16 set network.$netrenamed.proto="static"
17 set network.$netrenamed.ipaddr="$ipaddr"
18 EOF
19
20 set_defaults "interface_" network.$netrenamed
21 uci_commitverbose "Setup interface $netrenamed" network
22
23 # setup dhcp alias/interface
24
25 net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
26 if [ "$net_dhcp" == 1 ]; then
27
28 # Load meshwizard_settings
29 dhcprange="$(uci -q get meshwizard.netconfig.${net}_dhcprange)"
30 interface_ip="$(uci -q get meshwizard.netconfig.${net}_ip4addr)"
31 vap=$(uci -q get meshwizard.netconfig.${net}_vap)
32
33 # Rename config
34 handle_dhcpalias() {
35 config_get interface "$1" interface
36 if [ "$interface" == "$netrenamed" ]; then
37 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
38 section_rename network $1 ${netrenamed}dhcp
39 fi
40 fi
41 }
42 config_load network
43 config_foreach handle_dhcpalias alias
44
45 # Get IP/netmask and start-ip for $net dhcp
46 # If no dhcprange is given in /etc/config/meshwizard we autogenerate one
47
48 if [ -z "$dhcprange" ]; then
49 dhcprange="$($dir/helpers/gen_dhcp_ip.sh $interface_ip)/24"
50 uci set meshwizard.netconfig.${net}_dhcprange="$dhcprange"
51 fi
52 eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange 1 0)
53
54 # setup wifi-dhcp interface or alias
55
56 # Setup alias for $net
57
58 if [ "$vap" == 1 ]; then
59 uci set network.${netrenamed}dhcp=interface
60 else
61 uci set network.${netrenamed}dhcp=alias
62 uci set network.${netrenamed}dhcp.interface="$netrenamed"
63 fi
64
65 uci batch <<- EOF
66 set network.${netrenamed}dhcp.proto=static
67 set network.${netrenamed}dhcp.ipaddr="$START"
68 set network.${netrenamed}dhcp.netmask="$NETMASK"
69 uci_commitverbose "Setup interface for ${netrenamed}dhcp" network
70 EOF
71
72 fi
73