|
|
@@ -1,315 +0,0 @@
|
|
1
|
|
-#!/bin/bash
|
|
2
|
|
-#
|
|
3
|
|
-# .---. . .
|
|
4
|
|
-# | | |
|
|
5
|
|
-# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
6
|
|
-# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
7
|
|
-# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
8
|
|
-#
|
|
9
|
|
-# Freedom in the Cloud
|
|
10
|
|
-#
|
|
11
|
|
-# Used to enable or disable BMX6 mesh protocol on wlanX
|
|
12
|
|
-#
|
|
13
|
|
-# License
|
|
14
|
|
-# =======
|
|
15
|
|
-#
|
|
16
|
|
-# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
|
|
17
|
|
-#
|
|
18
|
|
-# This program is free software: you can redistribute it and/or modify
|
|
19
|
|
-# it under the terms of the GNU Affero General Public License as published by
|
|
20
|
|
-# the Free Software Foundation, either version 3 of the License, or
|
|
21
|
|
-# (at your option) any later version.
|
|
22
|
|
-#
|
|
23
|
|
-# This program is distributed in the hope that it will be useful,
|
|
24
|
|
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25
|
|
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26
|
|
-# GNU Affero General Public License for more details.
|
|
27
|
|
-#
|
|
28
|
|
-# You should have received a copy of the GNU Affero General Public License
|
|
29
|
|
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30
|
|
-
|
|
31
|
|
-PROJECT_NAME='freedombone'
|
|
32
|
|
-COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
|
|
33
|
|
-
|
|
34
|
|
-# hotspot passphrase must be 5 characters or longer
|
|
35
|
|
-HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
|
|
36
|
|
-
|
|
37
|
|
-source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
|
|
38
|
|
-source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
|
|
39
|
|
-
|
|
40
|
|
-mesh_protocol_init
|
|
41
|
|
-
|
|
42
|
|
-update_wifi_adaptors
|
|
43
|
|
-
|
|
44
|
|
-if [ ! $IFACE ]; then
|
|
45
|
|
- echo $'No wlan adaptor'
|
|
46
|
|
- exit 0
|
|
47
|
|
-fi
|
|
48
|
|
-
|
|
49
|
|
-function status {
|
|
50
|
|
- bmx6 -cd8
|
|
51
|
|
-}
|
|
52
|
|
-
|
|
53
|
|
-function stop {
|
|
54
|
|
- if [ -z "$IFACE" ]; then
|
|
55
|
|
- echo 'error: unable to find wifi interface, not enabling BMX6 mesh'
|
|
56
|
|
- return
|
|
57
|
|
- fi
|
|
58
|
|
-
|
|
59
|
|
- systemctl stop dnsmasq
|
|
60
|
|
- systemctl disable dnsmasq
|
|
61
|
|
- systemctl stop bmx6
|
|
62
|
|
- systemctl disable bmx6
|
|
63
|
|
-
|
|
64
|
|
- if [ "$EIFACE" ]; then
|
|
65
|
|
- ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
|
|
66
|
|
- if [[ "$ethernet_connected" != "0" ]]; then
|
|
67
|
|
- systemctl stop hostapd
|
|
68
|
|
- ifconfig $EIFACE down -promisc
|
|
69
|
|
- fi
|
|
70
|
|
- fi
|
|
71
|
|
-
|
|
72
|
|
- ifconfig $IFACE down -promisc
|
|
73
|
|
-
|
|
74
|
|
- ifconfig $IFACE mtu 1500
|
|
75
|
|
- ifconfig $IFACE down
|
|
76
|
|
- iwconfig $IFACE mode managed
|
|
77
|
|
-
|
|
78
|
|
- if [ $IFACE_SECONDARY ]; then
|
|
79
|
|
- systemctl stop hostapd
|
|
80
|
|
- systemctl disable hostapd
|
|
81
|
|
- ifconfig $IFACE_SECONDARY mtu 1500
|
|
82
|
|
- ifconfig $IFACE_SECONDARY down
|
|
83
|
|
- iwconfig $IFACE_SECONDARY mode managed
|
|
84
|
|
- fi
|
|
85
|
|
-
|
|
86
|
|
- disable_mesh_firewall
|
|
87
|
|
-
|
|
88
|
|
- systemctl restart network-manager
|
|
89
|
|
-
|
|
90
|
|
- if [ -f $MESH_CURRENT_PROTOCOL ]; then
|
|
91
|
|
- rm $MESH_CURRENT_PROTOCOL
|
|
92
|
|
- fi
|
|
93
|
|
-}
|
|
94
|
|
-
|
|
95
|
|
-function verify {
|
|
96
|
|
- # TODO
|
|
97
|
|
- echo -n ''
|
|
98
|
|
-}
|
|
99
|
|
-
|
|
100
|
|
-function add_wifi_interface {
|
|
101
|
|
- ifname=$1
|
|
102
|
|
- ifssid=$WIFI_SSID
|
|
103
|
|
- if [ $2 ]; then
|
|
104
|
|
- ifssid=$2
|
|
105
|
|
- fi
|
|
106
|
|
- ifmode=ad-hoc
|
|
107
|
|
- if [ $3 ]; then
|
|
108
|
|
- ifmode=$3
|
|
109
|
|
- fi
|
|
110
|
|
- ifchannel=$CHANNEL
|
|
111
|
|
- if [ $4 ]; then
|
|
112
|
|
- ifchannel=$4
|
|
113
|
|
- fi
|
|
114
|
|
-
|
|
115
|
|
- ifconfig $ifname down
|
|
116
|
|
- ifconfig $ifname mtu 1500
|
|
117
|
|
- peermac=$(assign_peer_address)
|
|
118
|
|
- if [ ! $peermac ]; then
|
|
119
|
|
- echo $"Unable to obtain MAC address for $peermac on $ifname"
|
|
120
|
|
- return
|
|
121
|
|
- fi
|
|
122
|
|
- ifconfig $ifname hw ether $peermac
|
|
123
|
|
- echo $"$ifname assigned MAC address $peermac"
|
|
124
|
|
- iwconfig $ifname enc off
|
|
125
|
|
- iwconfig $ifname mode $ifmode essid $ifssid channel $ifchannel
|
|
126
|
|
- #iwconfig wlan0 mode ad-hoc ap 02:ca:ff:ee:ba:be channel 11 essid my-mesh-network
|
|
127
|
|
-
|
|
128
|
|
- ifconfig $ifname up
|
|
129
|
|
-}
|
|
130
|
|
-
|
|
131
|
|
-function start {
|
|
132
|
|
- update_wifi_adaptors
|
|
133
|
|
-
|
|
134
|
|
- if [ -z "$IFACE" ] ; then
|
|
135
|
|
- echo 'error: unable to find wifi interface, not enabling BMX6 mesh'
|
|
136
|
|
- exit 723657
|
|
137
|
|
- fi
|
|
138
|
|
- echo "info: enabling BMX6 mesh network $WIFI_SSID on $IFACE"
|
|
139
|
|
-
|
|
140
|
|
- systemctl stop network-manager
|
|
141
|
|
- sleep 5
|
|
142
|
|
-
|
|
143
|
|
- systemctl stop dnsmasq
|
|
144
|
|
- systemctl disable dnsmasq
|
|
145
|
|
-
|
|
146
|
|
- # remove an avahi service which isn't used
|
|
147
|
|
- if [ -f /etc/avahi/services/udisks.service ]; then
|
|
148
|
|
- sudo rm /etc/avahi/services/udisks.service
|
|
149
|
|
- fi
|
|
150
|
|
-
|
|
151
|
|
- global_rate_limit
|
|
152
|
|
-
|
|
153
|
|
- # Might have to re-enable wifi
|
|
154
|
|
- rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
|
|
155
|
|
-
|
|
156
|
|
- secondary_wifi_available=
|
|
157
|
|
- if [ $IFACE_SECONDARY ]; then
|
|
158
|
|
- if [[ $IFACE != $IFACE_SECONDARY ]]; then
|
|
159
|
|
- if [ -d /etc/hostapd ]; then
|
|
160
|
|
- if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
|
|
161
|
|
- secondary_wifi_available=1
|
|
162
|
|
- else
|
|
163
|
|
- echo $'Hotspot passphrase is too short'
|
|
164
|
|
- fi
|
|
165
|
|
- fi
|
|
166
|
|
- fi
|
|
167
|
|
- fi
|
|
168
|
|
-
|
|
169
|
|
- add_wifi_interface $IFACE $WIFI_SSID ad-hoc $CHANNEL
|
|
170
|
|
- ifconfig $IFACE up promisc
|
|
171
|
|
-
|
|
172
|
|
- if [ ! $secondary_wifi_available ]; then
|
|
173
|
|
- sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE}|g" /etc/systemd/system/bmx6.service
|
|
174
|
|
- else
|
|
175
|
|
- sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
|
|
176
|
|
- fi
|
|
177
|
|
-
|
|
178
|
|
- # avahi on ipv6
|
|
179
|
|
- sed -i 's|use-ipv4=.*|use-ipv4=no|g' /etc/avahi/avahi-daemon.conf
|
|
180
|
|
- sed -i 's|use-ipv6=.*|use-ipv6=yes|g' /etc/avahi/avahi-daemon.conf
|
|
181
|
|
- sed -i 's|#disallow-other-stacks=.*|disallow-other-stacks=no|g' /etc/avahi/avahi-daemon.conf
|
|
182
|
|
- sed -i 's|disallow-other-stacks=.*|disallow-other-stacks=no|g' /etc/avahi/avahi-daemon.conf
|
|
183
|
|
- sed -i 's|#publish-a-on-ipv6=.*|publish-a-on-ipv6=yes|g' /etc/avahi/avahi-daemon.conf
|
|
184
|
|
- sed -i 's|publish-a-on-ipv6=.*|publish-a-on-ipv6=yes|g' /etc/avahi/avahi-daemon.conf
|
|
185
|
|
- systemctl restart avahi-daemon
|
|
186
|
|
-
|
|
187
|
|
- systemctl daemon-reload
|
|
188
|
|
- systemctl enable bmx6
|
|
189
|
|
-
|
|
190
|
|
- # NOTE: Don't connect the secondary wifi device. hostapd will handle that by itself
|
|
191
|
|
-
|
|
192
|
|
- ethernet_connected='0'
|
|
193
|
|
- if [ "$EIFACE" ] ; then
|
|
194
|
|
- ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
|
|
195
|
|
- if [[ "$ethernet_connected" != "0" ]]; then
|
|
196
|
|
- echo $'Trying ethernet bridge to the internet'
|
|
197
|
|
- ifconfig $EIFACE up promisc
|
|
198
|
|
- echo $'End of ethernet bridge'
|
|
199
|
|
- else
|
|
200
|
|
- echo $"$EIFACE is not connected"
|
|
201
|
|
- fi
|
|
202
|
|
- fi
|
|
203
|
|
-
|
|
204
|
|
- enable_mesh_seconary_wifi
|
|
205
|
|
-
|
|
206
|
|
- enable_mesh_firewall
|
|
207
|
|
-
|
|
208
|
|
- systemctl restart avahi-daemon
|
|
209
|
|
-
|
|
210
|
|
- enable_mesh_scuttlebot
|
|
211
|
|
- enable_mesh_tor
|
|
212
|
|
-
|
|
213
|
|
-
|
|
214
|
|
- sed -i "s|server_name .*|server_name ${HOSTNAME}.local;|g" /etc/nginx/sites-available/git_ssb
|
|
215
|
|
-
|
|
216
|
|
- systemctl restart nginx
|
|
217
|
|
- systemctl restart bmx6
|
|
218
|
|
-
|
|
219
|
|
- verify
|
|
220
|
|
-
|
|
221
|
|
- echo "bmx6" > $MESH_CURRENT_PROTOCOL
|
|
222
|
|
-}
|
|
223
|
|
-
|
|
224
|
|
-function monitor {
|
|
225
|
|
- if [ -z "$IFACE" ] ; then
|
|
226
|
|
- echo 'error: unable to find wifi interface, not enabling BMX6 mesh'
|
|
227
|
|
- exit 723657
|
|
228
|
|
- fi
|
|
229
|
|
-
|
|
230
|
|
- clear
|
|
231
|
|
- echo ''
|
|
232
|
|
- echo $'*** Stopping network ***'
|
|
233
|
|
- echo ''
|
|
234
|
|
-
|
|
235
|
|
- stop
|
|
236
|
|
-
|
|
237
|
|
- echo "info: monitoring mesh network $WIFI_SSID on $IFACE"
|
|
238
|
|
-
|
|
239
|
|
- systemctl stop network-manager
|
|
240
|
|
- sleep 5
|
|
241
|
|
-
|
|
242
|
|
- clear
|
|
243
|
|
- echo ''
|
|
244
|
|
- echo $'*** Setting firewall rate limit ***'
|
|
245
|
|
- echo ''
|
|
246
|
|
-
|
|
247
|
|
- global_rate_limit
|
|
248
|
|
-
|
|
249
|
|
- clear
|
|
250
|
|
- echo ''
|
|
251
|
|
- echo $'*** Enabling wifi adaptor in monitor mode ***'
|
|
252
|
|
- echo ''
|
|
253
|
|
-
|
|
254
|
|
- # Might have to re-enable wifi
|
|
255
|
|
- rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
|
|
256
|
|
-
|
|
257
|
|
- ifconfig $IFACE down
|
|
258
|
|
- ifconfig $IFACE mtu 1500
|
|
259
|
|
- ifconfig $IFACE hw ether $(assign_peer_address)
|
|
260
|
|
- iwconfig $IFACE enc off
|
|
261
|
|
- iwconfig $IFACE mode monitor channel $CHANNEL
|
|
262
|
|
- sleep 1
|
|
263
|
|
- iwconfig $IFACE ap $CELLID
|
|
264
|
|
-
|
|
265
|
|
- ifconfig $IFACE up
|
|
266
|
|
-
|
|
267
|
|
- horst -i $IFACE
|
|
268
|
|
-
|
|
269
|
|
- clear
|
|
270
|
|
- echo ''
|
|
271
|
|
- echo $'*** Restarting the network daemon. This may take a while. ***'
|
|
272
|
|
- echo ''
|
|
273
|
|
-
|
|
274
|
|
- start
|
|
275
|
|
-}
|
|
276
|
|
-
|
|
277
|
|
-if ! grep -q "$IFACE" /proc/net/dev; then
|
|
278
|
|
- echo 'Interface $IFACE was not found'
|
|
279
|
|
- stop
|
|
280
|
|
- exit 1
|
|
281
|
|
-fi
|
|
282
|
|
-
|
|
283
|
|
-case "$1" in
|
|
284
|
|
- start|stop|status|monitor)
|
|
285
|
|
- $1
|
|
286
|
|
- ;;
|
|
287
|
|
- restart)
|
|
288
|
|
- clear
|
|
289
|
|
- echo ''
|
|
290
|
|
- echo $'*** Stopping BMX6 mesh network connection ***'
|
|
291
|
|
- echo ''
|
|
292
|
|
- stop
|
|
293
|
|
- sleep 10
|
|
294
|
|
- clear
|
|
295
|
|
- echo ''
|
|
296
|
|
- echo $'*** Starting BMX6 mesh network connection ***'
|
|
297
|
|
- echo ''
|
|
298
|
|
- start
|
|
299
|
|
- ;;
|
|
300
|
|
- ping)
|
|
301
|
|
- traceroute6 -n -q 1 $2
|
|
302
|
|
- ;;
|
|
303
|
|
- data)
|
|
304
|
|
- bmx6 -lc traffic=$IFACE
|
|
305
|
|
- ;;
|
|
306
|
|
- ls|list)
|
|
307
|
|
- avahi-browse -atl
|
|
308
|
|
- ;;
|
|
309
|
|
- *)
|
|
310
|
|
- echo "error: invalid parameter $1"
|
|
311
|
|
- echo 'usage: $0 {start|stop|restart|status|ping|ls|list}'
|
|
312
|
|
- exit 2
|
|
313
|
|
- ;;
|
|
314
|
|
-esac
|
|
315
|
|
-exit 0
|