freedombone/src/freedombone-mesh

106 lines
2.5 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# A script to easily locate mesh peers and start communicating
# 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/>.
IRC_PORT=6697
PEERS_FILE=/tmp/meshpeers.txt
2015-08-22 13:40:03 +02:00
if [ ! -f /usr/bin/batman ]; then
echo 'Mesh networking is not configured on your system'
echo 'Run freedombone-client to install the necessary packages'
exit 1
fi
if [ ! -f /tmp/meshtype ]; then
sudo batman start
2015-08-22 13:52:18 +02:00
if [ ! "$?" = "0" ]; then
exit 2
fi
2015-08-22 13:40:03 +02:00
clear
fi
avahi-browse -at | awk -F ' ' '{print $4}' > $PEERS_FILE
if [ ! -f $PEERS_FILE ]; then
echo 'No peers were found'
exit 0
fi
ctr=0
while IFS='' read -r line || [[ -n "$line" ]]; do
ctr=$((ctr + 1))
done < "$PEERS_FILE"
if [ ${ctr} -lt "2" ]; then
echo 'No peers were found'
exit 0
fi
echo 'Choose a peer to connect to:'
idx=1
while IFS='' read -r line || [[ -n "$line" ]]; do
echo " $idx. $line"
idx=$((idx + 1))
done < "$PEERS_FILE"
peer_index=0
read peer_index
2015-08-22 13:47:01 +02:00
# if no selection made
if [ ! $peer_index ]; then
exit 0
fi
# get the avahi domain name
AVAHI_DOMAIN=
idx=1
while IFS='' read -r line || [[ -n "$line" ]]; do
if [ ${idx} -eq "$peer_index" ]; then
AVAHI_DOMAIN=${line}.local
fi
idx=$((idx + 1))
done < "$PEERS_FILE"
if [ ! $AVAHI_DOMAIN ]; then
echo 'No domain name'
2015-08-22 13:52:18 +02:00
exit 3
fi
# Connect to IRC
if [ ! -f /usr/bin/irssi ]; then
if [ ! -f /usr/local/bin/irssi ]; then
echo 'You need irssi installed on your system'
2015-08-22 13:40:03 +02:00
sudo batman stop
2015-08-22 13:52:18 +02:00
exit 4
fi
fi
irssi -c $AVAHI_DOMAIN -p $IRC_PORT -n $USER
exit 0