contrib/meshwizard: Cleanup and add ssid_scheme option
[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 echo "
8 Meshwizard 0.0.3
9 "
10
11 # config
12 export dir="/usr/bin/meshwizard"
13 . $dir/functions.sh
14 debug=1
15
16 # Rename wifi interfaces
17         echo "+ Renaming wifi-devices in /etc/config/meshwizard"
18         $dir/helpers/rename-wifi.sh
19
20 # Firstboot/initial config
21         echo "+ Initial config"
22         $dir/helpers/initial_config.sh
23
24 # Get community
25 export community=$(uci get freifunk.community.name)
26 [ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1
27
28 # Check whether we want to cleanup uci config before setting new options or not
29 cleanup=$(uci -q get meshwizard.general.cleanup)
30
31 [ "$cleanup" == 1 ] && export cleanup=1
32
33 # Get a list of networks we need to setup
34 networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq)
35 export networks
36
37 [ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1
38
39 echo "    Community=$community
40     Network(s)=$networks"
41
42 # Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community,
43 # last will overwrite first
44
45
46 $dir/helpers/read_defaults.sh $community > /tmp/meshwizard.tmp
47 while read line; do
48         export "${line//\"/}"
49 done < /tmp/meshwizard.tmp
50
51 $dir/helpers/setup_dnsmasq.sh
52 $dir/helpers/setup_system.sh
53 $dir/helpers/setup_freifunk.sh
54
55 # Configure found networks
56 for net in $networks; do
57
58         netrenamed="${net/radio/wireless}"
59         export netrenamed
60
61         $dir/helpers/setup_network.sh $net
62         $dir/helpers/setup_wifi.sh $net
63         $dir/helpers/setup_olsrd.sh $net
64
65         net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
66         if [ "$net_dhcp" == 1 ]; then
67                 $dir/helpers/setup_dhcp.sh $net
68         fi
69
70         $dir/helpers/setup_splash.sh $net
71         $dir/helpers/setup_firewall.sh $net
72 done
73
74 ##### Reboot the router (because simply restarting services gave errors)
75
76 reboot