|
@@ -8,7 +8,7 @@
|
8
|
8
|
#
|
9
|
9
|
# Freedom in the Cloud
|
10
|
10
|
#
|
11
|
|
-# Used to enable or disable batman mesh protocol on wlanX
|
|
11
|
+# Used to enable or disable batman mesh protocol on a given interface
|
12
|
12
|
#
|
13
|
13
|
# License
|
14
|
14
|
# =======
|
|
@@ -34,22 +34,12 @@ COMPLETION_FILE="/root/${PROJECT_NAME}-completed.txt"
|
34
|
34
|
# hotspot passphrase must be 5 characters or longer
|
35
|
35
|
HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
|
36
|
36
|
|
|
37
|
+# The type of interface which the mesh will run on
|
|
38
|
+MESH_INTERFACE_TYPE='wlan'
|
|
39
|
+
|
37
|
40
|
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
|
38
|
41
|
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
|
39
|
42
|
|
40
|
|
-mesh_protocol_init
|
41
|
|
-update_wifi_adaptors
|
42
|
|
-
|
43
|
|
-if [ ! "$IFACE" ]; then
|
44
|
|
- echo $'No wlan adaptor'
|
45
|
|
- exit 0
|
46
|
|
-fi
|
47
|
|
-
|
48
|
|
-if [ -e /etc/default/batctl ]; then
|
49
|
|
- # shellcheck disable=SC1091
|
50
|
|
- . /etc/default/batctl
|
51
|
|
-fi
|
52
|
|
-
|
53
|
43
|
function status {
|
54
|
44
|
batctl o
|
55
|
45
|
|
|
@@ -84,15 +74,17 @@ function stop {
|
84
|
74
|
|
85
|
75
|
# shellcheck disable=SC2153
|
86
|
76
|
if [ "$EIFACE" ]; then
|
87
|
|
- brctl delif "$BRIDGE" bat0
|
88
|
|
- ifconfig "$BRIDGE" down || true
|
89
|
|
- ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
|
90
|
|
- if [[ "$ethernet_connected" != "0" ]]; then
|
91
|
|
- systemctl stop hostapd
|
92
|
|
- brctl delif "$BRIDGE" "$EIFACE"
|
93
|
|
- ifconfig "$EIFACE" down -promisc
|
|
77
|
+ if [[ "$EIFACE" != "$IFACE" ]] ; then
|
|
78
|
+ brctl delif "$BRIDGE" bat0
|
|
79
|
+ ifconfig "$BRIDGE" down || true
|
|
80
|
+ ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
|
|
81
|
+ if [[ "$ethernet_connected" != "0" ]]; then
|
|
82
|
+ systemctl stop hostapd
|
|
83
|
+ brctl delif "$BRIDGE" "$EIFACE"
|
|
84
|
+ ifconfig "$EIFACE" down -promisc
|
|
85
|
+ fi
|
|
86
|
+ brctl delbr "$BRIDGE"
|
94
|
87
|
fi
|
95
|
|
- brctl delbr "$BRIDGE"
|
96
|
88
|
fi
|
97
|
89
|
|
98
|
90
|
ifconfig bat0 down -promisc
|
|
@@ -100,7 +92,9 @@ function stop {
|
100
|
92
|
batctl if del "$IFACE"
|
101
|
93
|
ifconfig "$IFACE" mtu 1500
|
102
|
94
|
ifconfig "$IFACE" down
|
103
|
|
- iwconfig "$IFACE" mode managed
|
|
95
|
+ if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
|
|
96
|
+ iwconfig "$IFACE" mode managed
|
|
97
|
+ fi
|
104
|
98
|
|
105
|
99
|
if [ "$IFACE_SECONDARY" ]; then
|
106
|
100
|
systemctl stop hostapd
|
|
@@ -108,7 +102,9 @@ function stop {
|
108
|
102
|
batctl if del "$IFACE_SECONDARY"
|
109
|
103
|
ifconfig "$IFACE_SECONDARY" mtu 1500
|
110
|
104
|
ifconfig "$IFACE_SECONDARY" down
|
111
|
|
- iwconfig "$IFACE_SECONDARY" mode managed
|
|
105
|
+ if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
|
|
106
|
+ iwconfig "$IFACE_SECONDARY" mode managed
|
|
107
|
+ fi
|
112
|
108
|
fi
|
113
|
109
|
|
114
|
110
|
rmmod batman-adv
|
|
@@ -159,8 +155,10 @@ function add_wifi_interface {
|
159
|
155
|
fi
|
160
|
156
|
ifconfig "$ifname" hw ether "$peermac"
|
161
|
157
|
echo $"$ifname assigned MAC address $peermac"
|
162
|
|
- iwconfig "$ifname" enc off
|
163
|
|
- iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel"
|
|
158
|
+ if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
|
|
159
|
+ iwconfig "$ifname" enc off
|
|
160
|
+ iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel"
|
|
161
|
+ fi
|
164
|
162
|
|
165
|
163
|
batctl if add "$ifname"
|
166
|
164
|
ifconfig "$ifname" up
|
|
@@ -168,7 +166,7 @@ function add_wifi_interface {
|
168
|
166
|
|
169
|
167
|
# shellcheck disable=SC2120
|
170
|
168
|
function start {
|
171
|
|
- update_wifi_adaptors
|
|
169
|
+ update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
|
172
|
170
|
|
173
|
171
|
if [ -z "$IFACE" ] ; then
|
174
|
172
|
echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
|
|
@@ -194,13 +192,15 @@ function start {
|
194
|
192
|
rfkill unblock "$(rfkill list|awk -F: "/phy/ {print $1}")" || true
|
195
|
193
|
|
196
|
194
|
secondary_wifi_available=
|
197
|
|
- if [ "$IFACE_SECONDARY" ]; then
|
198
|
|
- if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then
|
199
|
|
- if [ -d /etc/hostapd ]; then
|
200
|
|
- if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
|
201
|
|
- secondary_wifi_available=1
|
202
|
|
- else
|
203
|
|
- echo $'Hotspot passphrase is too short'
|
|
195
|
+ if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
|
|
196
|
+ if [ "$IFACE_SECONDARY" ]; then
|
|
197
|
+ if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then
|
|
198
|
+ if [ -d /etc/hostapd ]; then
|
|
199
|
+ if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
|
|
200
|
+ secondary_wifi_available=1
|
|
201
|
+ else
|
|
202
|
+ echo $'Hotspot passphrase is too short'
|
|
203
|
+ fi
|
204
|
204
|
fi
|
205
|
205
|
fi
|
206
|
206
|
fi
|
|
@@ -229,21 +229,23 @@ function start {
|
229
|
229
|
ifconfig bat0 0.0.0.0
|
230
|
230
|
ethernet_connected='0'
|
231
|
231
|
if [ "$EIFACE" ] ; then
|
232
|
|
- ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
|
233
|
|
- if [[ "$ethernet_connected" != "0" ]]; then
|
234
|
|
- echo $'Trying ethernet bridge to the internet'
|
235
|
|
- brctl addif "$BRIDGE" "$EIFACE"
|
236
|
|
- ifconfig "$EIFACE" 0.0.0.0
|
237
|
|
- ifconfig "$EIFACE" up promisc
|
238
|
|
- echo $'End of ethernet bridge'
|
239
|
|
-
|
240
|
|
- sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
|
241
|
|
- sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
|
242
|
|
- sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service
|
243
|
|
- sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service
|
244
|
|
- systemctl daemon-reload
|
245
|
|
- else
|
246
|
|
- echo $"$EIFACE is not connected"
|
|
232
|
+ if [[ "$EIFACE" != "$IFACE" ]] ; then
|
|
233
|
+ ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
|
|
234
|
+ if [[ "$ethernet_connected" != "0" ]]; then
|
|
235
|
+ echo $'Trying ethernet bridge to the internet'
|
|
236
|
+ brctl addif "$BRIDGE" "$EIFACE"
|
|
237
|
+ ifconfig "$EIFACE" 0.0.0.0
|
|
238
|
+ ifconfig "$EIFACE" up promisc
|
|
239
|
+ echo $'End of internet bridge'
|
|
240
|
+
|
|
241
|
+ sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
|
|
242
|
+ sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
|
|
243
|
+ sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service
|
|
244
|
+ sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service
|
|
245
|
+ systemctl daemon-reload
|
|
246
|
+ else
|
|
247
|
+ echo $"$EIFACE is not connected"
|
|
248
|
+ fi
|
247
|
249
|
fi
|
248
|
250
|
fi
|
249
|
251
|
ifconfig "$BRIDGE" up
|
|
@@ -302,6 +304,9 @@ function start {
|
302
|
304
|
}
|
303
|
305
|
|
304
|
306
|
function monitor {
|
|
307
|
+ if [[ "$MESH_INTERFACE_TYPE" != 'wlan'* ]]; then
|
|
308
|
+ return
|
|
309
|
+ fi
|
305
|
310
|
if [ -z "$IFACE" ] ; then
|
306
|
311
|
echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
|
307
|
312
|
exit 723657
|
|
@@ -357,6 +362,36 @@ function monitor {
|
357
|
362
|
start
|
358
|
363
|
}
|
359
|
364
|
|
|
365
|
+# optionally a file can contain the mesh interface type
|
|
366
|
+mesh_interface_type_file=/root/.mesh_interface_type
|
|
367
|
+if [ -f "$mesh_interface_type_file" ]; then
|
|
368
|
+ MESH_INTERFACE_TYPE=$(head -n 1 < "$mesh_interface_type_file")
|
|
369
|
+ if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
|
|
370
|
+ MESH_INTERFACE_TYPE='wlan'
|
|
371
|
+ fi
|
|
372
|
+ if [[ "$MESH_INTERFACE_TYPE" == 'eth'* ]]; then
|
|
373
|
+ MESH_INTERFACE_TYPE='eth'
|
|
374
|
+ fi
|
|
375
|
+fi
|
|
376
|
+
|
|
377
|
+mesh_protocol_init
|
|
378
|
+
|
|
379
|
+if [[ "$MESH_INTERFACE_TYPE" == 'eth'* ]]; then
|
|
380
|
+ MESH_INTERFACE_TYPE='eth'
|
|
381
|
+fi
|
|
382
|
+
|
|
383
|
+update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
|
|
384
|
+
|
|
385
|
+if [ ! "$IFACE" ]; then
|
|
386
|
+ echo $'No wlan adaptor'
|
|
387
|
+ exit 0
|
|
388
|
+fi
|
|
389
|
+
|
|
390
|
+if [ -e /etc/default/batctl ]; then
|
|
391
|
+ # shellcheck disable=SC1091
|
|
392
|
+ . /etc/default/batctl
|
|
393
|
+fi
|
|
394
|
+
|
360
|
395
|
if ! grep -q "$IFACE" /proc/net/dev; then
|
361
|
396
|
echo "Interface \$IFACE was not found"
|
362
|
397
|
stop
|