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