contrib/meshwizard: Load olsrd config earlier
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / setup_olsrd.sh
1 #!/bin/sh
2 # Sets up olsrd
3
4 . /lib/functions.sh
5 . $dir/functions.sh
6
7 # Clean the config, remove httpinfo and interface wlan
8 uci -q delete olsrd.olsrd_httpinfo
9 handle_interface() {
10 config_get interface "$1" interface
11 if [ "$interface" = "wlan" ]; then
12 uci delete olsrd.$1
13 fi
14 }
15 config_load olsrd
16 config_foreach handle_interface Interface
17 uci_commitverbose "Cleanup olsrd config" olsrd
18
19 #Rename olsrd basic settings
20 handle_olsrd() {
21 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
22 section_rename olsrd $1 olsrd
23 fi
24 }
25 config_foreach handle_olsrd olsrd
26
27 # Rename interface defaults
28 handle_interfacedefaults() {
29 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
30 section_rename olsrd $1 InterfaceDefaults
31 fi
32 }
33 config_foreach handle_interfacedefaults InterfaceDefaults
34
35 # Set basic olsrd settings
36 if [ "$profile_ipv6" = 1 ]; then
37 uci set olsrd.olsrd.IpVersion="6and4"
38 fi
39 uci_commitverbose "Setup olsr basic settings" olsrd
40
41
42 # Setup new InterfaceDefaults
43 uci set olsrd.InterfaceDefaults=InterfaceDefaults
44 set_defaults "olsr_interfacedefaults_" olsrd.InterfaceDefaults
45 uci_commitverbose "Setup olsr interface defaults" olsrd
46
47 # Rename nameservice, dyngw and httpinfo plugins
48
49 handle_plugin() {
50 config_get library "$1" library
51 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
52 new="$(echo $library | cut -d '.' -f 1)"
53 section_rename olsrd $1 $new
54 fi
55 }
56 config_foreach handle_plugin LoadPlugin
57
58 # Setup nameservice plugin
59 if [ -n "$profile_suffix" ]; then
60 suffix=".$profile_suffix"
61 else
62 suffix=".olsr"
63 fi
64 uci batch << EOF
65 set olsrd.olsrd_nameservice=LoadPlugin
66 set olsrd.olsrd_nameservice.library="olsrd_nameservice.so.0.3"
67 set olsrd.olsrd_nameservice.latlon_file="/var/run/latlon.js"
68 set olsrd.olsrd_nameservice.hosts_file="/var/etc/hosts.olsr"
69 set olsrd.olsrd_nameservice.sighup_pid_file="/var/run/dnsmasq.pid"
70 set olsrd.olsrd_nameservice.suffix="$suffix"
71 EOF
72
73 uci_commitverbose "Setup olsr nameservice plugin" olsrd
74
75 # Setup dyngw_plain
76
77 # If Sharing of Internet is enabled then enable dyngw_plain plugin
78
79 if [ "$general_sharenet" == 1 ]; then
80 uci set olsrd.dyngw_plain=LoadPlugin
81 uci set olsrd.dyngw_plain.ignore=0
82 uci set olsrd.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4"
83
84 uci_commitverbose "Setup olsrd_dyngw_plain plugin" olsrd
85 fi
86
87 # Setup watchdog
88 uci batch << EOF
89 set olsrd.olsrd_watchdog=LoadPlugin
90 set olsrd.olsrd_watchdog.library="olsrd_watchdog.so.0.1"
91 set olsrd.olsrd_watchdog.file="/var/run/olsrd.watchdog"
92 set olsrd.olsrd_watchdog.interval=30
93 EOF
94 uci_commitverbose "Setup olsr watchdog plugin" olsrd