From 73d2ce5ee70caff63879de6cbd66afe4c752f56e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 25 Jul 2015 22:43:57 +0100 Subject: [PATCH] Batman init script --- src/freedombone | 159 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 2 deletions(-) diff --git a/src/freedombone b/src/freedombone index 67641fa6..756f7ff4 100755 --- a/src/freedombone +++ b/src/freedombone @@ -1608,7 +1608,7 @@ function install_atheros_wifi { fi # have drivers already been installed ? if [ -f /lib/firmware/htc_9271.fw ]; then - return + return fi apt-get -y install build-essential cmake git m4 texinfo if [ ! -d $INSTALL_DIR ]; then @@ -1703,7 +1703,7 @@ function mesh_batman_bridge { apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl apt-get -y install python-dev libevent-dev ebtables python-pip git - apt-get -y install wireless-tools + apt-get -y install wireless-tools rfkill #install_vpn_tunnel @@ -1726,6 +1726,161 @@ function mesh_batman_bridge { BATMAN_IPV6="$IPV6_NETWORK:$a:$b:$c:$d" fi + echo '#!/bin/sh' > /etc/init.d/batman + echo '### BEGIN INIT INFO' >> /etc/init.d/batman + echo '# Provides: mesh-node' >> /etc/init.d/batman + echo '# Required-Start: $local_fs $remote_fs $network' >> /etc/init.d/batman + echo '# Required-Stop: $local_fs $remote_fs' >> /etc/init.d/batman + echo '# Default-Start: 2 3 4 5' >> /etc/init.d/batman + echo '# Default-Stop: 0 1 6' >> /etc/init.d/batman + echo '# Short-Description: Enable batman-adv based mesh node' >> /etc/init.d/batman + echo '# Description: Configure the first wifi network card found as a' >> /etc/init.d/batman + echo '# batman-adv mesh node.' >> /etc/init.d/batman + echo '### END INIT INFO' >> /etc/init.d/batman + echo '#' >> /etc/init.d/batman + echo '# Based on http://www.open-mesh.org/projects/batman-adv/wiki/Quick-start-guide' >> /etc/init.d/batman + echo '# and http://freifunk.in-kiel.de/wiki/Eigenen_Rechner_in_das_Freifunk-Netz' >> /etc/init.d/batman + echo '#' >> /etc/init.d/batman + echo '# Set up bat0 network interface on Linux to join the mesh network in' >> /etc/init.d/batman + echo '# Oslo, Norway by default. The mesh setup can be adjusted by creating' >> /etc/init.d/batman + echo '# /etc/default/batctl.' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo '# Exit on first error' >> /etc/init.d/batman + echo '#set -e' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo '# Mesh definition' >> /etc/init.d/batman + echo "ESSID=mesh" >> /etc/init.d/batman + echo "CELLID=02:BA:00:00:03:01" >> /etc/init.d/batman + echo 'CHANNEL=2' >> /etc/init.d/batman + echo 'FREQUENCY=2437' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo '# Ethernet bridge definition (bridged do bat0)' >> /etc/init.d/batman + echo 'BRIDGE=br-mesh' >> /etc/init.d/batman + echo 'EIFACE=wlan0' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo 'if [ -e /etc/default/batctl ] ; then' >> /etc/init.d/batman + echo ' . /etc/default/batctl' >> /etc/init.d/batman + echo 'fi' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo 'install_dependencies() {' >> /etc/init.d/batman + echo ' echo "info: installing dependencies"' >> /etc/init.d/batman + echo ' apt-get update -qq' >> /etc/init.d/batman + echo ' DEBIAN_FRONTEND=noninteractive \' >> /etc/init.d/batman + echo ' apt-get install -qqy \' >> /etc/init.d/batman + echo ' rfkill \' >> /etc/init.d/batman + echo ' batctl \' >> /etc/init.d/batman + echo ' wireless-tools \' >> /etc/init.d/batman + echo ' bridge-utils ' >> /etc/init.d/batman + echo '}' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo 'first_wifi_interface() {' >> /etc/init.d/batman + echo ' IFACE=$(ls -d /sys/class/net/*/wireless 2>/dev/null | sort | head -1|cut -d/ -f5)' >> /etc/init.d/batman + echo ' if [ -z "$IFACE" ] ;then' >> /etc/init.d/batman + echo ' IFACE=$(iwconfig 2>/dev/null | sort | awk "/IEEE 802/ {print $1; exit}")' >> /etc/init.d/batman + echo ' fi' >> /etc/init.d/batman + echo ' echo $IFACE' >> /etc/init.d/batman + echo '}' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo 'start() {' >> /etc/init.d/batman + echo ' if [ -z "$IFACE" ] ; then' >> /etc/init.d/batman + echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> /etc/init.d/batman + echo ' return' >> /etc/init.d/batman + echo ' fi' >> /etc/init.d/batman + echo ' echo "info: enabling batman-adv mesh network $ESSID on $IFACE"' >> /etc/init.d/batman + echo ' $NETWORKMANAGER stop' >> /etc/init.d/batman + echo ' sleep 5' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo ' # Might have to re-enable wifi' >> /etc/init.d/batman + echo ' rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo ' ifconfig $IFACE down' >> /etc/init.d/batman + echo ' ifconfig $IFACE mtu 1528' >> /etc/init.d/batman + echo ' iwconfig $IFACE enc off' >> /etc/init.d/batman + echo ' iwconfig $IFACE mode ad-hoc essid $ESSID channel $CHANNEL' >> /etc/init.d/batman + echo ' sleep 1' >> /etc/init.d/batman + echo ' iwconfig $IFACE ap $CELLID' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo ' modprobe batman-adv' >> /etc/init.d/batman + echo ' batctl if add $IFACE' >> /etc/init.d/batman + echo ' ifconfig $IFACE up' >> /etc/init.d/batman + echo ' ifconfig bat0 up promisc' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo ' #Use persistent HWAddr' >> /etc/init.d/batman + echo ' ether_new=$(ifconfig eth0 | grep HWaddr | sed -e "s/.*HWaddr //")' >> /etc/init.d/batman + echo ' if [ ! -f /var/lib/mesh-node/bat0 ]' >> /etc/init.d/batman + echo ' then' >> /etc/init.d/batman + echo ' mkdir /var/lib/mesh-node' >> /etc/init.d/batman + echo ' echo "${ether_new}" > /var/lib/mesh-node/bat0' >> /etc/init.d/batman + echo ' else' >> /etc/init.d/batman + echo ' ether=$(cat /var/lib/mesh-node/bat0)' >> /etc/init.d/batman + echo ' ifconfig bat0 hw ether ${ether}' >> /etc/init.d/batman + echo ' fi' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo ' if [ "$EIFACE" ] ; then' >> /etc/init.d/batman + echo ' ifconfig $EIFACE up promisc' >> /etc/init.d/batman + echo ' brctl addbr $BRIDGE' >> /etc/init.d/batman + echo ' brctl addif $BRIDGE bat0' >> /etc/init.d/batman + echo ' brctl addif $BRIDGE $EIFACE' >> /etc/init.d/batman + echo ' ifconfig $BRIDGE up' >> /etc/init.d/batman + echo ' fi' >> /etc/init.d/batman + echo '}' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo 'stop() {' >> /etc/init.d/batman + echo ' if [ -z "$IFACE" ] ; then' >> /etc/init.d/batman + echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> /etc/init.d/batman + echo ' return' >> /etc/init.d/batman + echo ' fi' >> /etc/init.d/batman + echo ' if [ "$EIFACE" ] ; then' >> /etc/init.d/batman + echo ' brctl delif $BRIDGE bat0' >> /etc/init.d/batman + echo ' brctl delif $BRIDGE $EIFACE' >> /etc/init.d/batman + echo ' ifconfig $BRIDGE down || true' >> /etc/init.d/batman + echo ' brctl delbr $BRIDGE' >> /etc/init.d/batman + echo ' ifconfig $EIFACE down -promisc' >> /etc/init.d/batman + echo ' fi' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo ' ifconfig bat0 down -promisc' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo ' batctl if del $IFACE' >> /etc/init.d/batman + echo ' rmmod batman-adv' >> /etc/init.d/batman + echo ' ifconfig $IFACE mtu 1500' >> /etc/init.d/batman + echo ' ifconfig $IFACE down' >> /etc/init.d/batman + echo ' iwconfig $IFACE mode managed' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo ' $NETWORKMANAGER restart' >> /etc/init.d/batman + echo '}' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo 'status() {' >> /etc/init.d/batman + echo ' batctl o' >> /etc/init.d/batman + echo '}' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo 'IFACE=$(first_wifi_interface)' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo '# Work even if network-manager isnt installed' >> /etc/init.d/batman + echo 'if [ -e /etc/init.d/network-manager ] || [ -e /etc/init/network-manager ] ; then' >> /etc/init.d/batman + echo ' NETWORKMANAGER="service network-manager"' >> /etc/init.d/batman + echo 'else' >> /etc/init.d/batman + echo ' NETWORKMANAGER=true' >> /etc/init.d/batman + echo 'fi' >> /etc/init.d/batman + echo '' >> /etc/init.d/batman + echo 'case "$1" in' >> /etc/init.d/batman + echo ' setup)' >> /etc/init.d/batman + echo ' install_dependencies' >> /etc/init.d/batman + echo ' ;;' >> /etc/init.d/batman + echo ' start|stop|status)' >> /etc/init.d/batman + echo ' $1' >> /etc/init.d/batman + echo ' ;;' >> /etc/init.d/batman + echo ' force-reload)' >> /etc/init.d/batman + echo ' ;;' >> /etc/init.d/batman + echo ' *)' >> /etc/init.d/batman + echo ' echo "error: invalid parameter $1"' >> /etc/init.d/batman + echo ' echo "usage: $0 {start|stop|status}"' >> /etc/init.d/batman + echo ' exit 1' >> /etc/init.d/batman + echo ' ;;' >> /etc/init.d/batman + echo 'esac' >> /etc/init.d/batman + echo 'exit 0' >> /etc/init.d/batman + chmod +x /etc/init.d/batman + update-rc.d batman defaults + if ! grep -q "# Mesh Networking (B.A.T.M.A.N)" /etc/network/interfaces; then echo '' >> /etc/network/interfaces echo '# Mesh Networking (B.A.T.M.A.N)' >> /etc/network/interfaces