2016-07-03 17:13:34 +02:00
|
|
|
#!/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/>.
|
|
|
|
|
2016-09-30 11:06:30 +02:00
|
|
|
VARIANTS=''
|
2016-07-06 17:47:55 +02:00
|
|
|
|
2016-07-03 17:13:34 +02:00
|
|
|
ENABLE_BATMAN="no"
|
|
|
|
BATMAN_CELLID='any'
|
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
batman_variables=(MY_USERNAME
|
|
|
|
BATMAN_CELLID)
|
|
|
|
|
2016-09-30 12:34:39 +02:00
|
|
|
function install_interactive_batman {
|
|
|
|
echo -n ''
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=1
|
2016-09-30 12:34:39 +02:00
|
|
|
}
|
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
function change_password_batman {
|
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
|
|
|
function configure_firewall_for_batman {
|
2016-07-24 14:19:56 +02:00
|
|
|
if grep -Fxq "configure_firewall_for_batman" $COMPLETION_FILE; then
|
2016-09-25 12:20:41 +02:00
|
|
|
return
|
2016-07-24 14:19:56 +02:00
|
|
|
fi
|
|
|
|
if [[ $ENABLE_BATMAN != "yes" ]]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
return
|
2016-07-24 14:19:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
function_check save_firewall_settings
|
|
|
|
save_firewall_settings
|
|
|
|
echo 'configure_firewall_for_batman' >> $COMPLETION_FILE
|
2016-07-03 20:54:48 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 12:36:12 +02:00
|
|
|
function reconfigure_batman {
|
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
2016-07-06 16:01:28 +02:00
|
|
|
function upgrade_batman {
|
2016-07-09 12:15:41 +02:00
|
|
|
echo -n ''
|
2016-07-06 16:01:28 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:55:09 +02:00
|
|
|
function backup_local_batman {
|
2016-07-09 12:15:41 +02:00
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore_local_batman {
|
|
|
|
echo -n ''
|
2016-07-06 15:55:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function backup_remote_batman {
|
2016-07-09 12:15:41 +02:00
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore_remote_batman {
|
|
|
|
echo -n ''
|
2016-07-04 22:02:22 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 20:54:48 +02:00
|
|
|
function remove_batman {
|
2016-07-24 14:19:56 +02:00
|
|
|
${PROJECT_NAME}-mesh-install -f batman --remove yes
|
|
|
|
if [ ! "$?" = "0" ]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
echo $'Failed to remove batman'
|
|
|
|
exit 79353
|
2016-07-24 14:19:56 +02:00
|
|
|
fi
|
|
|
|
sed -i '/install_batman/d' $COMPLETION_FILE
|
|
|
|
sed -i '/configure_firewall_for_batman/d' $COMPLETION_FILE
|
2016-07-03 19:52:57 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 09:27:11 +02:00
|
|
|
function mesh_install_batman {
|
2016-07-24 14:19:56 +02:00
|
|
|
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
|
2016-09-25 12:20:41 +02:00
|
|
|
echo 'batman_adv' >> $rootdir/etc/modules
|
2016-07-24 14:19:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
BATMAN_SCRIPT=$rootdir/var/lib/batman
|
|
|
|
|
|
|
|
if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
|
2016-07-24 14:19:56 +02:00
|
|
|
else
|
2016-09-25 12:20:41 +02:00
|
|
|
cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
|
2016-07-24 14:19:56 +02:00
|
|
|
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
|
2016-07-12 09:27:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-05 09:22:33 +02:00
|
|
|
function install_batman {
|
2016-07-24 14:19:56 +02:00
|
|
|
if [ $INSTALLING_MESH ]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
mesh_install_batman
|
|
|
|
return
|
2016-07-24 14:19:56 +02:00
|
|
|
fi
|
|
|
|
if [[ $ENABLE_BATMAN != "yes" ]]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
return
|
2016-07-24 14:19:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
${PROJECT_NAME}-mesh-install -f batman
|
|
|
|
if [ ! "$?" = "0" ]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
echo $'Failed to install batman'
|
|
|
|
exit 72524
|
2016-07-24 14:19:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
|
2016-09-25 12:20:41 +02:00
|
|
|
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
|
2016-07-24 14:19:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
function_check configure_firewall_for_batman
|
|
|
|
configure_firewall_for_batman
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=1
|
2016-07-03 17:13:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: deliberately no exit 0
|