freedombone/src/freedombone-client

425 lines
19 KiB
Plaintext
Raw Normal View History

2015-01-24 21:02:39 +01:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# License
# =======
#
# Copyright (C) 2015 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 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CURR_USER=$USER
# Version number of this script
2015-07-09 19:59:43 +02:00
VERSION="1.01"
2015-01-24 21:02:39 +01:00
2015-07-30 22:04:59 +02:00
WIFI_CHANNEL=2
WIFI_INTERFACE=wlan0
2015-07-30 22:04:59 +02:00
# B.A.T.M.A.N settings
BATMAN_CELLID='02:BA:00:00:03:01'
ESSID='mesh'
2015-07-30 22:24:38 +02:00
# Babel
BABEL_PORT=6696
2015-01-24 21:02:39 +01:00
# ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
SSH_CIPHERS="chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
SSH_MACS="hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com"
SSH_KEX="curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256"
SSH_HOST_KEY_ALGORITHMS="ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-ed25519,ssh-rsa"
# see https://stribika.github.io/2015/01/04/secure-secure-shell.html
function ssh_remove_small_moduli {
sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
}
function configure_ssh_client {
#sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
#sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
2015-08-09 11:06:29 +02:00
sudo cp /etc/ssh/ssh_config ~/ssh_config
2015-08-09 13:15:59 +02:00
sudo chown $CURR_USER:$CURR_USER ~/ssh_config
2015-08-09 10:59:28 +02:00
echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config
2015-08-09 13:15:59 +02:00
sudo chown root:root /etc/ssh/ssh_config
2015-01-24 21:02:39 +01:00
fi
sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
2015-08-09 11:06:29 +02:00
sudo cp /etc/ssh/ssh_config ~/ssh_config
2015-08-09 13:15:59 +02:00
sudo chown $CURR_USER:$CURR_USER ~/ssh_config
2015-08-09 10:59:28 +02:00
echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config
2015-08-09 13:15:59 +02:00
sudo chown root:root /etc/ssh/ssh_config
2015-01-24 21:02:39 +01:00
fi
sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
if ! grep -q "MACs " /etc/ssh/ssh_config; then
2015-08-09 11:06:29 +02:00
sudo cp /etc/ssh/ssh_config ~/ssh_config
2015-08-09 13:15:59 +02:00
sudo chown $CURR_USER:$CURR_USER ~/ssh_config
2015-08-09 10:59:28 +02:00
echo " MACs $SSH_MACS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config
2015-08-09 13:15:59 +02:00
sudo chown root:root /etc/ssh/ssh_config
2015-01-24 21:02:39 +01:00
fi
# Create ssh keys
if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
ssh-keygen -t ed25519 -o -a 100
fi
if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
ssh-keygen -t rsa -b 4096 -o -a 100
fi
ssh_remove_small_moduli
echo ''
echo 'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server'
echo ''
echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
echo ''
}
2015-07-30 22:22:37 +02:00
function mesh_babel {
sudo apt-get -y install babeld
babel_script=/tmp/babel
2015-08-08 11:01:41 +02:00
echo '#!/bin/bash' > $babel_script
2015-08-08 10:28:40 +02:00
echo '' >> $babel_script
2015-08-08 10:54:49 +02:00
echo 'if [[ $1 == "ls" || $1 == "list" ]]; then' >> $babel_script
2015-08-08 18:28:58 +02:00
echo ' avahi-browse -at' >> $babel_script
2015-08-08 10:54:49 +02:00
echo ' exit 0' >> $babel_script
echo 'fi' >> $babel_script
echo '' >> $babel_script
2015-08-08 10:42:50 +02:00
echo 'if [[ $1 == "start" ]]; then' >> $babel_script
2015-08-22 13:40:03 +02:00
echo ' if [ -f /tmp/meshtype ] ; then' >> $babel_script
echo ' echo "Mesh already running"' >> $babel_script
echo ' return' >> $babel_script
echo ' fi' >> $batman_script
2015-08-08 10:42:50 +02:00
echo ' # install avahi' >> $babel_script
2015-08-08 23:55:36 +02:00
echo ' apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd' >> $babel_script
2015-08-08 10:42:50 +02:00
echo ' sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
echo ' sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
echo ' if ! grep -q "avahi-daemon" /etc/crontab; then' >> $babel_script
2015-08-09 23:56:14 +02:00
echo ' if [ -f /bin/systemctl ]; then' >> $babel_script
2015-08-22 10:45:38 +02:00
echo " echo '* * * * * root systemctl restart avahi-daemon > /dev/null' >> /etc/crontab" >> $babel_script
2015-08-09 23:56:14 +02:00
echo ' else' >> $babel_script
2015-08-22 10:45:38 +02:00
echo " echo '* * * * * root service avahi-daemon restart > /dev/null' >> /etc/crontab" >> $babel_script
2015-08-09 23:56:14 +02:00
echo ' fi' >> $babel_script
echo ' fi' >> $babel_script
2015-08-08 10:42:50 +02:00
echo ' if [ -f /bin/systemctl ]; then' >> $babel_script
echo ' systemctl restart avahi-daemon' >> $babel_script
echo ' else' >> $babel_script
echo ' service avahi-daemon restart' >> $babel_script
2015-08-22 13:40:03 +02:00
echo ' echo "babel" > /tmp/meshtype' >> $babel_script
2015-08-08 10:42:50 +02:00
echo ' fi' >> $babel_script
2015-08-08 10:28:40 +02:00
echo 'fi' >> $babel_script
echo '' >> $babel_script
echo "IFACE=$WIFI_INTERFACE" >> $babel_script
echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
echo ' if grep -q "wlan1" /proc/net/dev; then' >> $babel_script
echo ' IFACE=wlan1' >> $babel_script
echo ' fi' >> $babel_script
2015-08-08 10:50:18 +02:00
echo 'fi' >> $babel_script
2015-08-09 20:28:03 +02:00
echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
echo ' if grep -q "wlan2" /proc/net/dev; then' >> $babel_script
echo ' IFACE=wlan2' >> $babel_script
echo ' fi' >> $babel_script
echo 'fi' >> $babel_script
echo 'if [[ $IFACE == "wlan0" ]]; then' >> $babel_script
echo ' if grep -q "wlan3" /proc/net/dev; then' >> $babel_script
echo ' IFACE=wlan3' >> $babel_script
echo ' fi' >> $babel_script
echo 'fi' >> $babel_script
2015-07-30 22:22:37 +02:00
echo '' >> $babel_script
2015-08-08 10:50:18 +02:00
echo 'if [[ ! grep -q "$IFACE" /proc/net/dev || $1 == "stop" ]]; then' >> $babel_script
echo ' if ! grep -q "$IFACE" /proc/net/dev; then' >> $babel_script
echo ' echo "Interface $IFACE was not found"' >> $babel_script
echo ' else' >> $babel_script
echo ' echo "Stopping"' >> $babel_script
echo ' fi' >> $babel_script
2015-07-30 22:22:37 +02:00
echo ' ifconfig $IFACE down' >> $babel_script
echo ' pkill babeld' >> $babel_script
2015-08-08 00:22:21 +02:00
echo ' if [ -f /bin/systemctl ]; then' >> $babel_script
2015-08-08 11:06:43 +02:00
echo ' systemctl restart network-manager' >> $babel_script
2015-08-08 00:22:21 +02:00
echo ' else' >> $babel_script
2015-08-08 00:48:47 +02:00
echo ' service network-manager restart' >> $babel_script
2015-08-08 00:22:21 +02:00
echo ' fi' >> $babel_script
2015-07-30 22:22:37 +02:00
echo ' exit 1' >> $babel_script
echo 'fi' >> $babel_script
echo '' >> $babel_script
2015-08-08 00:23:01 +02:00
echo 'if [ -f /bin/systemctl ]; then' >> $babel_script
2015-08-08 11:06:43 +02:00
echo ' systemctl stop network-manager' >> $babel_script
2015-08-08 00:23:01 +02:00
echo 'else' >> $babel_script
2015-08-08 00:48:47 +02:00
echo ' service network-manager stop' >> $babel_script
2015-08-08 00:23:01 +02:00
echo 'fi' >> $babel_script
2015-07-30 22:22:37 +02:00
echo 'ifconfig $IFACE down' >> $babel_script
echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script
echo "$WIFI_CHANNEL essid \"$ESSID\"" >> $babel_script
echo 'ifconfig $IFACE up' >> $babel_script
echo -n 'ifconfig $IFACE:avahi ' >> $babel_script
echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script
echo '255.255.255.0 broadcast 192.168.13.255' >> $babel_script
echo -n 'babeld -D $IFACE:avahi -p ' >> $babel_script
2015-08-08 16:36:27 +02:00
echo -n "$BABEL_PORT -d 5 " >> $babel_script
echo '$IFACE' >> $babel_script
2015-07-30 22:22:37 +02:00
echo 'exit 0' >> $babel_script
chmod +x $babel_script
sudo mv $babel_script /usr/bin/babel
}
function mesh_batman {
2015-07-30 22:22:37 +02:00
sudo apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
sudo apt-get -y install python-dev libevent-dev ebtables python-pip
sudo apt-get -y install wireless-tools rfkill
2015-07-30 22:04:59 +02:00
batman_script=/tmp/batman
2015-08-08 11:01:41 +02:00
echo '#!/bin/bash' > $batman_script
2015-07-30 22:04:59 +02:00
echo '' >> $batman_script
2015-08-08 10:41:50 +02:00
echo 'if [[ $1 == "start" ]]; then' >> $batman_script
echo ' # install avahi' >> $batman_script
2015-08-08 23:55:36 +02:00
echo ' apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd' >> $batman_script
2015-08-08 10:41:50 +02:00
echo ' sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
echo ' sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
2015-08-09 13:15:59 +02:00
echo ' sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
echo ' sed -i "s|use-ipv6=.*|use-ipv6=no|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
2015-08-09 23:14:41 +02:00
echo ' sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf' >> $batman_script
echo ' if ! grep -q "avahi-daemon" /etc/crontab; then' >> $batman_script
2015-08-09 23:56:14 +02:00
echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
2015-08-23 13:46:08 +02:00
echo " echo '* * * * * root systemctl restart avahi-daemon > /dev/null' >> /etc/crontab" >> $batman_script
2015-08-09 23:56:14 +02:00
echo ' else' >> $batman_script
2015-08-23 13:46:08 +02:00
echo " echo '* * * * * root service avahi-daemon restart > /dev/null' >> /etc/crontab" >> $batman_script
2015-08-09 23:56:14 +02:00
echo ' fi' >> $batman_script
echo ' fi' >> $batman_script
2015-08-08 10:28:40 +02:00
echo 'fi' >> $batman_script
echo '' >> $batman_script
2015-07-30 22:04:59 +02:00
echo '# Mesh definition' >> $batman_script
echo "ESSID=$ESSID" >> $batman_script
echo "CELLID=$BATMAN_CELLID" >> $batman_script
echo "CHANNEL=$WIFI_CHANNEL" >> $batman_script
echo '' >> $batman_script
2015-08-08 18:56:56 +02:00
echo '# Ethernet bridge definition (bridged to bat0)' >> $batman_script
2015-07-30 22:04:59 +02:00
echo 'BRIDGE=br-mesh' >> $batman_script
echo "IFACE=$WIFI_INTERFACE" >> $batman_script
2015-07-30 22:04:59 +02:00
echo 'EIFACE=eth0' >> $batman_script
2015-08-08 00:26:40 +02:00
echo '' >> $batman_script
echo 'if [[ $IFACE == "wlan0" ]]; then' >> $batman_script
echo ' if grep -q "wlan1" /proc/net/dev; then' >> $batman_script
echo ' IFACE=wlan1' >> $batman_script
echo ' fi' >> $batman_script
2015-08-08 00:26:40 +02:00
echo 'fi' >> $batman_script
2015-08-09 20:28:03 +02:00
echo 'if [[ $IFACE == "wlan0" ]]; then' >> $batman_script
echo ' if grep -q "wlan2" /proc/net/dev; then' >> $batman_script
echo ' IFACE=wlan2' >> $batman_script
echo ' fi' >> $batman_script
echo 'fi' >> $batman_script
echo 'if [[ $IFACE == "wlan0" ]]; then' >> $batman_script
echo ' if grep -q "wlan3" /proc/net/dev; then' >> $batman_script
echo ' IFACE=wlan3' >> $batman_script
echo ' fi' >> $batman_script
echo 'fi' >> $batman_script
2015-07-30 22:04:59 +02:00
echo '' >> $batman_script
echo 'if [ -e /etc/default/batctl ]; then' >> $batman_script
echo ' . /etc/default/batctl' >> $batman_script
echo 'fi' >> $batman_script
echo '' >> $batman_script
echo 'start() {' >> $batman_script
2015-08-22 13:40:03 +02:00
echo ' if [ -f /tmp/meshtype ] ; then' >> $batman_script
echo ' echo "Mesh already running"' >> $batman_script
echo ' return' >> $batman_script
echo ' fi' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' if [ -z "$IFACE" ] ; then' >> $batman_script
echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> $batman_script
echo ' return' >> $batman_script
echo ' fi' >> $batman_script
echo ' echo "info: enabling batman-adv mesh network $ESSID on $IFACE"' >> $batman_script
2015-08-07 23:53:28 +02:00
echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
2015-08-08 11:06:43 +02:00
echo ' systemctl stop network-manager' >> $batman_script
2015-08-07 23:53:28 +02:00
echo ' else' >> $batman_script
2015-08-08 00:48:47 +02:00
echo ' service network-manager stop' >> $batman_script
2015-08-07 23:53:28 +02:00
echo ' fi' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' sleep 5' >> $batman_script
echo '' >> $batman_script
2015-08-09 12:10:56 +02:00
echo " # remove an avahi service which isn't used" >> $batman_script
echo ' if [ -f /etc/avahi/services/udisks.service ]; then' >> $batman_script
echo ' sudo rm /etc/avahi/services/udisks.service' >> $batman_script
echo ' fi' >> $batman_script
echo '' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' # Might have to re-enable wifi' >> $batman_script
echo ' rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true' >> $batman_script
echo '' >> $batman_script
echo ' ifconfig $IFACE down' >> $batman_script
2015-08-08 20:35:45 +02:00
echo ' ifconfig $IFACE mtu 1532' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' iwconfig $IFACE enc off' >> $batman_script
echo ' iwconfig $IFACE mode ad-hoc essid $ESSID channel $CHANNEL' >> $batman_script
echo ' sleep 1' >> $batman_script
echo ' iwconfig $IFACE ap $CELLID' >> $batman_script
echo '' >> $batman_script
echo ' modprobe batman-adv' >> $batman_script
echo ' batctl if add $IFACE' >> $batman_script
echo ' ifconfig $IFACE up' >> $batman_script
2015-08-09 16:05:38 +02:00
echo ' avahi-autoipd --force-bind --daemonize --wait $BRIDGE' >> $batman_script
echo ' avahi-autoipd --force-bind --daemonize --wait $IFACE' >> $batman_script
2015-08-09 12:13:21 +02:00
echo ' ifconfig bat0 up promisc' >> $batman_script
2015-07-30 22:04:59 +02:00
echo '' >> $batman_script
echo ' #Use persistent HWAddr' >> $batman_script
echo ' ether_new=$(ifconfig eth0 | grep HWaddr | sed -e "s/.*HWaddr //")' >> $batman_script
2015-08-08 23:55:36 +02:00
echo ' if [ ! -f /var/lib/mesh-node/bat0 ]; then' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' mkdir /var/lib/mesh-node' >> $batman_script
echo ' echo "${ether_new}" > /var/lib/mesh-node/bat0' >> $batman_script
echo ' else' >> $batman_script
echo ' ether=$(cat /var/lib/mesh-node/bat0)' >> $batman_script
echo ' ifconfig bat0 hw ether ${ether}' >> $batman_script
echo ' fi' >> $batman_script
echo '' >> $batman_script
echo ' if [ "$EIFACE" ] ; then' >> $batman_script
echo ' brctl addbr $BRIDGE' >> $batman_script
echo ' brctl addif $BRIDGE bat0' >> $batman_script
echo ' brctl addif $BRIDGE $EIFACE' >> $batman_script
2015-08-08 19:45:53 +02:00
echo ' ifconfig bat0 0.0.0.0' >> $batman_script
echo ' ifconfig $EIFACE 0.0.0.0' >> $batman_script
echo ' ifconfig $EIFACE up promisc' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' ifconfig $BRIDGE up' >> $batman_script
echo ' fi' >> $batman_script
echo '' >> $batman_script
2015-08-09 16:38:14 +02:00
echo ' iptables -A INPUT -p tcp -m state -m tcp --dport 548 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 22:39:10 +02:00
echo ' iptables -A INPUT -p udp -m state -m udp --dport 548 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 16:38:14 +02:00
echo ' iptables -A INPUT -p tcp -m state -m tcp --dport 5353 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 22:39:10 +02:00
echo ' iptables -A INPUT -p udp -m state -m udp --dport 5353 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 16:38:14 +02:00
echo ' iptables -A INPUT -p tcp -m state -m tcp --dport 5354 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 22:39:10 +02:00
echo ' iptables -A INPUT -p udp -m state -m udp --dport 5354 --state NEW -j ACCEPT' >> $batman_script
2015-08-08 19:31:18 +02:00
echo '' >> $batman_script
echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
echo ' systemctl restart avahi-daemon' >> $batman_script
echo ' else' >> $batman_script
echo ' service avahi-daemon restart' >> $batman_script
echo ' fi' >> $batman_script
2015-08-22 13:40:03 +02:00
echo ' echo "batman" > /tmp/meshtype' >> $batman_script
2015-07-30 22:04:59 +02:00
echo '}' >> $batman_script
echo '' >> $batman_script
echo 'stop() {' >> $batman_script
2015-08-08 16:50:56 +02:00
echo ' if [ -z "$IFACE" ]; then' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> $batman_script
echo ' return' >> $batman_script
echo ' fi' >> $batman_script
2015-08-08 16:50:56 +02:00
echo ' if [ "$EIFACE" ]; then' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' brctl delif $BRIDGE bat0' >> $batman_script
echo ' brctl delif $BRIDGE $EIFACE' >> $batman_script
echo ' ifconfig $BRIDGE down || true' >> $batman_script
echo ' brctl delbr $BRIDGE' >> $batman_script
echo ' ifconfig $EIFACE down -promisc' >> $batman_script
echo ' fi' >> $batman_script
echo '' >> $batman_script
2015-08-09 13:28:59 +02:00
echo ' avahi-autoipd -k $BRIDGE' >> $batman_script
2015-08-09 13:50:56 +02:00
echo ' avahi-autoipd -k $IFACE' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' ifconfig bat0 down -promisc' >> $batman_script
echo '' >> $batman_script
echo ' batctl if del $IFACE' >> $batman_script
echo ' rmmod batman-adv' >> $batman_script
echo ' ifconfig $IFACE mtu 1500' >> $batman_script
echo ' ifconfig $IFACE down' >> $batman_script
echo ' iwconfig $IFACE mode managed' >> $batman_script
echo '' >> $batman_script
2015-08-09 16:38:14 +02:00
echo ' iptables -D INPUT -p tcp -m state -m tcp --dport 548 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 22:39:10 +02:00
echo ' iptables -D INPUT -p udp -m state -m udp --dport 548 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 16:38:14 +02:00
echo ' iptables -D INPUT -p tcp -m state -m tcp --dport 5353 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 22:39:10 +02:00
echo ' iptables -D INPUT -p udp -m state -m udp --dport 5353 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 16:38:14 +02:00
echo ' iptables -D INPUT -p tcp -m state -m tcp --dport 5354 --state NEW -j ACCEPT' >> $batman_script
2015-08-09 22:39:10 +02:00
echo ' iptables -D INPUT -p udp -m state -m udp --dport 5354 --state NEW -j ACCEPT' >> $batman_script
2015-08-08 19:31:18 +02:00
echo '' >> $batman_script
2015-08-07 23:53:28 +02:00
echo ' if [ -f /bin/systemctl ]; then' >> $batman_script
2015-08-08 11:06:43 +02:00
echo ' systemctl restart network-manager' >> $batman_script
2015-08-07 23:53:28 +02:00
echo ' else' >> $batman_script
2015-08-08 00:48:47 +02:00
echo ' service network-manager restart' >> $batman_script
2015-08-07 23:53:28 +02:00
echo ' fi' >> $batman_script
2015-08-22 13:40:03 +02:00
echo ' rm -f /tmp/meshtype' >> $batman_script
2015-07-30 22:04:59 +02:00
echo '}' >> $batman_script
echo '' >> $batman_script
2015-08-08 00:26:40 +02:00
echo 'if ! grep -q "$IFACE" /proc/net/dev; then' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' echo "Interface $IFACE was not found"' >> $batman_script
echo ' stop' >> $batman_script
echo ' exit 1' >> $batman_script
echo 'fi' >> $batman_script
echo '' >> $batman_script
echo 'case "$1" in' >> $batman_script
echo ' start|stop)' >> $batman_script
echo ' $1' >> $batman_script
echo ' ;;' >> $batman_script
2015-08-08 18:02:27 +02:00
echo ' restart)' >> $batman_script
echo ' stop' >> $batman_script
echo ' sleep 10' >> $batman_script
echo ' start' >> $batman_script
echo ' ;;' >> $batman_script
2015-08-08 00:35:45 +02:00
echo ' status)' >> $batman_script
echo ' batctl o' >> $batman_script
echo ' ;;' >> $batman_script
2015-08-09 10:54:44 +02:00
echo ' ping)' >> $batman_script
echo ' batctl ping $2' >> $batman_script
echo ' ;;' >> $batman_script
2015-08-08 10:54:49 +02:00
echo ' ls|list)' >> $batman_script
2015-08-08 18:28:58 +02:00
echo ' avahi-browse -at' >> $batman_script
2015-08-08 10:54:49 +02:00
echo ' ;;' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' *)' >> $batman_script
echo ' echo "error: invalid parameter $1"' >> $batman_script
2015-08-09 10:54:44 +02:00
echo ' echo "usage: $0 {start|stop|restart|status|ping|ls|list}"' >> $batman_script
2015-07-30 22:04:59 +02:00
echo ' exit 2' >> $batman_script
echo ' ;;' >> $batman_script
echo 'esac' >> $batman_script
echo 'exit 0' >> $batman_script
chmod +x $batman_script
sudo mv $batman_script /usr/bin/batman
}
function show_help {
echo ''
2015-07-30 22:26:39 +02:00
echo 'freedombone-client'
echo ''
exit 0
}
while [[ $# > 1 ]]
do
key="$1"
case $key in
-h|--help)
show_help
;;
*)
# unknown option
;;
esac
shift
done
2015-01-24 21:02:39 +01:00
echo 'Configuring client'
configure_ssh_client
mesh_batman
2015-07-30 22:22:37 +02:00
mesh_babel
2015-01-24 21:02:39 +01:00
echo 'Configuration complete'
exit 0