|  | @@ -79,6 +79,9 @@ MINIMUM_PASSWORD_LENGTH=10
 | 
	
		
			
			| 79 | 79 |  # number of CPU cores
 | 
	
		
			
			| 80 | 80 |  CPU_CORES=1
 | 
	
		
			
			| 81 | 81 |  
 | 
	
		
			
			|  | 82 | +# If the system is on an IPv6 network
 | 
	
		
			
			|  | 83 | +IPV6_NETWORK='2001:470:26:307'
 | 
	
		
			
			|  | 84 | +
 | 
	
		
			
			| 82 | 85 |  # The static IP address of the system within the local network
 | 
	
		
			
			| 83 | 86 |  LOCAL_NETWORK_STATIC_IP_ADDRESS="192.168.1.60"
 | 
	
		
			
			| 84 | 87 |  
 | 
	
	
		
			
			|  | @@ -376,7 +379,7 @@ CJDNS_PORT=
 | 
	
		
			
			| 376 | 379 |  
 | 
	
		
			
			| 377 | 380 |  # B.A.T.M.A.N settings
 | 
	
		
			
			| 378 | 381 |  ENABLE_BATMAN="no"
 | 
	
		
			
			| 379 |  | -BATMAN_IP='10.47.254.254'
 | 
	
		
			
			|  | 382 | +BATMAN_IPV6=
 | 
	
		
			
			| 380 | 383 |  
 | 
	
		
			
			| 381 | 384 |  function show_help {
 | 
	
		
			
			| 382 | 385 |    echo ''
 | 
	
	
		
			
			|  | @@ -713,6 +716,9 @@ function read_configuration {
 | 
	
		
			
			| 713 | 716 |    fi
 | 
	
		
			
			| 714 | 717 |  
 | 
	
		
			
			| 715 | 718 |    if [ -f $CONFIGURATION_FILE ]; then
 | 
	
		
			
			|  | 719 | +      if grep -q "IPV6_NETWORK" $CONFIGURATION_FILE; then
 | 
	
		
			
			|  | 720 | +          IPV6_NETWORK=$(grep "IPV6_NETWORK" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
 | 
	
		
			
			|  | 721 | +      fi
 | 
	
		
			
			| 716 | 722 |        if grep -q "HWRNG_TYPE" $CONFIGURATION_FILE; then
 | 
	
		
			
			| 717 | 723 |            HWRNG_TYPE=$(grep "HWRNG_TYPE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
 | 
	
		
			
			| 718 | 724 |        fi
 | 
	
	
		
			
			|  | @@ -808,8 +814,8 @@ function read_configuration {
 | 
	
		
			
			| 808 | 814 |        if grep -q "ENABLE_BATMAN" $CONFIGURATION_FILE; then
 | 
	
		
			
			| 809 | 815 |            ENABLE_BATMAN=$(grep "ENABLE_BATMAN" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
 | 
	
		
			
			| 810 | 816 |        fi
 | 
	
		
			
			| 811 |  | -      if grep -q "BATMAN_IP" $CONFIGURATION_FILE; then
 | 
	
		
			
			| 812 |  | -          BATMAN_IP=$(grep "BATMAN_IP" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
 | 
	
		
			
			|  | 817 | +      if grep -q "BATMAN_IPV6" $CONFIGURATION_FILE; then
 | 
	
		
			
			|  | 818 | +          BATMAN_IPV6=$(grep "BATMAN_IPV6" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
 | 
	
		
			
			| 813 | 819 |        fi
 | 
	
		
			
			| 814 | 820 |        if grep -q "ENABLE_CJDNS" $CONFIGURATION_FILE; then
 | 
	
		
			
			| 815 | 821 |            ENABLE_CJDNS=$(grep "ENABLE_CJDNS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
 | 
	
	
		
			
			|  | @@ -1202,6 +1208,15 @@ function get_cjdns_password {
 | 
	
		
			
			| 1202 | 1208 |    fi
 | 
	
		
			
			| 1203 | 1209 |  }
 | 
	
		
			
			| 1204 | 1210 |  
 | 
	
		
			
			|  | 1211 | +function enable_ipv6 {
 | 
	
		
			
			|  | 1212 | +  # endure that ipv6 is enabled and can route
 | 
	
		
			
			|  | 1213 | +  sed -i 's/net.ipv6.conf.all.disable_ipv6.*/net.ipv6.conf.all.disable_ipv6 = 0/g' /etc/sysctl.conf
 | 
	
		
			
			|  | 1214 | +  #sed -i "s/net.ipv6.conf.all.accept_redirects.*/net.ipv6.conf.all.accept_redirects = 1/g" /etc/sysctl.conf
 | 
	
		
			
			|  | 1215 | +  #sed -i "s/net.ipv6.conf.all.accept_source_route.*/net.ipv6.conf.all.accept_source_route = 1/g" /etc/sysctl.conf
 | 
	
		
			
			|  | 1216 | +  sed -i "s/net.ipv6.conf.all.forwarding.*/net.ipv6.conf.all.forwarding=1/g" /etc/sysctl.conf
 | 
	
		
			
			|  | 1217 | +  echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
 | 
	
		
			
			|  | 1218 | +}
 | 
	
		
			
			|  | 1219 | +
 | 
	
		
			
			| 1205 | 1220 |  function mesh_cjdns {
 | 
	
		
			
			| 1206 | 1221 |    if grep -Fxq "mesh_cjdns" $COMPLETION_FILE; then
 | 
	
		
			
			| 1207 | 1222 |        return
 | 
	
	
		
			
			|  | @@ -1282,12 +1297,7 @@ function mesh_cjdns {
 | 
	
		
			
			| 1282 | 1297 |        CJDNS_PORT=$(cat /etc/cjdns/cjdroute.conf | grep '"bind": "0.0.0.0:' | awk -F '"' '{print $4}' | awk -F ':' '{print $2}' | sed -n 1p)
 | 
	
		
			
			| 1283 | 1298 |    fi
 | 
	
		
			
			| 1284 | 1299 |  
 | 
	
		
			
			| 1285 |  | -  # endure that ipv6 is enabled and can route
 | 
	
		
			
			| 1286 |  | -  sed -i 's/net.ipv6.conf.all.disable_ipv6.*/net.ipv6.conf.all.disable_ipv6 = 0/g' /etc/sysctl.conf
 | 
	
		
			
			| 1287 |  | -  #sed -i "s/net.ipv6.conf.all.accept_redirects.*/net.ipv6.conf.all.accept_redirects = 1/g" /etc/sysctl.conf
 | 
	
		
			
			| 1288 |  | -  #sed -i "s/net.ipv6.conf.all.accept_source_route.*/net.ipv6.conf.all.accept_source_route = 1/g" /etc/sysctl.conf
 | 
	
		
			
			| 1289 |  | -  sed -i "s/net.ipv6.conf.all.forwarding.*/net.ipv6.conf.all.forwarding=1/g" /etc/sysctl.conf
 | 
	
		
			
			| 1290 |  | -  echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
 | 
	
		
			
			|  | 1300 | +  enable_ipv6
 | 
	
		
			
			| 1291 | 1301 |  
 | 
	
		
			
			| 1292 | 1302 |    echo '#!/bin/sh -e' > /etc/init.d/cjdns
 | 
	
		
			
			| 1293 | 1303 |    echo '### BEGIN INIT INFO' >> /etc/init.d/cjdns
 | 
	
	
		
			
			|  | @@ -1411,7 +1421,7 @@ function mesh_cjdns {
 | 
	
		
			
			| 1411 | 1421 |        exit 4395
 | 
	
		
			
			| 1412 | 1422 |    fi
 | 
	
		
			
			| 1413 | 1423 |  
 | 
	
		
			
			| 1414 |  | -  if ! grep -q "# Mesh network cjdns" /etc/network/interfaces; then
 | 
	
		
			
			|  | 1424 | +  if ! grep -q "# Mesh Networking (cjdns)" /etc/network/interfaces; then
 | 
	
		
			
			| 1415 | 1425 |        echo '' >> /etc/network/interfaces
 | 
	
		
			
			| 1416 | 1426 |        echo '# Mesh Networking (cjdns)' >> /etc/network/interfaces
 | 
	
		
			
			| 1417 | 1427 |        echo 'iface eth0 inet6 static' >> /etc/network/interfaces
 | 
	
	
		
			
			|  | @@ -1510,6 +1520,16 @@ function mesh_cjdns_tools {
 | 
	
		
			
			| 1510 | 1520 |    echo 'mesh_cjdns_tools' >> $COMPLETION_FILE
 | 
	
		
			
			| 1511 | 1521 |  }
 | 
	
		
			
			| 1512 | 1522 |  
 | 
	
		
			
			|  | 1523 | +function get_batman_ipv6_address {
 | 
	
		
			
			|  | 1524 | +  if [ -f /home/$MY_USERNAME/README ]; then
 | 
	
		
			
			|  | 1525 | +      if grep -q "BATMAN IPv6 address" /home/$MY_USERNAME/README; then
 | 
	
		
			
			|  | 1526 | +          if [ ! $BATMAN_IPV6 ]; then
 | 
	
		
			
			|  | 1527 | +              BATMAN_IPV6=$(cat /home/$MY_USERNAME/README | grep "BATMAN IPv6 address" | awk -F ':' '{print $2}' | sed 's/^ *//')
 | 
	
		
			
			|  | 1528 | +          fi
 | 
	
		
			
			|  | 1529 | +      fi
 | 
	
		
			
			|  | 1530 | +  fi
 | 
	
		
			
			|  | 1531 | +}
 | 
	
		
			
			|  | 1532 | +
 | 
	
		
			
			| 1513 | 1533 |  function mesh_batman {
 | 
	
		
			
			| 1514 | 1534 |    # https://sudoroom.org/wiki/Mesh/Relay_setup
 | 
	
		
			
			| 1515 | 1535 |    # also see http://www.netlore.co.uk/airmesh/
 | 
	
	
		
			
			|  | @@ -1544,12 +1564,30 @@ function mesh_batman {
 | 
	
		
			
			| 1544 | 1564 |        echo 'l2tp_netlink' >> /etc/modules
 | 
	
		
			
			| 1545 | 1565 |    fi
 | 
	
		
			
			| 1546 | 1566 |  
 | 
	
		
			
			| 1547 |  | -  if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /etc/network/interfaces; then
 | 
	
		
			
			|  | 1567 | +  get_batman_ipv6_address
 | 
	
		
			
			|  | 1568 | +
 | 
	
		
			
			|  | 1569 | +  # If no address has been given then create a ramdom one
 | 
	
		
			
			|  | 1570 | +  if [ ! $BATMAN_IPV6 ]; then
 | 
	
		
			
			|  | 1571 | +      hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
 | 
	
		
			
			|  | 1572 | +      a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
 | 
	
		
			
			|  | 1573 | +      b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
 | 
	
		
			
			|  | 1574 | +      c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
 | 
	
		
			
			|  | 1575 | +      d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
 | 
	
		
			
			|  | 1576 | +      BATMAN_IPV6="$IPV6_NETWORK:$a:$b:$c:$d"
 | 
	
		
			
			|  | 1577 | +  fi
 | 
	
		
			
			|  | 1578 | +
 | 
	
		
			
			|  | 1579 | +  if ! grep -q "# Mesh Networking (B.A.T.M.A.N)" /etc/network/interfaces; then
 | 
	
		
			
			| 1548 | 1580 |        echo '' >> /etc/network/interfaces
 | 
	
		
			
			| 1549 | 1581 |        echo '# Mesh Networking (B.A.T.M.A.N)' >> /etc/network/interfaces
 | 
	
		
			
			| 1550 |  | -      echo 'iface bat0 inet static' >> /etc/network/interfaces
 | 
	
		
			
			| 1551 |  | -      echo "    address $BATMAN_IP" >> /etc/network/interfaces
 | 
	
		
			
			| 1552 |  | -      echo '    netmask 255.0.0.0' >> /etc/network/interfaces
 | 
	
		
			
			|  | 1582 | +      echo 'iface bat0 inet6 static' >> /etc/network/interfaces
 | 
	
		
			
			|  | 1583 | +      echo '    pre-up modprobe ipv6' >> /etc/network/interfaces
 | 
	
		
			
			|  | 1584 | +      echo "    address $BATMAN_IPV6" >> /etc/network/interfaces
 | 
	
		
			
			|  | 1585 | +      echo '    netmask 64' >> /etc/network/interfaces
 | 
	
		
			
			|  | 1586 | +      service networking restart
 | 
	
		
			
			|  | 1587 | +      if [ ! "$?" = "0" ]; then
 | 
	
		
			
			|  | 1588 | +          systemctl status networking.service
 | 
	
		
			
			|  | 1589 | +          exit 6949
 | 
	
		
			
			|  | 1590 | +      fi
 | 
	
		
			
			| 1553 | 1591 |    fi
 | 
	
		
			
			| 1554 | 1592 |  
 | 
	
		
			
			| 1555 | 1593 |    apt-get -y install iproute bridge-utils libnetfilter-conntrack3 python-dev libevent-dev ebtables python-pip git
 | 
	
	
		
			
			|  | @@ -1560,8 +1598,7 @@ function mesh_batman {
 | 
	
		
			
			| 1560 | 1598 |    cd /opt/tunneldigger/broker
 | 
	
		
			
			| 1561 | 1599 |    pip install -r requirements.txt
 | 
	
		
			
			| 1562 | 1600 |  
 | 
	
		
			
			| 1563 |  | -  EXTERNAL_IP=$(TODO)
 | 
	
		
			
			| 1564 |  | -  sed -i 's|address=.*|address=$EXTERNAL_IP|g' l2tp_broker.cfg
 | 
	
		
			
			|  | 1601 | +  sed -i 's|address=.*|address=$BATMAN_IPV6|g' l2tp_broker.cfg
 | 
	
		
			
			| 1565 | 1602 |    sed -i 's|interface=.*|interface=eth0|g' l2tp_broker.cfg
 | 
	
		
			
			| 1566 | 1603 |    sed -i 's|session.up=.*|session.up=/opt/tunneldigger/broker/scripts/up_hook.sh|g' l2tp_broker.cfg
 | 
	
		
			
			| 1567 | 1604 |  
 | 
	
	
		
			
			|  | @@ -1571,12 +1608,20 @@ function mesh_batman {
 | 
	
		
			
			| 1571 | 1608 |    echo 'ifconfig $INTERFACE up' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1572 | 1609 |    echo 'batctl if add $INTERFACE' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1573 | 1610 |    echo 'if [ `cat /sys/class/net/bat0/operstate` != "up" ]; then' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1574 |  | -  echo "    ifconfig bat0 $BATMAN_IP netmask 255.0.0.0 up" >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			|  | 1611 | +  echo "    ifconfig bat0 up" >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1575 | 1612 |    echo 'fi' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1576 | 1613 |    chmod 755 up_hook.sh
 | 
	
		
			
			| 1577 | 1614 |  
 | 
	
		
			
			| 1578 | 1615 |    # TODO make a systemd service to run ./l2tp_broker.py l2tp_broker.cfg
 | 
	
		
			
			| 1579 | 1616 |  
 | 
	
		
			
			|  | 1617 | +  if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
 | 
	
		
			
			|  | 1618 | +      echo '' >> /home/$MY_USERNAME/README
 | 
	
		
			
			|  | 1619 | +      echo '' >> /home/$MY_USERNAME/README
 | 
	
		
			
			|  | 1620 | +      echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
 | 
	
		
			
			|  | 1621 | +      echo '=============================' >> /home/$MY_USERNAME/README
 | 
	
		
			
			|  | 1622 | +      echo "BATMAN IPv6 address: $BATMAN_IPV6" >> /home/$MY_USERNAME/README
 | 
	
		
			
			|  | 1623 | +  fi
 | 
	
		
			
			|  | 1624 | +
 | 
	
		
			
			| 1580 | 1625 |    echo 'mesh_batman' >> $COMPLETION_FILE
 | 
	
		
			
			| 1581 | 1626 |  }
 | 
	
		
			
			| 1582 | 1627 |  
 |