root/luci/branches/luci-0.10/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh @ 7810

Revision 7810, 2.1 KB (checked in by jow, 19 months ago)

luci-0.10: sync with trunk, drop broken and unfinished applications

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