Browse Source

Mesh peer interfaces configuration

Bob Mottram 10 years ago
parent
commit
1bcd6a21a1
1 changed files with 31 additions and 7 deletions
  1. 31
    7
      src/freedombone-client

+ 31
- 7
src/freedombone-client View File

32
 VERSION="1.01"
32
 VERSION="1.01"
33
 
33
 
34
 # mesh networking settings
34
 # mesh networking settings
35
-BATMAN_IPV6=
35
+BRIDGE_BATMAN_IPV6=
36
+PEER_BATMAN_IPV6=
36
 
37
 
37
 # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
38
 # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
38
 SSH_CIPHERS="chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
39
 SSH_CIPHERS="chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
83
 }
84
 }
84
 
85
 
85
 function mesh_batman {
86
 function mesh_batman {
86
-  if [ ! $BATMAN_IPV6 ]; then
87
+  if [ ! $BRIDGE_BATMAN_IPV6 ]; then
87
       return
88
       return
88
   fi
89
   fi
89
   sudo apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
90
   sudo apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
95
       sudo echo 'batman_adv' >> /etc/modules
96
       sudo echo 'batman_adv' >> /etc/modules
96
   fi
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
   echo '#!/bin/bash' > /tmp/freedombone_mesh
122
   echo '#!/bin/bash' > /tmp/freedombone_mesh
99
   echo '' > /tmp/freedombone_mesh
123
   echo '' > /tmp/freedombone_mesh
100
   echo '# stop network manager to make the mesh network work' >> /tmp/freedombone_mesh
124
   echo '# stop network manager to make the mesh network work' >> /tmp/freedombone_mesh
109
   echo '' >> /tmp/freedombone_mesh
133
   echo '' >> /tmp/freedombone_mesh
110
   echo '# add the interface to the ad-hoc network - or create it.' >> /tmp/freedombone_mesh
134
   echo '# add the interface to the ad-hoc network - or create it.' >> /tmp/freedombone_mesh
111
   echo -n "iwconfig wlan0 mode ad-hoc essid mesh ap " >> /tmp/freedombone_mesh
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
   echo '' >> /tmp/freedombone_mesh
137
   echo '' >> /tmp/freedombone_mesh
114
   echo -n '# add wlan0 to the batman-adv virtual interface(so it can ' >> /tmp/freedombone_mesh
138
   echo -n '# add wlan0 to the batman-adv virtual interface(so it can ' >> /tmp/freedombone_mesh
115
   echo 'communicate with other batman-adv nodes)' >> /tmp/freedombone_mesh
139
   echo 'communicate with other batman-adv nodes)' >> /tmp/freedombone_mesh
127
 
151
 
128
 function show_help {
152
 function show_help {
129
     echo ''
153
     echo ''
130
-    echo 'freedombone-client --mesh-ip [mesh bridge IPv6 address]'
154
+    echo 'freedombone-client --bridge-ip [mesh bridge IPv6 address]'
131
     echo ''
155
     echo ''
132
     exit 0
156
     exit 0
133
 }
157
 }
140
     -h|--help)
164
     -h|--help)
141
     show_help
165
     show_help
142
     ;;
166
     ;;
143
-    --mesh-ip)
167
+    --bridge-ip)
144
     shift
168
     shift
145
-    BATMAN_IPV6="$1"
169
+    BRIDGE_BATMAN_IPV6="$1"
146
     ;;
170
     ;;
147
     *)
171
     *)
148
     # unknown option
172
     # unknown option
155
 configure_ssh_client
179
 configure_ssh_client
156
 mesh_batman
180
 mesh_batman
157
 echo 'Configuration complete'
181
 echo 'Configuration complete'
158
-if [[ $BATMAN_IPV6 ]]; then
182
+if [[ $BRIDGE_BATMAN_IPV6 ]]; then
159
     echo ''
183
     echo ''
160
     echo 'Type "sudo mesh" to connect to the mesh network'
184
     echo 'Type "sudo mesh" to connect to the mesh network'
161
 fi
185
 fi