瀏覽代碼

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
 #
8
 #
9
 #                    Freedom in the Cloud
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
 # License
13
 # License
14
 # =======
14
 # =======
34
 # hotspot passphrase must be 5 characters or longer
34
 # hotspot passphrase must be 5 characters or longer
35
 HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
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
 source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
40
 source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
40
 source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
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
 function status {
43
 function status {
56
     batctl o
44
     batctl o
57
 
45
 
170
 
158
 
171
 # shellcheck disable=SC2120
159
 # shellcheck disable=SC2120
172
 function start {
160
 function start {
173
-    update_wifi_adaptors "${interface_type}"
161
+    update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
174
 
162
 
175
     if [ -z "$IFACE" ] ; then
163
     if [ -z "$IFACE" ] ; then
176
         echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
164
         echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
237
             brctl addif "$BRIDGE" "$EIFACE"
225
             brctl addif "$BRIDGE" "$EIFACE"
238
             ifconfig "$EIFACE" 0.0.0.0
226
             ifconfig "$EIFACE" 0.0.0.0
239
             ifconfig "$EIFACE" up promisc
227
             ifconfig "$EIFACE" up promisc
240
-            echo $'End of ethernet bridge'
228
+            echo $'End of internet bridge'
241
 
229
 
242
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
230
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
243
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
231
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
359
     start
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
 if ! grep -q "$IFACE" /proc/net/dev; then
375
 if ! grep -q "$IFACE" /proc/net/dev; then
363
     echo "Interface \$IFACE was not found"
376
     echo "Interface \$IFACE was not found"
364
     stop
377
     stop