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