Add new meshwizard (WIP)
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / wizard.sh
1 #!/bin/sh
2 # This script will take settings from /etc/config/meshwizard, /etc/config/freifunk and /etc/config/profile_<selected in freifunk>
3 # and setup the router to participate in wireless mesh networks
4
5 . /etc/functions.sh
6
7 # config
8 export dir="/usr/bin/meshwizard"
9 . $dir/functions.sh
10 debug=1
11
12 # Rename wifi interfaces
13 echo "++++ Renaming wifi-devices in /etc/config/meshwizard"
14 $dir/helpers/rename-wifi.sh
15
16 # Firstboot/initial config
17 echo "++++ Initial config"
18 $dir/helpers/initial_config.sh
19
20 # Get community
21 export community=$(uci get freifunk.community.name)
22 [ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1
23
24 # Check whether we want to cleanup uci config before setting new options or not
25 cleanup=$(uci -q get meshwizard.general.cleanup)
26
27 [ "$cleanup" == 1 ] && export cleanup=1
28
29 # Get a list of networks we need to setup
30 networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq)
31 export networks
32
33 [ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1
34
35 echo "+++ wizard 0.0.1 +++
36 Community=$community
37 Network(s)=$networks"
38
39 # Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community,
40 # last will overwrite first
41
42
43 $dir/helpers/read_defaults.sh $community > /tmp/meshwizard.tmp
44 while read line; do
45 export "${line//\"/}"
46 done < /tmp/meshwizard.tmp
47
48 # dnsmasq
49 echo "++++ dnsmasq config"
50 $dir/helpers/setup_dnsmasq.sh
51
52 # Configure found networks
53 for net in $networks; do
54
55 netrenamed="${net/radio/wireless}"
56 export netrenamed
57
58 echo "++++ Configure interface $net"
59
60 config="network"
61 echo "$(msg_start $config)"
62 $dir/helpers/setup_network.sh $net
63
64 config="wireless"
65 echo "$(msg_start $config)"
66 $dir/helpers/setup_wifi.sh $net
67
68 config="OLSRd"
69 echo "$(msg_start $config)"
70 $dir/helpers/setup_olsrd.sh $net
71
72 net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
73 if [ "$net_dhcp" == 1 ]; then
74 config="DHCP"
75 echo "$(msg_start $config)"
76 $dir/helpers/setup_dhcp.sh $net
77 fi
78
79 config="luci_splash"
80 echo "$(msg_start $config)"
81 $dir/helpers/setup_splash.sh $net
82
83 config="firewall"
84 echo "$(msg_start $config)"
85 $dir/helpers/setup_firewall.sh $net
86
87 echo " Configuration of $net finished."
88 done
89
90 ##### Restart services
91 services="network olsrd dnsmasq luci_splash"
92 echo " Restarting services:"
93 for s in $services; do
94 /etc/init.d/$s restart >/dev/null 2>&1
95 echo " * $s"
96 done