| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 | #!/bin/bash
#
# .---.                  .              .
# |                      |              |
# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
#
#                    Freedom in the Cloud
#
# batman adv mesh functions
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
VARIANTS='mesh'
ENABLE_BATMAN="no"
BATMAN_CELLID='any'
function configure_firewall_for_batma {
    if grep -Fxq "configure_firewall_for_batman" $COMPLETION_FILE; then
	return
    fi
    if [[ $ENABLE_BATMAN != "yes" ]]; then
	return
    fi
    function_check save_firewall_settings
    save_firewall_settings
    echo 'configure_firewall_for_batman' >> $COMPLETION_FILE
}
function reconfigure_batman {
    echo -n ''
}
function upgrade_batman {
    echo -n ''
}
function backup_local_batman {
    echo -n ''
}
function restore_local_batman {
    echo -n ''
}
function backup_remote_batman {
    echo -n ''
}
function restore_remote_batman {
    echo -n ''
}
function remove_batman {
    if ! grep -Fxq "install_batman" $COMPLETION_FILE; then
	return
    fi
    ${PROJECT_NAME}-mesh-install -f batman --remove yes
    if [ ! "$?" = "0" ]; then
	echo $'Failed to remove batman'
	exit 79353
    fi
    sed -i '/install_batman/d' $COMPLETION_FILE
    sed -i '/configure_firewall_for_batman/d' $COMPLETION_FILE
}
function mesh_install_batman {
    chroot "$rootdir" apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
    chroot "$rootdir" apt-get -y install python-dev libevent-dev ebtables python-pip git
    chroot "$rootdir" apt-get -y install wireless-tools rfkill
    if ! grep -q "batman_adv" $rootdir/etc/modules; then
	echo 'batman_adv' >> $rootdir/etc/modules
    fi
    BATMAN_SCRIPT=$rootdir/var/lib/batman
    if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
	cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
    else
	cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
    fi
    BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
    echo '[Unit]' > $BATMAN_DAEMON
    echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
    echo 'After=network.target' >> $BATMAN_DAEMON
    echo '' >> $BATMAN_DAEMON
    echo '[Service]' >> $BATMAN_DAEMON
    echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
    echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
    echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
    echo 'Restart=on-failure' >> $BATMAN_DAEMON
    echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
    echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
    echo '' >> $BATMAN_DAEMON
    echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
    echo 'TimeoutSec=300' >> $BATMAN_DAEMON
    echo '' >> $BATMAN_DAEMON
    echo '[Install]' >> $BATMAN_DAEMON
    echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
    chroot "$rootdir" systemctl enable batman
}
function install_batman {
    if [ $INSTALLING_MESH ]; then
	mesh_install_batman
	return
    fi
    if grep -Fxq "install_batman" $COMPLETION_FILE; then
	return
    fi
    if [[ $ENABLE_BATMAN != "yes" ]]; then
	return
    fi
    ${PROJECT_NAME}-mesh-install -f batman
    if [ ! "$?" = "0" ]; then
	echo $'Failed to install batman'
	exit 72524
    fi
    if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
	echo '' >> /home/$MY_USERNAME/README
	echo '' >> /home/$MY_USERNAME/README
	echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
	echo '=============================' >> /home/$MY_USERNAME/README
	echo "Mesh ESSID: $WIFI_SSID" >> /home/$MY_USERNAME/README
	echo "Mesh cell ID: $BATMAN_CELLID" >> /home/$MY_USERNAME/README
	echo "Mesh wifi channel: $WIFI_CHANNEL" >> /home/$MY_USERNAME/README
	chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
	chmod 600 /home/$MY_USERNAME/README
    fi
    function_check configure_firewall_for_batman
    configure_firewall_for_batman
    echo 'install_batman' >> $COMPLETION_FILE
}
# NOTE: deliberately no exit 0
 |