9d18a582acc670367399449f4f71e93e77f25da7
[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 local protocols="4"
8 if [ "$ipv6_enabled" = 1 ] && [ "$has_ipv6" == "1" ]; then
9 protocols="4 6"
10 fi
11
12 clean_config() {
13 # Clean the config, remove interface wlan
14 handle_interface() {
15 config_get interface "$1" interface
16 if [ "$interface" = "wlan" ]; then
17 uci delete $cfg.$1
18 fi
19 }
20 config_foreach handle_interface Interface
21 }
22
23 rename_olsrd() {
24 #Rename olsrd basic settings
25 handle_olsrd() {
26 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
27 section_rename $cfg $1 olsrd
28 fi
29 }
30 config_foreach handle_olsrd olsrd
31 }
32
33 rename_interface_defaults() {
34 # Rename interface defaults
35 handle_interfacedefaults() {
36 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
37 section_rename $cfg $1 InterfaceDefaults
38 fi
39 }
40 config_foreach handle_interfacedefaults InterfaceDefaults
41 }
42
43 cleanup_plugins() {
44 # Rename nameservice, dyngw and httpinfo plugins
45 handle_plugin() {
46 config_get library "$1" library
47 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
48 new="$(echo $library | cut -d '.' -f 1)"
49 section_rename $cfg "$1" "$new"
50 fi
51 }
52 config_foreach handle_plugin LoadPlugin
53 uci -q delete $cfg.olsrd_httpinfo
54 uci -q delete $cfg.olsrd_dyn_gw
55 }
56
57 setup_nameservice() {
58 # Setup nameservice plugin
59 if [ -n "$profile_suffix" ]; then
60 suffix=".$profile_suffix"
61 else
62 suffix=".olsr"
63 fi
64 local llfile="/var/run/latlon.js"
65 local hosts="/var/etc/hosts.olsr"
66 local services="/var/run/services_olsr"
67
68 if [ "$proto" = "6" ]; then
69 local llfile="/var/run/latlon.js.ipv6"
70 local hosts="/var/etc/hosts.olsr.ipv6"
71 local services="/var/run/services_olsr.ipv6"
72 fi
73
74 uci batch <<- EOF
75 set $cfg.olsrd_nameservice=LoadPlugin
76 set $cfg.olsrd_nameservice.library="olsrd_nameservice.so.0.3"
77 set $cfg.olsrd_nameservice.latlon_file="$llfile"
78 set $cfg.olsrd_nameservice.hosts_file="$hosts"
79 set $cfg.olsrd_nameservice.sighup_pid_file="/var/run/dnsmasq.pid"
80 set $cfg.olsrd_nameservice.services_file="$services"
81 set $cfg.olsrd_nameservice.suffix="$suffix"
82 EOF
83
84 uci_commitverbose "Setup olsr nameservice plugin" $cfg
85 }
86
87 setup_dyngw_plain() {
88 # Setup dyngw_plain
89 # If Sharing of Internet is enabled then enable dyngw_plain plugin
90
91 if [ "$general_sharenet" == 1 ]; then
92 uci set $cfg.dyngw_plain=LoadPlugin
93 uci set $cfg.dyngw_plain.ignore=0
94 uci set $cfg.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4"
95 uci_commitverbose "Setup olsrd_dyngw_plain plugin" $cfg
96 fi
97
98 }
99
100 setup_watchdog() {
101 # Setup watchdog
102 local watchdogfile="/var/run/olsrd.watchdog"
103 if [ "$proto" = "6" ]; then
104 watchdogfile="/var/run/olsrd.watchdog.ipv6"
105 fi
106
107 uci batch <<- EOF
108 set $cfg.olsrd_watchdog=LoadPlugin
109 set $cfg.olsrd_watchdog.library="olsrd_watchdog.so.0.1"
110 set $cfg.olsrd_watchdog.file="$watchdogfile"
111 set $cfg.olsrd_watchdog.interval=30
112 EOF
113 uci_commitverbose "Setup olsr watchdog plugin" $cfg
114
115 }
116
117 setup_jsoninfo() {
118 # Setup jsoninfo
119 uci batch <<- EOF
120 set $cfg.olsrd_jsoninfo=LoadPlugin
121 set $cfg.olsrd_jsoninfo.library="olsrd_jsoninfo.so.0.0"
122 EOF
123 uci_commitverbose "Setup olsr jsoninfo plugin" $cfg
124 }
125
126
127 for proto in $protocols; do
128 cfg="olsrd"
129 [ "$proto" == "6" ] && cfg="olsrd6"
130 config_load $cfg
131 clean_config
132 rename_olsrd
133 cleanup_plugins
134
135 uci set $cfg.olsrd.IpVersion="$proto"
136 uci set $cfg.InterfaceDefaults=InterfaceDefaults
137 set_defaults "olsr_interfacedefaults_" $cfg.InterfaceDefaults
138 uci_commitverbose "Cleanup olsrd config" $cfg
139
140 setup_nameservice
141 setup_dyngw_plain
142 setup_watchdog
143 setup_jsoninfo
144
145 done