contrib/meshwizard: add support for setting up qos on wan
[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 . /lib/functions.sh
13
14 echo "
15 /* Meshwizard 0.2.0 */
16 "
17
18 # config
19 export dir="/usr/bin/meshwizard"
20 . $dir/functions.sh
21 [ -f /proc/net/ipv6_route ] && export has_ipv6=1
22
23 # Check which packages we have installed
24 export has_luci=FALSE
25 opkg list_installed |grep luci-mod-admin > /dev/null && export has_luci=TRUE
26 export has_luci_splash=FALSE
27 opkg list_installed |grep luci-app-splash > /dev/null && export has_luci_splash=TRUE
28
29 # Check whether we want to cleanup/restore uci config before setting new options
30 cleanup=$(uci -q get meshwizard.general.cleanup)
31 [ "$cleanup" == 1 ] && $dir/helpers/restore_default_config.sh
32
33 # Rename wifi interfaces
34 $dir/helpers/rename-wifi.sh
35
36 # Get community
37 community=$(uci -q get meshwizard.community.name || uci -q get freifunk.community.name)
38 [ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1
39 export community="$community"
40 echo $community
41
42 # Get a list of networks we need to setup
43 networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq)
44 export networks
45 [ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1
46
47 # Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community
48 # then /etc/config/meshwizard
49 # last will overwrite first
50
51 $dir/helpers/read_defaults.sh $community > /tmp/meshwizard.tmp
52 while read line; do
53         export "${line//\"/}"
54 done < /tmp/meshwizard.tmp
55
56 # Do config
57 $dir/helpers/initial_config.sh
58 $dir/helpers/setup_dnsmasq.sh
59 $dir/helpers/setup_system.sh
60 $dir/helpers/setup_olsrd.sh
61 $dir/helpers/setup_firewall.sh
62 $dir/helpers/setup_ssh.sh
63 $dir/helpers/setup_uhttpd.sh
64 $dir/helpers/setup_widgets.sh
65
66 if [ "$wan_proto" == "static" ] && [ -n "$wan_ip4addr" ] && [ -n "$wan_netmask" ]; then
67         $dir/helpers/setup_wan_static.sh
68 fi
69
70 if [ "$wan_proto" == "dhcp" ]; then
71         $dir/helpers/setup_wan_dhcp.sh
72 fi
73
74 if [ -n "$wan_down" -a -n "$wan_up" ]; then
75         $dir/helpers/setup_qos.sh
76 fi
77
78 if [ "$lan_proto" == "static" ] && [ -n "$lan_ip4addr" ] && [ -n "$lan_netmask" ]; then
79         $dir/helpers/setup_lan_static.sh
80 fi
81
82 if [ "$ipv6_enabled" == 1 ] && [ "$has_ipv6" = 1 ]; then
83         $dir/helpers/setup_lan_ipv6.sh
84         # Setup auto-ipv6
85         if [ -n "$(echo "$ipv6_config" |grep auto-ipv6)" ]; then
86                 $dir/helpers/setup_auto-ipv6.sh
87         fi
88 fi
89
90 # Setup policyrouting if internet sharing is disabled and wan is not used for olsrd
91 # Always disable it first to make sure its disabled when the user decied to share his internet
92 uci set freifunk-policyrouting.pr.enable=0
93 if [ ! "$general_sharenet" == 1 ] && [ ! "$(uci -q get meshwizard.netconfig.wan_proto)" == "olsr" ]; then
94         $dir/helpers/setup_policyrouting.sh
95 fi
96
97 # Configure found networks
98 for net in $networks; do
99         # radioX devices need to be renamed
100         netrenamed="${net/radio/wireless}"
101         export netrenamed
102
103         if [ ! "$net" == "wan" ] && [ ! "$net" == "lan" ]; then
104                 $dir/helpers/setup_wifi.sh $net
105                 # check if this net supports vap
106                 /sbin/wifi # wifi needs to be up for the check
107                 export supports_vap="0"
108                 type="$(uci -q get wireless.$net.type)"
109                 [ -n "$type" ] && $dir/helpers/supports_vap.sh $net $type && export supports_vap=1
110                 if [ "$supports_vap" = 1 ]; then
111                         $dir/helpers/setup_wifi_vap.sh $net
112                 fi
113         fi
114
115         $dir/helpers/setup_network.sh $net
116
117         $dir/helpers/setup_olsrd_interface.sh $net
118
119         net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
120         if [ "$net_dhcp" == 1 ]; then
121                 $dir/helpers/setup_dhcp.sh $net
122         fi
123
124         $dir/helpers/setup_splash.sh $net
125         $dir/helpers/setup_firewall_interface.sh $net
126
127         if [ -n "$(echo "$ipv6_config" |grep auto-ipv6)" ]; then
128                 $dir/helpers/setup_auto-ipv6-interface.sh $net
129         fi
130 done
131
132 ##### postinstall script
133
134 [ -f /etc/rc.local.meshkitpostinstall ] && /etc/rc.local.meshkitpostinstall
135
136
137 ##### Reboot the router (because simply restarting services gave errors)
138
139 echo "+ The wizard has finished and the router will reboot now."
140
141 reboot