Merge pull request #1818 from dibdot/lxc_fix
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / setup_dhcp.sh
1 #!/bin/sh
2 # Sets up the dhcp part of dnsmasq
3
4 . /lib/functions.sh
5 . $dir/functions.sh
6
7 net="$1"
8 vap="$(uci -q get meshwizard.netconfig.${net}_vap)"
9
10 handle_dnsmasq() {
11         config_get interface "$1" interface
12         if [ "$interface" == "${netrenamed}dhcp" ]; then
13                 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
14                         section_rename dhcp $1 ${netrenamed}dhcp
15                 fi
16         fi
17 }
18 config_load dhcp
19 config_foreach handle_dnsmasq dhcp
20
21 [ "$net" == "lan" ] && uci -q delete dhcp.lan
22
23 if [ "$supports_vap" = 1 -a "$vap" = 1 ]; then
24         uci batch <<- EOF
25                 set dhcp.${netrenamed}dhcp="dhcp"
26                 set dhcp.${netrenamed}dhcp.ignore="0"
27                 set dhcp.${netrenamed}dhcp.interface="${netrenamed}dhcp"
28         EOF
29         set_defaults "dhcp_" dhcp.${netrenamed}dhcp
30 fi
31
32 ahdhcp_when_vap="$(uci get profile_$community.profile.adhoc_dhcp_when_vap)"
33 if [ "$supports_vap" = 0 ] || \
34         [ "$supports_vap" = 1 -a "$vap" = 1 -a "$ahdhcp_when_vap" = 1 ] || \
35         [ "$lan_is_olsr" = "1" -a "$lan_dhcp" = 1 ]; then
36         uci batch <<- EOF
37                 set dhcp.${netrenamed}ahdhcp="dhcp"
38                 set dhcp.${netrenamed}ahdhcp.ignore="0"
39                 set dhcp.${netrenamed}ahdhcp.interface="${netrenamed}ahdhcp"
40         EOF
41 fi
42 set_defaults "dhcp_" dhcp.${netrenamed}ahdhcp
43
44 uci_commitverbose "Setup DHCP for $netrenamed" dhcp
45
46