浏览代码

optionally a file can contain the mesh interface type

Bob Mottram 7 年前
父节点
当前提交
9f14c00645
共有 1 个文件被更改,包括 30 次插入17 次删除
  1. 30
    17
      src/freedombone-mesh-batman

+ 30
- 17
src/freedombone-mesh-batman 查看文件

@@ -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,24 +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
-interface_type='wlan'
37
+# The type of interface which the mesh will run on
38
+MESH_INTERFACE_TYPE='wlan'
38 39
 
39 40
 source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
40 41
 source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
41 42
 
42
-mesh_protocol_init
43
-update_wifi_adaptors "${interface_type}"
44
-
45
-if [ ! "$IFACE" ]; then
46
-    echo $'No wlan adaptor'
47
-    exit 0
48
-fi
49
-
50
-if [ -e /etc/default/batctl ]; then
51
-    # shellcheck disable=SC1091
52
-    . /etc/default/batctl
53
-fi
54
-
55 43
 function status {
56 44
     batctl o
57 45
 
@@ -170,7 +158,7 @@ function add_wifi_interface {
170 158
 
171 159
 # shellcheck disable=SC2120
172 160
 function start {
173
-    update_wifi_adaptors "${interface_type}"
161
+    update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
174 162
 
175 163
     if [ -z "$IFACE" ] ; then
176 164
         echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
@@ -237,7 +225,7 @@ function start {
237 225
             brctl addif "$BRIDGE" "$EIFACE"
238 226
             ifconfig "$EIFACE" 0.0.0.0
239 227
             ifconfig "$EIFACE" up promisc
240
-            echo $'End of ethernet bridge'
228
+            echo $'End of internet bridge'
241 229
 
242 230
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
243 231
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
@@ -359,6 +347,31 @@ function monitor {
359 347
     start
360 348
 }
361 349
 
350
+# optionally a file can contain the mesh interface type
351
+mesh_interface_type_file=/root/.mesh_interface_type
352
+if [ -f "$mesh_interface_type_file" ]; then
353
+    MESH_INTERFACE_TYPE=$(head -n 1 < "$mesh_interface_type_file")
354
+    if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
355
+        MESH_INTERFACE_TYPE='wlan'
356
+    fi
357
+    if [[ "$MESH_INTERFACE_TYPE" == 'eth'* ]]; then
358
+        MESH_INTERFACE_TYPE='eth'
359
+    fi
360
+fi
361
+
362
+mesh_protocol_init
363
+update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
364
+
365
+if [ ! "$IFACE" ]; then
366
+    echo $'No wlan adaptor'
367
+    exit 0
368
+fi
369
+
370
+if [ -e /etc/default/batctl ]; then
371
+    # shellcheck disable=SC1091
372
+    . /etc/default/batctl
373
+fi
374
+
362 375
 if ! grep -q "$IFACE" /proc/net/dev; then
363 376
     echo "Interface \$IFACE was not found"
364 377
     stop