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