Skip to content
Snippets Groups Projects
freedombone-app-batman 4.23 KiB
Newer Older
Bob Mottram's avatar
Bob Mottram committed
#!/bin/bash
Bob Mottram's avatar
Bob Mottram committed
#  _____               _           _
# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
Bob Mottram's avatar
Bob Mottram committed
#
Bob Mottram's avatar
Bob Mottram committed
#                              Freedom in the Cloud
Bob Mottram's avatar
Bob Mottram committed
#
# batman adv mesh functions
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2014-2019 Bob Mottram <bob@freedombone.net>
Bob Mottram's avatar
Bob Mottram committed
#
# 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=''
Bob Mottram's avatar
Bob Mottram committed
ENABLE_BATMAN="no"
BATMAN_CELLID='any'

Bob Mottram's avatar
Bob Mottram committed
batman_variables=(MY_USERNAME
                  BATMAN_CELLID)

function logging_on_batman {
    echo -n ''
}

function logging_off_batman {
    echo -n ''
}

function install_interactive_batman {
    echo -n ''
    APP_INSTALLED=1
function configure_firewall_for_batman {
Bob Mottram's avatar
Bob Mottram committed
    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
Bob Mottram's avatar
Bob Mottram committed
    fi
    if [[ $ENABLE_BATMAN != "yes" ]]; then
Bob Mottram's avatar
Bob Mottram committed
    fi

    function_check save_firewall_settings
    save_firewall_settings
Bob Mottram's avatar
Bob Mottram committed
    mark_completed "${FUNCNAME[0]}"
function reconfigure_batman {
    echo -n ''
}

function upgrade_batman {
Bob Mottram's avatar
Bob Mottram committed
    echo -n ''
Bob Mottram's avatar
Bob Mottram committed
function backup_local_batman {
Bob Mottram's avatar
Bob Mottram committed
    echo -n ''
}

function restore_local_batman {
    echo -n ''
Bob Mottram's avatar
Bob Mottram committed
}

function backup_remote_batman {
Bob Mottram's avatar
Bob Mottram committed
    echo -n ''
}

function restore_remote_batman {
    echo -n ''
Bob Mottram's avatar
Bob Mottram committed
function remove_batman {
Bob Mottram's avatar
Bob Mottram committed
    if ! "${PROJECT_NAME}-mesh-install" -f batman --remove yes; then
        echo $'Failed to remove batman'
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    remove_completion_param install_batman
    remove_completion_param configure_firewall_for_batman
function mesh_install_batman {
    # shellcheck disable=SC2154,SC2086
    chroot "$rootdir" $INSTALL_PACKAGES iproute bridge-utils libnetfilter-conntrack3 batctl
    # shellcheck disable=SC2154,SC2086
    chroot "$rootdir" $INSTALL_PACKAGES python-dev libevent-dev ebtables python-pip git
    # shellcheck disable=SC2154,SC2086
    chroot "$rootdir" $INSTALL_PACKAGES wireless-tools rfkill
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q "batman_adv" "$rootdir/etc/modules"; then
        echo 'batman_adv' >> "$rootdir/etc/modules"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q "tunnel6" "$rootdir/etc/modules"; then
        echo 'tunnel6' >> "$rootdir/etc/modules"
    fi
    if ! grep -q "ip6_tunnel" "$rootdir/etc/modules"; then
        echo 'ip6_tunnel' >> "$rootdir/etc/modules"
    fi
Bob Mottram's avatar
Bob Mottram committed

    BATMAN_SCRIPT=$rootdir/var/lib/batman

Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/usr/local/bin/${PROJECT_NAME}-mesh-batman" ]; then
        cp "/usr/local/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
Bob Mottram's avatar
Bob Mottram committed
    else
Bob Mottram's avatar
Bob Mottram committed
        cp "/usr/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
Bob Mottram's avatar
Bob Mottram committed
    fi

    BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
Bob Mottram's avatar
Bob Mottram committed
    { echo '[Unit]';
      echo 'Description=B.A.T.M.A.N. Advanced';
      echo 'After=network.target';
      echo '';
      echo '[Service]';
      echo 'RemainAfterExit=yes';
      echo "ExecStart=/var/lib/batman start";
      echo "ExecStop=/var/lib/batman stop";
      echo 'Restart=on-failure';
      echo 'SuccessExitStatus=3 4';
      echo 'RestartForceExitStatus=3 4';
      echo '';
      echo '# Allow time for the server to start/stop';
      echo 'TimeoutSec=300';
      echo '';
      echo '[Install]';
      echo 'WantedBy=multi-user.target'; } > "$BATMAN_DAEMON"
Bob Mottram's avatar
Bob Mottram committed
    chroot "$rootdir" systemctl enable batman
Bob Mottram's avatar
Bob Mottram committed
function install_batman {
Bob Mottram's avatar
Bob Mottram committed
    if [ "$INSTALLING_MESH" ]; then
        mesh_install_batman
        return
Bob Mottram's avatar
Bob Mottram committed
    fi
    if [[ $ENABLE_BATMAN != "yes" ]]; then
Bob Mottram's avatar
Bob Mottram committed
    fi

Bob Mottram's avatar
Bob Mottram committed
    if ! "${PROJECT_NAME}-mesh-install" -f batman; then
        echo $'Failed to install batman'
Bob Mottram's avatar
Bob Mottram committed
    fi

    function_check configure_firewall_for_batman
    configure_firewall_for_batman
Bob Mottram's avatar
Bob Mottram committed
}

# NOTE: deliberately no exit 0