a5f9a2fb9f06024919274a6732261e65cbd8629e
[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.2 +++
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 # system
53         echo "++++ system config"
54         $dir/helpers/setup_system.sh
55
56 # freifunk
57         echo "++++ /etc/config/freifunk config"
58         $dir/helpers/setup_freifunk.sh
59
60 # Configure found networks
61 for net in $networks; do
62
63         netrenamed="${net/radio/wireless}"
64         export netrenamed
65
66         echo "++++ Configure interface $net"
67
68         config="network"
69         echo "$(msg_start $config)"
70         $dir/helpers/setup_network.sh $net
71
72         config="wireless"
73         echo "$(msg_start $config)"
74         $dir/helpers/setup_wifi.sh $net
75
76         config="OLSRd"
77         echo "$(msg_start $config)"
78         $dir/helpers/setup_olsrd.sh $net
79
80         net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
81         if [ "$net_dhcp" == 1 ]; then
82                 config="DHCP"
83                 echo "$(msg_start $config)"
84                 $dir/helpers/setup_dhcp.sh $net
85         fi
86
87         config="luci_splash"
88         echo "$(msg_start $config)"
89         $dir/helpers/setup_splash.sh $net
90
91         config="firewall"
92         echo "$(msg_start $config)"
93         $dir/helpers/setup_firewall.sh $net
94
95         echo "  Configuration of $net finished."
96 done
97
98 ##### Reboot the router (because simply restarting services gave errors)
99
100 reboot