Ver código fonte

Connect peers to the mesh network with the client setup script

Bob Mottram 10 anos atrás
pai
commit
f5c0c908eb
3 arquivos alterados com 83 adições e 29 exclusões
  1. 5
    22
      src/freedombone
  2. 78
    0
      src/freedombone-client
  3. 0
    7
      src/freedombone-config

+ 5
- 22
src/freedombone Ver arquivo

@@ -377,7 +377,6 @@ CJDNS_PORT=
377 377
 # B.A.T.M.A.N settings
378 378
 ENABLE_BATMAN="no"
379 379
 BATMAN_IPV6=
380
-MESH_ESSID=
381 380
 
382 381
 # social key management
383 382
 ENABLE_SOCIAL_KEY_MANAGEMENT="no"
@@ -738,9 +737,6 @@ function read_configuration {
738 737
   fi
739 738
 
740 739
   if [ -f $CONFIGURATION_FILE ]; then
741
-      if grep -q "MESH_ESSID" $CONFIGURATION_FILE; then
742
-          MESH_ESSID=$(grep "MESH_ESSID" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
743
-      fi
744 740
       if grep -q "TOX_PORT" $CONFIGURATION_FILE; then
745 741
           TOX_PORT=$(grep "TOX_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
746 742
       fi
@@ -1560,22 +1556,14 @@ function mesh_cjdns_tools {
1560 1556
 
1561 1557
 function get_batman_ipv6_address {
1562 1558
   if [ -f /home/$MY_USERNAME/README ]; then
1563
-      if grep -q "BATMAN IPv6 address" /home/$MY_USERNAME/README; then
1559
+      if grep -q "Mesh internet bridge IP address" /home/$MY_USERNAME/README; then
1564 1560
           if [ ! $BATMAN_IPV6 ]; then
1565
-              BATMAN_IPV6=$(cat /home/$MY_USERNAME/README | grep "BATMAN IPv6 address" | awk -F ':' '{print $2}' | sed 's/^ *//')
1561
+              BATMAN_IPV6=$(cat /home/$MY_USERNAME/README | grep "Mesh internet bridge IP address" | awk -F ':' '{print $2}' | sed 's/^ *//')
1566 1562
           fi
1567 1563
       fi
1568 1564
   fi
1569 1565
 }
1570 1566
 
1571
-function get_mesh_essid {
1572
-  if [ -f /home/$MY_USERNAME/README ]; then
1573
-      if grep -q 'Mesh ESSID:' /home/$MY_USERNAME/README; then
1574
-          MESH_ESSID==$(cat /home/$MY_USERNAME/README | grep "Mesh ESSID" | awk -F ':' '{print $2}' | sed 's/^ *//')
1575
-      fi
1576
-  fi
1577
-}
1578
-
1579 1567
 function mesh_batman_bridge {
1580 1568
   # https://sudoroom.org/wiki/Mesh/Relay_setup
1581 1569
   # also see http://www.netlore.co.uk/airmesh/
@@ -1625,11 +1613,6 @@ function mesh_batman_bridge {
1625 1613
       fi
1626 1614
   fi
1627 1615
 
1628
-  get_mesh_essid
1629
-  if [ ! $MESH_ESSID ]; then
1630
-      MESH_ESSID="$(openssl rand -base64 5)"
1631
-  fi
1632
-
1633 1616
   echo '#!/bin/bash' > /usr/bin/mesh
1634 1617
   echo '' > /usr/bin/mesh
1635 1618
   echo '# stop network manager to make the mesh network work' >> /usr/bin/mesh
@@ -1643,7 +1626,7 @@ function mesh_batman_bridge {
1643 1626
   echo 'iwconfig wlan0 enc off' >> /usr/bin/mesh
1644 1627
   echo '' >> /usr/bin/mesh
1645 1628
   echo '# add the interface to the ad-hoc network - or create it.' >> /usr/bin/mesh
1646
-  echo -n "iwconfig wlan0 mode ad-hoc essid mesh-$MESH_ESSID ap " >> /usr/bin/mesh
1629
+  echo -n "iwconfig wlan0 mode ad-hoc essid mesh ap " >> /usr/bin/mesh
1647 1630
   echo "$BATMAN_IPV6 channel 2" >> /usr/bin/mesh
1648 1631
   echo '' >> /usr/bin/mesh
1649 1632
   echo -n '# add wlan0 to the batman-adv virtual interface(so it can ' >> /usr/bin/mesh
@@ -1669,8 +1652,8 @@ function mesh_batman_bridge {
1669 1652
       echo '' >> /home/$MY_USERNAME/README
1670 1653
       echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
1671 1654
       echo '=============================' >> /home/$MY_USERNAME/README
1672
-      echo "Mesh ESSID: $MESH_ESSID" >> /home/$MY_USERNAME/README
1673
-      echo "BATMAN IPv6 address: $BATMAN_IPV6" >> /home/$MY_USERNAME/README
1655
+      echo 'Mesh ESSID: mesh' >> /home/$MY_USERNAME/README
1656
+      echo "Mesh internet bridge IP address: $BATMAN_IPV6" >> /home/$MY_USERNAME/README
1674 1657
       chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
1675 1658
       chmod 600 /home/$MY_USERNAME/README
1676 1659
   fi

+ 78
- 0
src/freedombone-client Ver arquivo

@@ -31,6 +31,9 @@ CURR_USER=$USER
31 31
 # Version number of this script
32 32
 VERSION="1.01"
33 33
 
34
+# mesh networking settings
35
+BATMAN_IPV6=
36
+
34 37
 # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
35 38
 SSH_CIPHERS="chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
36 39
 SSH_MACS="hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com"
@@ -79,6 +82,81 @@ function configure_ssh_client {
79 82
   echo ''
80 83
 }
81 84
 
85
+function mesh_batman {
86
+  if [ ! $BATMAN_IPV6 ]; then
87
+      return
88
+  fi
89
+  sudo apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
90
+  sudo apt-get -y install python-dev libevent-dev ebtables python-pip git
91
+
92
+  sudo modprobe batman-adv
93
+  [ $? -ne 0 ] && echo "B.A.T.M.A.N module not available" && exit 76482
94
+  if ! grep -q "batman_adv" /etc/modules; then
95
+      sudo echo 'batman_adv' >> /etc/modules
96
+  fi
97
+
98
+  echo '#!/bin/bash' > /tmp/freedombone_mesh
99
+  echo '' > /tmp/freedombone_mesh
100
+  echo '# stop network manager to make the mesh network work' >> /tmp/freedombone_mesh
101
+  echo 'service networking stop' >> /tmp/freedombone_mesh
102
+  echo '' >> /tmp/freedombone_mesh
103
+  echo -n '# configure the wlan interface to operate with ' >> /tmp/freedombone_mesh
104
+  echo 'mtus of 1532(batman requires it) and turn enc off ' >> /tmp/freedombone_mesh
105
+  echo 'to ensure it works' >> /tmp/freedombone_mesh
106
+  echo 'ifconfig wlan0 down' >> /tmp/freedombone_mesh
107
+  echo 'ifconfig wlan0 mtu 1532' >> /tmp/freedombone_mesh
108
+  echo 'iwconfig wlan0 enc off' >> /tmp/freedombone_mesh
109
+  echo '' >> /tmp/freedombone_mesh
110
+  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
112
+  echo "$BATMAN_IPV6 channel 2" >> /tmp/freedombone_mesh
113
+  echo '' >> /tmp/freedombone_mesh
114
+  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
116
+  echo 'batctl if add wlan0' >> /tmp/freedombone_mesh
117
+  echo 'ifconfig wlan0 up' >> /tmp/freedombone_mesh
118
+  echo 'ifconfig bat0 up' >> /tmp/freedombone_mesh
119
+  echo '' >> /tmp/freedombone_mesh
120
+  echo '# get the ip address for the node from the bridge connected to the dhcp server' >> /tmp/freedombone_mesh
121
+  echo 'dhclient bat0' >> /tmp/freedombone_mesh
122
+  echo '' >> /tmp/freedombone_mesh
123
+  echo 'exit 0' >> /tmp/freedombone_mesh
124
+  chmod +x /tmp/freedombone_mesh
125
+  sudo mv /tmp/freedombone_mesh /usr/bin/mesh
126
+}
127
+
128
+function show_help {
129
+    echo ''
130
+    echo 'freedombone-client --mesh-ip [mesh bridge IPv6 address]'
131
+    echo ''
132
+    exit 0
133
+}
134
+
135
+while [[ $# > 1 ]]
136
+do
137
+key="$1"
138
+
139
+case $key in
140
+    -h|--help)
141
+    show_help
142
+    ;;
143
+    --mesh-ip)
144
+    shift
145
+    BATMAN_IPV6="$1"
146
+    ;;
147
+    *)
148
+    # unknown option
149
+    ;;
150
+esac
151
+shift
152
+done
153
+
82 154
 echo 'Configuring client'
83 155
 configure_ssh_client
156
+mesh_batman
84 157
 echo 'Configuration complete'
158
+if [[ $BATMAN_IPV6 ]]; then
159
+    echo ''
160
+    echo 'Type "sudo mesh" to connect to the mesh network'
161
+fi
162
+exit 0

+ 0
- 7
src/freedombone-config Ver arquivo

@@ -90,7 +90,6 @@ USB_DRIVE=/dev/sdb1
90 90
 HWRNG_TYPE=
91 91
 ENABLE_SOCIAL_KEY_MANAGEMENT=
92 92
 BATMAN_IPV6=
93
-MESH_ESSID=
94 93
 
95 94
 CONFIGURATION_FILE=
96 95
 
@@ -232,9 +231,6 @@ function save_configuration_file {
232 231
   if [ $BATMAN_IPV6 ]; then
233 232
       echo "BATMAN_IPV6=$BATMAN_IPV6" >> $CONFIGURATION_FILE
234 233
   fi
235
-  if [ $MESH_ESSID ]; then
236
-      echo "MESH_ESSID=$MESH_ESSID" >> $CONFIGURATION_FILE
237
-  fi
238 234
 }
239 235
 
240 236
 # test a domain name to see if it's valid
@@ -1388,9 +1384,6 @@ function read_configuration {
1388 1384
       if grep -q "ENABLE_BATMAN" $CONFIGURATION_FILE; then
1389 1385
           ENABLE_BATMAN=$(grep "ENABLE_BATMAN" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
1390 1386
       fi
1391
-      if grep -q "MESH_ESSID" $CONFIGURATION_FILE; then
1392
-          MESH_ESSID=$(grep "MESH_ESSID" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
1393
-      fi
1394 1387
       if grep -q "BATMAN_IPV6" $CONFIGURATION_FILE; then
1395 1388
           BATMAN_IPV6=$(grep "BATMAN_IPV6" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
1396 1389
       fi