瀏覽代碼

Mesh peer interfaces configuration

Bob Mottram 9 年之前
父節點
當前提交
1bcd6a21a1
共有 1 個檔案被更改,包括 31 行新增7 行删除
  1. 31
    7
      src/freedombone-client

+ 31
- 7
src/freedombone-client 查看文件

@@ -32,7 +32,8 @@ CURR_USER=$USER
32 32
 VERSION="1.01"
33 33
 
34 34
 # mesh networking settings
35
-BATMAN_IPV6=
35
+BRIDGE_BATMAN_IPV6=
36
+PEER_BATMAN_IPV6=
36 37
 
37 38
 # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
38 39
 SSH_CIPHERS="chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
@@ -83,7 +84,7 @@ function configure_ssh_client {
83 84
 }
84 85
 
85 86
 function mesh_batman {
86
-  if [ ! $BATMAN_IPV6 ]; then
87
+  if [ ! $BRIDGE_BATMAN_IPV6 ]; then
87 88
       return
88 89
   fi
89 90
   sudo apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
@@ -95,6 +96,29 @@ function mesh_batman {
95 96
       sudo echo 'batman_adv' >> /etc/modules
96 97
   fi
97 98
 
99
+  # If no address has been given then create a ramdom one
100
+  if [ ! $PEER_BATMAN_IPV6 ]; then
101
+      hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
102
+      a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
103
+      b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
104
+      c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
105
+      d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
106
+      PEER_BATMAN_IPV6="$IPV6_NETWORK:$a:$b:$c:$d"
107
+  fi
108
+
109
+  sudo cp /etc/network/interfaces ~/interfaces
110
+  if ! grep -q "# Mesh Networking (B.A.T.M.A.N)" ~/interfaces; then
111
+      echo '' >> ~/interfaces
112
+      echo '# Mesh Networking (B.A.T.M.A.N)' >> ~/interfaces
113
+      echo 'iface bat0 inet6 static' >> ~/interfaces
114
+      echo '    pre-up modprobe ipv6' >> ~/interfaces
115
+      echo "    address $PEER_BATMAN_IPV6" >> ~/interfaces
116
+      echo '    netmask 64' >> ~/interfaces
117
+      sudo mv ~/interfaces /etc/network/interfaces
118
+  else
119
+      sudo rm ~/interfaces
120
+  fi
121
+
98 122
   echo '#!/bin/bash' > /tmp/freedombone_mesh
99 123
   echo '' > /tmp/freedombone_mesh
100 124
   echo '# stop network manager to make the mesh network work' >> /tmp/freedombone_mesh
@@ -109,7 +133,7 @@ function mesh_batman {
109 133
   echo '' >> /tmp/freedombone_mesh
110 134
   echo '# add the interface to the ad-hoc network - or create it.' >> /tmp/freedombone_mesh
111 135
   echo -n "iwconfig wlan0 mode ad-hoc essid mesh ap " >> /tmp/freedombone_mesh
112
-  echo "$BATMAN_IPV6 channel 2" >> /tmp/freedombone_mesh
136
+  echo "$BRIDGE_BATMAN_IPV6 channel 2" >> /tmp/freedombone_mesh
113 137
   echo '' >> /tmp/freedombone_mesh
114 138
   echo -n '# add wlan0 to the batman-adv virtual interface(so it can ' >> /tmp/freedombone_mesh
115 139
   echo 'communicate with other batman-adv nodes)' >> /tmp/freedombone_mesh
@@ -127,7 +151,7 @@ function mesh_batman {
127 151
 
128 152
 function show_help {
129 153
     echo ''
130
-    echo 'freedombone-client --mesh-ip [mesh bridge IPv6 address]'
154
+    echo 'freedombone-client --bridge-ip [mesh bridge IPv6 address]'
131 155
     echo ''
132 156
     exit 0
133 157
 }
@@ -140,9 +164,9 @@ case $key in
140 164
     -h|--help)
141 165
     show_help
142 166
     ;;
143
-    --mesh-ip)
167
+    --bridge-ip)
144 168
     shift
145
-    BATMAN_IPV6="$1"
169
+    BRIDGE_BATMAN_IPV6="$1"
146 170
     ;;
147 171
     *)
148 172
     # unknown option
@@ -155,7 +179,7 @@ echo 'Configuring client'
155 179
 configure_ssh_client
156 180
 mesh_batman
157 181
 echo 'Configuration complete'
158
-if [[ $BATMAN_IPV6 ]]; then
182
+if [[ $BRIDGE_BATMAN_IPV6 ]]; then
159 183
     echo ''
160 184
     echo 'Type "sudo mesh" to connect to the mesh network'
161 185
 fi