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