contrib/meshwizard: Fix variable for sharenet so policyrouting is setup correctly
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / wizard.sh
1 #!/bin/sh
2
3 # This collection of scripts will take settings from /etc/config/meshwizard, /etc/config/freifunk
4 # and /etc/config/profile_<community> and setup the router to participate in wireless mesh networks
5
6 # Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
7
8 # Licensed under the Apache License, Version 2.0 (the "License")
9 # You may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
11
12 . /etc/functions.sh
13
14 echo "
15 /* Meshwizard 0.0.4 */
16 "
17
18 # config
19 export dir="/usr/bin/meshwizard"
20 . $dir/functions.sh
21
22 # Check which packages we have installed
23 export has_luci=FALSE
24 opkg list_installed |grep luci-mod-admin > /dev/null && export has_luci=TRUE
25 export has_luci_splash=FALSE
26 opkg list_installed |grep luci-app-splash > /dev/null && export has_luci_splash=TRUE
27
28 # Check whether we want to cleanup/restore uci config before setting new options
29 cleanup=$(uci -q get meshwizard.general.cleanup)
30 [ "$cleanup" == 1 ] && $dir/helpers/restore_default_config.sh
31
32 # Rename wifi interfaces
33 $dir/helpers/rename-wifi.sh
34
35 # Get community
36 community=$(uci -q get meshwizard.community.name || uci -q get freifunk.community.name)
37 [ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1
38 export community="$community"
39 echo $community
40
41 # Get a list of networks we need to setup
42 networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq)
43 export networks
44 [ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1
45
46 # Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community
47 # then /etc/config/meshwizard
48 # last will overwrite first
49
50 $dir/helpers/read_defaults.sh $community > /tmp/meshwizard.tmp
51 while read line; do
52 export "${line//\"/}"
53 done < /tmp/meshwizard.tmp
54
55 # Do config
56 $dir/helpers/initial_config.sh
57 $dir/helpers/setup_dnsmasq.sh
58 $dir/helpers/setup_system.sh
59 $dir/helpers/setup_olsrd.sh
60 $dir/helpers/setup_firewall.sh
61
62 if [ "$wan_proto" == "static" ] && [ -n "$wan_ip4addr" ] && [ -n "$wan_netmask" ]; then
63 $dir/helpers/setup_wan_static.sh
64 fi
65
66 if [ "$lan_proto" == "static" ] && [ -n "$lan_ip4addr" ] && [ -n "$lan_netmask" ]; then
67 $dir/helpers/setup_lan_static.sh
68 fi
69
70 # Setup policyrouting if internet sharing is disabled and wan is not used for olsrd
71 # Always disable it first to make sure its disabled when the user decied to share his internet
72 uci set freifunk-policyrouting.pr.enable=0
73 if [ ! "$general_sharenet" == 1 ] && [ ! "$(uci -q get meshwizard.netconfig.wan_proto)" == "olsr" ]; then
74 $dir/helpers/setup_policyrouting.sh
75 fi
76
77 # Configure found networks
78 for net in $networks; do
79 # radioX devices need to be renamed
80 netrenamed="${net/radio/wireless}"
81 export netrenamed
82 $dir/helpers/setup_network.sh $net
83 if [ ! "$net" == "wan" ] && [ ! "$net" == "lan" ]; then
84 $dir/helpers/setup_wifi.sh $net
85 fi
86 $dir/helpers/setup_olsrd_interface.sh $net
87
88 net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
89 if [ "$net_dhcp" == 1 ]; then
90 $dir/helpers/setup_dhcp.sh $net
91 fi
92
93 $dir/helpers/setup_splash.sh $net
94 $dir/helpers/setup_firewall_interface.sh $net
95 done
96
97 ##### Reboot the router (because simply restarting services gave errors)
98
99 reboot