707178d2765672f63f19e710b576840bdfa59ff1
[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.interface="${netrenamed}dhcp"
27         EOF
28         set_defaults "dhcp_" dhcp.${netrenamed}dhcp
29 fi
30
31 ahdhcp_when_vap="$(uci get profile_$community.profile.adhoc_dhcp_when_vap)"
32 if [ "$supports_vap" = 0 ] || [ "$supports_vap" = 1 -a "$vap" = 1 -a "$ahdhcp_when_vap" = 1 ]; then
33         uci batch <<- EOF
34                 set dhcp.${netrenamed}ahdhcp="dhcp"
35                 set dhcp.${netrenamed}ahdhcp.interface="${netrenamed}ahdhcp"
36         EOF
37 fi
38 set_defaults "dhcp_" dhcp.${netrenamed}ahdhcp
39
40 uci_commitverbose "Setup DHCP for $netrenamed" dhcp
41
42