|  | @@ -1533,6 +1533,9 @@ function get_batman_ipv6_address {
 | 
	
		
			
			| 1533 | 1533 |  function mesh_batman {
 | 
	
		
			
			| 1534 | 1534 |    # https://sudoroom.org/wiki/Mesh/Relay_setup
 | 
	
		
			
			| 1535 | 1535 |    # also see http://www.netlore.co.uk/airmesh/
 | 
	
		
			
			|  | 1536 | +  # https://www.youtube.com/watch?v=CLKHWfQlFqQ
 | 
	
		
			
			|  | 1537 | +  # http://pastebin.com/4U9vdFFm
 | 
	
		
			
			|  | 1538 | +  # http://pastebin.com/eeTmL5XL
 | 
	
		
			
			| 1536 | 1539 |    if grep -Fxq "mesh_batman" $COMPLETION_FILE; then
 | 
	
		
			
			| 1537 | 1540 |        return
 | 
	
		
			
			| 1538 | 1541 |    fi
 | 
	
	
		
			
			|  | @@ -1546,24 +1549,6 @@ function mesh_batman {
 | 
	
		
			
			| 1546 | 1549 |        echo 'batman_adv' >> /etc/modules
 | 
	
		
			
			| 1547 | 1550 |    fi
 | 
	
		
			
			| 1548 | 1551 |  
 | 
	
		
			
			| 1549 |  | -  modprobe l2tp_core
 | 
	
		
			
			| 1550 |  | -  [ $? -ne 0 ] && echo "l2tp_core module not available" && exit 7358
 | 
	
		
			
			| 1551 |  | -  if ! grep -q "l2tp_core" /etc/modules; then
 | 
	
		
			
			| 1552 |  | -      echo 'l2tp_core' >> /etc/modules
 | 
	
		
			
			| 1553 |  | -  fi
 | 
	
		
			
			| 1554 |  | -
 | 
	
		
			
			| 1555 |  | -  modprobe l2tp_eth
 | 
	
		
			
			| 1556 |  | -  [ $? -ne 0 ] && echo "l2tp_eth module not available" && exit 8735
 | 
	
		
			
			| 1557 |  | -  if ! grep -q "l2tp_eth" /etc/modules; then
 | 
	
		
			
			| 1558 |  | -      echo 'l2tp_eth' >> /etc/modules
 | 
	
		
			
			| 1559 |  | -  fi
 | 
	
		
			
			| 1560 |  | -
 | 
	
		
			
			| 1561 |  | -  modprobe l2tp_netlink
 | 
	
		
			
			| 1562 |  | -  [ $? -ne 0 ] && echo "l2tp_netlink module not available" && exit 87367
 | 
	
		
			
			| 1563 |  | -  if ! grep -q "l2tp_netlink" /etc/modules; then
 | 
	
		
			
			| 1564 |  | -      echo 'l2tp_netlink' >> /etc/modules
 | 
	
		
			
			| 1565 |  | -  fi
 | 
	
		
			
			| 1566 |  | -
 | 
	
		
			
			| 1567 | 1552 |    enable_ipv6
 | 
	
		
			
			| 1568 | 1553 |    get_batman_ipv6_address
 | 
	
		
			
			| 1569 | 1554 |  
 | 
	
	
		
			
			|  | @@ -1591,48 +1576,35 @@ function mesh_batman {
 | 
	
		
			
			| 1591 | 1576 |        fi
 | 
	
		
			
			| 1592 | 1577 |    fi
 | 
	
		
			
			| 1593 | 1578 |  
 | 
	
		
			
			|  | 1579 | +  # TODO add wlan0
 | 
	
		
			
			|  | 1580 | +
 | 
	
		
			
			| 1594 | 1581 |    apt-get -y install iproute bridge-utils libnetfilter-conntrack3 python-dev libevent-dev ebtables python-pip git
 | 
	
		
			
			| 1595 | 1582 |  
 | 
	
		
			
			| 1596 |  | -  cd $BUILD_PATH
 | 
	
		
			
			| 1597 |  | -  git clone https://github.com/wlanslovenija/tunneldigger.git /opt/tunneldigger
 | 
	
		
			
			| 1598 |  | -  chown root:root -R /opt/tunneldigger
 | 
	
		
			
			| 1599 |  | -  cd /opt/tunneldigger/broker
 | 
	
		
			
			| 1600 |  | -  pip install -r requirements.txt
 | 
	
		
			
			| 1601 |  | -
 | 
	
		
			
			| 1602 |  | -  sed -i 's|address=.*|address=$BATMAN_IPV6|g' l2tp_broker.cfg
 | 
	
		
			
			| 1603 |  | -  sed -i 's|interface=.*|interface=eth0|g' l2tp_broker.cfg
 | 
	
		
			
			| 1604 |  | -  sed -i 's|session.up=.*|session.up=/opt/tunneldigger/broker/scripts/up_hook.sh|g' l2tp_broker.cfg
 | 
	
		
			
			| 1605 |  | -
 | 
	
		
			
			| 1606 |  | -  cd /opt/tunneldigger/broker/scripts
 | 
	
		
			
			| 1607 |  | -  echo '#!/bin/sh' > /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1608 |  | -  echo 'INTERFACE="$3"' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1609 |  | -  echo 'ifconfig $INTERFACE up' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1610 |  | -  echo 'batctl if add $INTERFACE' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1611 |  | -  echo 'if [ `cat /sys/class/net/bat0/operstate` != "up" ]; then' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1612 |  | -  echo "    ifconfig bat0 up" >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1613 |  | -  echo 'fi' >> /opt/tunneldigger/broker/scripts/up_hook.sh
 | 
	
		
			
			| 1614 |  | -  chmod 755 up_hook.sh
 | 
	
		
			
			| 1615 |  | -
 | 
	
		
			
			| 1616 |  | -  # make a systemd service to run ./l2tp_broker.py l2tp_broker.cfg
 | 
	
		
			
			| 1617 |  | -  echo '[Unit]' > /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1618 |  | -  echo 'Description=tunnerdigger (l2tp tunnel)' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1619 |  | -  echo 'After=syslog.target' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1620 |  | -  echo 'After=network.target' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1621 |  | -  echo '' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1622 |  | -  echo '[Service]' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1623 |  | -  echo 'Type=simple' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1624 |  | -  echo 'User=root' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1625 |  | -  echo 'Group=root' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1626 |  | -  echo 'WorkingDirectory=/opt/tunneldigger/broker' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1627 |  | -  echo 'ExecStart=/opt/tunneldigger/broker/l2tp_broker.py l2tp_broker.cfg' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1628 |  | -  echo 'Restart=always' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1629 |  | -  echo 'Environment="USER=root" "HOME=/opt/tunneldigger/broker"' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1630 |  | -  echo '' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1631 |  | -  echo '[Install]' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1632 |  | -  echo 'WantedBy=multi-user.target' >> /etc/systemd/system/tunneldigger.service
 | 
	
		
			
			| 1633 |  | -  systemctl enable tunneldigger
 | 
	
		
			
			| 1634 |  | -  systemctl daemon-reload
 | 
	
		
			
			| 1635 |  | -  systemctl restart tunneldigger
 | 
	
		
			
			|  | 1583 | +  # TODO turn the following into a script which can be run on startup
 | 
	
		
			
			|  | 1584 | +
 | 
	
		
			
			|  | 1585 | +  # stop network manager to make the mesh network work
 | 
	
		
			
			|  | 1586 | +  service networking stop
 | 
	
		
			
			|  | 1587 | +
 | 
	
		
			
			|  | 1588 | +  # configure the wlan interface to operate with mtus of 1532(batman requires it) and turn enc off to ensure it works
 | 
	
		
			
			|  | 1589 | +  ifconfig wlan0 down
 | 
	
		
			
			|  | 1590 | +  ifconfig wlan0 mtu 1532
 | 
	
		
			
			|  | 1591 | +  iwconfig wlan0 enc off
 | 
	
		
			
			|  | 1592 | +
 | 
	
		
			
			|  | 1593 | +  # add the interface to the ad-hoc network - or create it.
 | 
	
		
			
			|  | 1594 | +  iwconfig wlan0 mode ad-hoc essid NetworkName ap $BATMAN_IPV6 channel 2
 | 
	
		
			
			|  | 1595 | +
 | 
	
		
			
			|  | 1596 | +  # add wlan0 to the batman-adv virtual interface(so it can communicate with other batman-adv nodes)
 | 
	
		
			
			|  | 1597 | +  batctl if add wlan0
 | 
	
		
			
			|  | 1598 | +  ifconfig wlan0 up
 | 
	
		
			
			|  | 1599 | +  ifconfig bat0 up
 | 
	
		
			
			|  | 1600 | +
 | 
	
		
			
			|  | 1601 | +  # make the bridge linking the batman-adv virtual interface to the ethernet port
 | 
	
		
			
			|  | 1602 | +  brctl addbr bridge-link
 | 
	
		
			
			|  | 1603 | +  brctl addif bridge-link bat0
 | 
	
		
			
			|  | 1604 | +  brctl addif bridge-link eth0
 | 
	
		
			
			|  | 1605 | +
 | 
	
		
			
			|  | 1606 | +  #get the ip address for the bridge from the dhcp server
 | 
	
		
			
			|  | 1607 | +  dhclient bridge-link
 | 
	
		
			
			| 1636 | 1608 |  
 | 
	
		
			
			| 1637 | 1609 |    if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
 | 
	
		
			
			| 1638 | 1610 |        echo '' >> /home/$MY_USERNAME/README
 |