2015-08-30 12:50:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
2015-08-30 13:09:32 +02:00
|
|
|
PEERS_FILE=/tmp/meshwebstart
|
|
|
|
|
2015-08-30 12:50:50 +02:00
|
|
|
ZERONET_REPO='https://github.com/bashrc/ZeroNet'
|
|
|
|
ZERONET_DIR=~/zeronet
|
|
|
|
ZERONET_URL=http://127.0.0.1:43110
|
|
|
|
TRACKER_PORT=6969
|
|
|
|
|
2015-08-31 14:01:09 +02:00
|
|
|
function install_web_server {
|
|
|
|
if [ -d /etc/nginx ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
sudo apt-get -y remove --purge apache2
|
|
|
|
if [ -d /etc/apache2 ]; then
|
|
|
|
sudo rm -rf /etc/apache2
|
|
|
|
fi
|
|
|
|
# install nginx
|
|
|
|
sudo apt-get -y install nginx
|
|
|
|
|
|
|
|
if [ ! -d /etc/nginx ]; then
|
|
|
|
echo 'Unable to install web server'
|
|
|
|
exit 51
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-08-30 12:50:50 +02:00
|
|
|
function install_zeronet {
|
|
|
|
if [ -d $ZERONET_DIR ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
sudo apt-get -y install python python-msgpack python-gevent
|
|
|
|
sudo apt-get -y install python-pip bittornado
|
|
|
|
sudo pip install msgpack-python --upgrade
|
|
|
|
|
|
|
|
git clone $ZERONET_REPO $ZERONET_DIR
|
|
|
|
if [ ! -d $ZERONET_DIR ]; then
|
|
|
|
exit 56823
|
|
|
|
fi
|
|
|
|
cd $ZERONET_DIR
|
2015-08-31 12:24:49 +02:00
|
|
|
git checkout bashrc/bootstrap-file
|
|
|
|
#git checkout bashrc/test
|
2015-08-30 12:50:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ -f /var/lib/batman ]; then
|
|
|
|
SERVER_INSTALLATION="yes"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $SERVER_INSTALLATION == "no" ]]; then
|
|
|
|
if [ ! -f /usr/bin/batman ]; then
|
|
|
|
freedombone-client
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $SERVER_INSTALLATION == "no" ]]; then
|
|
|
|
if [ ! -f /tmp/meshtype ]; then
|
2015-08-31 14:09:34 +02:00
|
|
|
sudo apt-get update
|
2015-08-31 14:01:09 +02:00
|
|
|
install_web_server
|
2015-08-30 12:50:50 +02:00
|
|
|
install_zeronet
|
|
|
|
sudo batman start
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
avahi-browse -atl | grep "Workstation" | awk -F ' ' '{print $4}' | sort -u > $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"
|
|
|
|
|
2015-08-30 13:09:32 +02:00
|
|
|
rm $PEERS_FILE
|
|
|
|
|
2015-08-30 12:50:50 +02:00
|
|
|
if [ ${ctr} -lt "1" ]; then
|
|
|
|
echo 'No peers were found'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $ZERONET_DIR ]; then
|
|
|
|
echo 'zeronet was not installed'
|
|
|
|
exit 63
|
|
|
|
fi
|
|
|
|
cd $ZERONET_DIR
|
|
|
|
|
|
|
|
|
|
|
|
existing_bttrack=$(ps aux | grep bttrack | wc -l)
|
|
|
|
if [ $existing_bttrack -lt "2" ]; then
|
2015-08-31 14:01:09 +02:00
|
|
|
if [ ! -d ~/.bttrack ]; then
|
|
|
|
mkdir ~/.bttrack
|
|
|
|
fi
|
2015-08-31 11:44:50 +02:00
|
|
|
bttrack --port ${TRACKER_PORT} --dfile ~/.bttrack/dstate --logfile ~/.bttrack/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0 &
|
2015-08-30 12:50:50 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
zeronetavahi
|
|
|
|
|
|
|
|
existing_zeronet=$(ps aux | grep zeronet | wc -l)
|
|
|
|
if [ $existing_zeronet -lt "2" ]; then
|
|
|
|
python zeronet.py &
|
|
|
|
fi
|
|
|
|
|
|
|
|
if which xdg-open > /dev/null; then
|
|
|
|
xdg-open $ZERONET_URL
|
|
|
|
elif which gnome-open > /dev/null; then
|
|
|
|
gnome-open $ZERONET_URL
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|