2015-08-22 12:27:56 +02:00
|
|
|
#!/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/>.
|
|
|
|
|
2015-08-26 21:28:01 +02:00
|
|
|
IRSSI_PATH=/usr/bin/irssi
|
|
|
|
MUMBLE_PATH=/usr/bin/mumble
|
2015-08-26 21:32:56 +02:00
|
|
|
TOXIC_PATH=/usr/bin/toxic
|
|
|
|
DHTNODES=/usr/share/toxic/DHTnodes
|
2015-08-26 21:28:01 +02:00
|
|
|
|
2015-08-22 12:27:56 +02:00
|
|
|
IRC_PORT=6697
|
|
|
|
PEERS_FILE=/tmp/meshpeers.txt
|
2015-08-22 13:40:03 +02:00
|
|
|
|
|
|
|
if [ ! -f /usr/bin/batman ]; then
|
2015-08-22 18:50:17 +02:00
|
|
|
freedombone-client
|
2015-08-22 13:40:03 +02:00
|
|
|
fi
|
|
|
|
|
2015-08-26 21:28:01 +02:00
|
|
|
# alternative toxic paths
|
2015-08-26 21:32:56 +02:00
|
|
|
if [ -f /usr/local/bin/toxic ]; then
|
|
|
|
TOXIC_PATH=/usr/local/bin/toxic
|
2015-08-26 21:28:01 +02:00
|
|
|
fi
|
2015-08-26 21:32:56 +02:00
|
|
|
if [ -f /usr/local/share/toxic/DHTnodes ]; then
|
|
|
|
DHTNODES=/usr/local/share/toxic/DHTnodes
|
2015-08-26 21:28:01 +02:00
|
|
|
fi
|
|
|
|
|
2015-08-22 13:40:03 +02:00
|
|
|
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
|
|
|
fi
|
|
|
|
|
2015-08-24 21:57:22 +02:00
|
|
|
avahi-browse -atl | grep "Workstation" | awk -F ' ' '{print $4}' > $PEERS_FILE
|
2015-08-22 12:27:56 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-08-22 14:01:53 +02:00
|
|
|
clear
|
|
|
|
echo ''
|
|
|
|
echo ".---. . . "
|
|
|
|
echo "| | | "
|
|
|
|
echo "|--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. "
|
|
|
|
echo "| | (.-' (.-' ( | ( )| | | | )( )| | (.-' "
|
|
|
|
echo "' ' --' --' -' - -' ' ' -' -' -' ' - --'"
|
2015-08-26 21:28:01 +02:00
|
|
|
echo ' Freedom in the Mesh'
|
2015-08-22 14:01:53 +02:00
|
|
|
echo ''
|
|
|
|
echo 'Please choose a peer to connect to:'
|
2015-08-22 12:27:56 +02:00
|
|
|
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
|
2015-08-22 18:14:10 +02:00
|
|
|
echo 'Nothing was selected'
|
|
|
|
echo ''
|
2015-08-22 13:47:01 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-08-22 12:27:56 +02:00
|
|
|
# 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
|
2015-08-22 12:27:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Connect to IRC
|
2015-08-26 21:28:01 +02:00
|
|
|
if [ ! -f $IRSSI_PATH ]; then
|
|
|
|
if [ ! -f $TOXIC_PATH ]; then
|
|
|
|
if [ -f $MUMBLE_PATH ]; then
|
|
|
|
MUMBLE_PATH &
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo 'You need irssi/mumble/toxic installed on your system'
|
|
|
|
sudo batman stop
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $MUMBLE_PATH ]; then
|
|
|
|
if [ ! -f $TOXIC_PATH ]; then
|
|
|
|
if [ -f $IRSSI_PATH ]; then
|
|
|
|
$IRSSI_PATH -c $AVAHI_DOMAIN -p $IRC_PORT -n $USER
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo 'You need irssi/mumble/toxic installed on your system'
|
|
|
|
sudo batman stop
|
|
|
|
exit 4
|
2015-08-22 18:14:10 +02:00
|
|
|
fi
|
2015-08-22 17:44:16 +02:00
|
|
|
fi
|
|
|
|
|
2015-08-26 21:28:01 +02:00
|
|
|
if [ ! -f $MUMBLE_PATH ]; then
|
|
|
|
if [ ! -f $IRSSI_PATH ]; then
|
|
|
|
if [ -f $TOXIC_PATH ]; then
|
2015-08-26 21:49:27 +02:00
|
|
|
if [ -f $DHTNODES ]; then
|
|
|
|
if [ ! -f $DHTNODES.internet ]; then
|
|
|
|
sudo cp $DHTNODES $DHTNODES.internet
|
|
|
|
fi
|
|
|
|
fi
|
2015-08-26 21:55:41 +02:00
|
|
|
lstox -f dht > /tmp/dht
|
2015-08-26 22:17:26 +02:00
|
|
|
sudo cp /tmp/dht $DHTNODES
|
2015-08-26 22:12:18 +02:00
|
|
|
PEER_TOX_ID=$(lstox | grep $AVAHI_DOMAIN | head -n 1 | awk -F ' ' '{print $2}')
|
2015-08-26 21:28:01 +02:00
|
|
|
if [ ${#PEER_TOX_ID} -gt 30 ]; then
|
2015-08-26 22:12:18 +02:00
|
|
|
echo "/nick $USER
|
|
|
|
/add $PEER_TOX_ID
|
2015-08-26 22:17:26 +02:00
|
|
|
/exit
|
2015-08-26 21:28:01 +02:00
|
|
|
" | $TOXIC_PATH -d
|
2015-08-26 22:17:26 +02:00
|
|
|
$TOXIC_PATH -d
|
2015-08-26 21:28:01 +02:00
|
|
|
exit 0
|
|
|
|
else
|
2015-08-26 22:17:26 +02:00
|
|
|
echo $PEER_TOX_ID
|
2015-08-26 21:28:01 +02:00
|
|
|
echo "Tox ID for $AVAHI_DOMAIN was not found"
|
|
|
|
exit 6
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo 'You need irssi/mumble/toxic installed on your system'
|
|
|
|
sudo batman stop
|
|
|
|
exit 4
|
2015-08-22 18:14:10 +02:00
|
|
|
fi
|
2015-08-22 12:27:56 +02:00
|
|
|
fi
|
|
|
|
|
2015-08-22 18:14:10 +02:00
|
|
|
echo ''
|
|
|
|
echo 'Choose communication service:'
|
2015-08-26 21:28:01 +02:00
|
|
|
echo ' 1. VoIP'
|
|
|
|
echo ' 2. Tox Chat'
|
|
|
|
echo ' 3. IRC (WARNING: not encrypted)'
|
2015-08-22 18:14:10 +02:00
|
|
|
echo ''
|
|
|
|
|
|
|
|
read peer_index
|
|
|
|
|
|
|
|
# if no selection made
|
|
|
|
if [ ! $peer_index ]; then
|
|
|
|
echo 'Nothing was selected'
|
|
|
|
echo ''
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $peer_index == 1 ]]; then
|
2015-08-26 21:28:01 +02:00
|
|
|
if [ -f $MUMBLE_PATH ]; then
|
|
|
|
echo ''
|
|
|
|
echo 'To setup for the first time click "Add New", then set:'
|
|
|
|
echo " Label: $AVAHI_DOMAIN"
|
|
|
|
echo " Address: $AVAHI_DOMAIN"
|
|
|
|
echo ' Port: 64738'
|
|
|
|
echo " Username: $USER"
|
|
|
|
echo ''
|
|
|
|
echo 'Press Enter to continue.'
|
|
|
|
echo ''
|
|
|
|
read peer_index
|
|
|
|
$MUMBLE_PATH &
|
|
|
|
else
|
|
|
|
echo 'Mumble may not be installed on this system'
|
|
|
|
exit 5
|
|
|
|
fi
|
2015-08-22 18:14:10 +02:00
|
|
|
else
|
2015-08-26 21:28:01 +02:00
|
|
|
if [[ $peer_index == 2 ]]; then
|
|
|
|
if [ -f $TOX_PATH ]; then
|
2015-08-26 21:49:27 +02:00
|
|
|
if [ -f $DHTNODES ]; then
|
|
|
|
if [ ! -f $DHTNODES.internet ]; then
|
|
|
|
sudo cp $DHTNODES $DHTNODES.internet
|
|
|
|
fi
|
|
|
|
fi
|
2015-08-26 21:55:41 +02:00
|
|
|
lstox -f dht > /tmp/dht
|
2015-08-26 22:17:26 +02:00
|
|
|
sudo cp /tmp/dht $DHTNODES
|
2015-08-26 22:12:18 +02:00
|
|
|
PEER_TOX_ID=$(lstox | grep $AVAHI_DOMAIN | head -n 1 | awk -F ' ' '{print $2}')
|
2015-08-26 21:28:01 +02:00
|
|
|
if [ ${#PEER_TOX_ID} -gt 30 ]; then
|
2015-08-26 22:12:18 +02:00
|
|
|
echo "/nick $USER
|
|
|
|
/add $PEER_TOX_ID
|
2015-08-26 22:17:26 +02:00
|
|
|
/exit
|
2015-08-26 21:28:01 +02:00
|
|
|
" | $TOXIC_PATH -d
|
2015-08-26 22:17:26 +02:00
|
|
|
$TOXIC_PATH -d
|
2015-08-26 21:28:01 +02:00
|
|
|
else
|
|
|
|
echo "Tox ID for $AVAHI_DOMAIN was not found"
|
|
|
|
exit 6
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo 'Tox may not be installed on this system'
|
|
|
|
exit 7
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ -f $IRSSI_PATH ]; then
|
|
|
|
$IRSSI_PATH -c $AVAHI_DOMAIN -p $IRC_PORT -n $USER
|
|
|
|
else
|
|
|
|
echo 'Irssi may not be installed on this system'
|
|
|
|
exit 8
|
|
|
|
fi
|
|
|
|
fi
|
2015-08-22 18:14:10 +02:00
|
|
|
fi
|
2015-08-22 17:44:16 +02:00
|
|
|
|
2015-08-22 12:27:56 +02:00
|
|
|
exit 0
|