freedomboneeee/src/freedombone-mesh

374 lines
11 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# A script to easily locate mesh peers and start communicating
# License
# =======
#
2016-01-02 22:58:27 +01:00
# Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
#
# This program is free software: you can redistribute it and/or modify
2016-02-13 23:09:27 +01:00
# 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
2016-02-13 23:09:27 +01:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
2016-02-13 23:09:27 +01:00
# 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/>.
2015-11-27 12:42:16 +01:00
PROJECT_NAME='freedombone'
2015-11-27 17:52:23 +01:00
export TEXTDOMAIN=${PROJECT_NAME}-mesh
2015-11-27 12:42:16 +01:00
export TEXTDOMAINDIR="/usr/share/locale"
2015-08-26 21:28:01 +02:00
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
PEERS_FILE=/tmp/meshpeers.txt
2015-08-22 13:40:03 +02:00
TOX_PORT=33445
2015-08-27 19:37:50 +02:00
TOXCORE_REPO='git://github.com/irungentoo/toxcore.git'
2016-01-25 20:48:08 +01:00
TOXID_REPO='https://github.com/bashrc/toxid'
TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt
2015-08-30 18:42:06 +02:00
QTOX_INI="/home/$USER/.config/tox/qtox.ini"
# client or server installations sounds odd for a mesh, but this
# indicates whether this is a dedicated mesh peer ("yes") or
# a 'client' such as a laptop or desktop machine with
# the freedombone-client script installed
SERVER_INSTALLATION="no"
function install_toxcore {
2015-08-27 19:45:03 +02:00
if [ -f /etc/tox-bootstrapd.conf ]; then
return
fi
sudo apt-get -y install build-essential libtool autotools-dev
sudo apt-get -y install automake checkinstall check git yasm
sudo apt-get -y install libsodium13 libsodium-dev libcap2-bin
sudo apt-get -y install libconfig9 libconfig-dev
if [ ! -d ~/develop ]; then
mkdir ~/develop
fi
cd ~/develop
2016-01-26 17:50:43 +01:00
git clone $TOXCORE_REPO ~/develop/toxcore
cd ~/develop/toxcore
autoreconf -i
./configure --enable-daemon
if [ ! "$?" = "0" ]; then
exit 78467
fi
make
if [ ! "$?" = "0" ]; then
exit 84562
fi
sudo make install
sudo cp /usr/local/lib/libtoxcore* /usr/lib/
if [ ! -f /usr/local/bin/tox-bootstrapd ]; then
2015-11-27 16:29:43 +01:00
echo $"File not found /usr/local/bin/tox-bootstrapd"
exit 73862
fi
sudo useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
sudo chmod 700 /var/lib/tox-bootstrapd
if [ ! -f ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf ]; then
2015-11-27 16:29:43 +01:00
echo $"File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf"
exit 476835
fi
# create configuration file
echo "port = $TOX_PORT" > /tmp/tox-bootstrapd.conf
echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> /tmp/tox-bootstrapd.conf
echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> /tmp/tox-bootstrapd.conf
echo 'enable_ipv6 = true' >> /tmp/tox-bootstrapd.conf
echo 'enable_ipv4_fallback = true' >> /tmp/tox-bootstrapd.conf
echo 'enable_lan_discovery = true' >> /tmp/tox-bootstrapd.conf
echo 'enable_tcp_relay = true' >> /tmp/tox-bootstrapd.conf
echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> /tmp/tox-bootstrapd.conf
echo 'enable_motd = true' >> /tmp/tox-bootstrapd.conf
echo 'motd = "tox-bootstrapd"' >> /tmp/tox-bootstrapd.conf
sudo cp /tmp/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
rm /tmp/tox-bootstrapd.conf
if [ -f /bin/systemctl ]; then
if [ ! -f ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.service ]; then
2015-11-27 16:29:43 +01:00
echo $"File not found ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.service"
exit 7359
fi
sudo cp ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable tox-bootstrapd.service
sudo systemctl start tox-bootstrapd.service
if [ ! "$?" = "0" ]; then
sudo systemctl status tox-bootstrapd.service
exit 5846
fi
sudo systemctl restart tox-bootstrapd.service
else
sudo cp ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.sh /etc/init.d/tox-bootstrapd
sudo chmod 755 /etc/init.d/tox-bootstrapd
sudo update-rc.d tox-bootstrapd defaults
sudo service tox-bootstrapd start
fi
TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
2015-11-27 16:29:43 +01:00
echo $'Could not obtain the tox node public key'
exit 6529
fi
# save the public key for later reference
2015-08-27 20:10:06 +02:00
echo "$TOX_PUBLIC_KEY" > /tmp/boostrapid
2015-08-27 20:11:22 +02:00
sudo mv /tmp/boostrapid $TOX_BOOTSTRAP_ID_FILE
}
function install_toxid {
if [ -f /usr/local/bin/toxid ]; then
return
fi
cd ~/develop
2016-01-26 17:50:43 +01:00
git clone $TOXID_REPO ~/develop/toxid
cd ~/develop/toxid
make
sudo make install
if [ ! -f /usr/local/bin/toxid ]; then
2015-11-27 16:29:43 +01:00
echo $"Couldn't install toxid"
exit 6389
fi
if ! grep -Fxq "toxavahi" /etc/crontab; then
cp /etc/crontab /tmp/crontab
echo "* * * * * root toxavahi > /dev/null" >> /tmp/crontab
sudo cp /tmp/crontab /etc/crontab
rm /tmp/crontab
fi
}
function run_tox {
2015-08-30 18:42:06 +02:00
echo $QTOX_INI
if [[ -f $TOXIC_PATH || -f $QTOX_INI ]]; then
2015-08-27 22:18:44 +02:00
if [[ $SERVER_INSTALLATION == "no" ]]; then
# update bootstrap nodes
if [ -f $DHTNODES ]; then
if [ ! -f $DHTNODES.internet ]; then
sudo cp $DHTNODES $DHTNODES.internet
fi
fi
2015-08-27 22:18:44 +02:00
lstox -f dht > /tmp/dht
sudo cp /tmp/dht $DHTNODES
fi
# get a list of peers
PEER_TOX_ID_LIST=$(lstox | grep $AVAHI_DOMAIN | sort -u)
2015-08-27 22:18:44 +02:00
if [ ! "$PEER_TOX_ID_LIST" ]; then
2015-11-27 16:29:43 +01:00
echo $'No peers found'
exit 0
fi
2015-08-27 22:18:44 +02:00
PEER_TOX_ID_LIST_COUNT=$(echo "$PEER_TOX_ID_LIST" | wc -l)
PEER_TOX_ID=''
if [ $PEER_TOX_ID_LIST_COUNT -lt "2" ]; then
# single peer
2015-08-27 22:18:44 +02:00
PEER_TOX_ID=$(echo "$PEER_TOX_ID_LIST" | awk -F ' ' '{print $3}')
else
# choose a user from a list
echo ''
2015-11-27 16:29:43 +01:00
echo $"Select a user on $AVAHI_DOMAIN:"
ctr=0
while IFS='' read -r line || [[ -n "$line" ]]; do
toxusername=$(echo $line | awk -F ' ' '{print $2}')
echo " $ctr. $toxusername"
ctr=$((ctr + 1))
done < "$PEER_TOX_ID_LIST"
read user_index
2015-08-27 22:18:44 +02:00
PEER_TOX_ID=$(echo "$PEER_TOX_ID_LIST" | tail -n+${user_index} | head -n1 | awk -F ' ' '{print $3}')
fi
# if this is a valid ID
if [ ${#PEER_TOX_ID} -gt 30 ]; then
# start client and make a friend request
2015-08-30 18:02:36 +02:00
if [ -f $QTOX_INI ]; then
2015-11-27 16:29:43 +01:00
echo $'Launch qTox'
2015-08-30 18:02:36 +02:00
qtox &
else
echo "n
/nick $USER
/add $PEER_TOX_ID
/exit
" | $TOXIC_PATH -d
2015-08-30 18:02:36 +02:00
# Running twice is a hack to get around buggyness in the client
$TOXIC_PATH -d
fi
exit 0
else
# ID was invalid
echo $PEER_TOX_ID
2015-11-27 16:29:43 +01:00
echo $"Tox ID for $AVAHI_DOMAIN was not found"
exit 6
fi
fi
}
if [ -f /var/lib/batman ]; then
SERVER_INSTALLATION="yes"
fi
if [[ $SERVER_INSTALLATION == "no" ]]; then
if [ ! -f /usr/bin/batman ]; then
2015-12-08 17:22:48 +01:00
${PROJECT_NAME}-client
fi
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
if [[ $SERVER_INSTALLATION == "no" ]]; then
if [ ! -f /tmp/meshtype ]; then
install_toxcore
install_toxid
sudo batman start
if [ ! "$?" = "0" ]; then
exit 2
fi
2015-08-22 13:52:18 +02:00
fi
2015-08-22 13:40:03 +02:00
fi
2015-09-11 20:36:04 +02:00
avahi-browse -atl | awk -F ' ' '{print $4}' | sort -u > $PEERS_FILE
if [ ! -f $PEERS_FILE ]; then
2015-11-27 16:29:43 +01:00
echo $'No peers were found'
exit 0
fi
ctr=0
while IFS='' read -r line || [[ -n "$line" ]]; do
ctr=$((ctr + 1))
done < "$PEERS_FILE"
2015-08-30 11:52:22 +02:00
if [ ${ctr} -lt "1" ]; then
2015-11-27 16:29:43 +01:00
echo $'No peers were found'
exit 0
fi
2015-08-22 14:01:53 +02:00
clear
echo ''
echo ".---. . . "
echo "| | | "
echo "|--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. "
echo "| | (.-' (.-' ( | ( )| | | | )( )| | (.-' "
echo "' ' --' --' -' - -' ' ' -' -' -' ' - --'"
2015-11-27 16:29:43 +01:00
echo $' Freedom in the Mesh'
2015-08-22 14:01:53 +02:00
echo ''
2015-11-27 16:29:43 +01:00
echo $'Please 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
2015-11-27 16:29:43 +01:00
echo $'Nothing was selected'
echo ''
2015-08-22 13:47:01 +02:00
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
2015-11-27 16:29:43 +01:00
echo $'No domain name'
2015-08-22 13:52:18 +02:00
exit 3
fi
# if only mumble is installed
if [ ! -f $TOXIC_PATH ]; then
if [ -f $MUMBLE_PATH ]; then
$MUMBLE_PATH &
exit 0
2015-08-26 21:28:01 +02:00
fi
2015-11-27 16:29:43 +01:00
echo $'You need mumble/toxic/qTox installed on your system'
if [[ $SERVER_INSTALLATION == "no" ]]; then
sudo batman stop
fi
exit 4
2015-08-22 17:44:16 +02:00
fi
# if only tox is installed
2015-08-26 21:28:01 +02:00
if [ ! -f $MUMBLE_PATH ]; then
run_tox
fi
echo ''
2015-11-27 16:29:43 +01:00
echo $'Choose communication service:'
echo $' 1. VoIP'
echo $' 2. Tox Chat'
echo ''
read peer_index
# if no selection made
if [ ! $peer_index ]; then
2015-11-27 16:29:43 +01:00
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 ''
2015-11-27 16:29:43 +01:00
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"
2015-08-26 21:28:01 +02:00
echo ''
2015-11-27 16:29:43 +01:00
echo $'Press Enter to continue.'
2015-08-26 21:28:01 +02:00
echo ''
read peer_index
$MUMBLE_PATH &
else
2015-11-27 16:29:43 +01:00
echo $'Mumble may not be installed on this system'
2015-08-26 21:28:01 +02:00
exit 5
fi
2015-08-30 18:42:06 +02:00
fi
if [[ $peer_index == 2 ]]; then
run_tox
fi
exit 0