From 18043c1e48dca16ee45cf0b81bd82873e5da5fb0 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 30 Aug 2015 11:50:50 +0100 Subject: [PATCH] Move mesh web to its own command --- Makefile | 4 ++ src/freedombone-mesh | 63 ++------------------------- src/freedombone-meshweb | 95 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 59 deletions(-) create mode 100755 src/freedombone-meshweb diff --git a/Makefile b/Makefile index 40cb3ce7..85a33339 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,8 @@ install: install -m 755 src/${APP}-xmpp-pass ${DESTDIR}${PREFIX}/bin install -m 755 src/${APP}-mesh ${DESTDIR}${PREFIX}/bin install -m 755 src/${APP}-mesh ${DESTDIR}${PREFIX}/bin/mesh + install -m 755 src/${APP}-meshweb ${DESTDIR}${PREFIX}/bin + install -m 755 src/${APP}-meshweb ${DESTDIR}${PREFIX}/bin/mesh mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/${APP}.1.gz ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/${APP}-keydrive.1.gz ${DESTDIR}${PREFIX}/share/man/man1 @@ -104,6 +106,8 @@ uninstall: rm -f ${PREFIX}/bin/${APP}-xmpp-pass rm -f ${PREFIX}/bin/${APP}-mesh rm -f ${PREFIX}/bin/mesh + rm -f ${PREFIX}/bin/${APP}-meshweb + rm -f ${PREFIX}/bin/meshweb clean: rm -f \#* \.#* debian/*.substvars debian/*.log rm -fr deb.* debian/${APP} diff --git a/src/freedombone-mesh b/src/freedombone-mesh index 0bb91f03..4c163823 100755 --- a/src/freedombone-mesh +++ b/src/freedombone-mesh @@ -46,28 +46,6 @@ TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt # the freedombone-client script installed SERVER_INSTALLATION="no" -ZERONET_REPO='https://github.com/bashrc/ZeroNet' -ZERONET_DIR=~/zeronet -ZERONET_DEFAULT=1Name2NXVi1RDPDgf5617UoW7xA6YrhM9F -ZERONET_URL=http://127.0.0.1:43110/$ZERONET_DEFAULT -TRACKER_PORT=6969 - -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 - git checkout bashrc/bootstrap-file -} - function install_toxcore { if [ -f /etc/tox-bootstrapd.conf ]; then return @@ -364,10 +342,9 @@ fi echo '' echo 'Choose communication service:' -echo ' 1. Web' -echo ' 2. VoIP' -echo ' 3. Tox Chat' -echo ' 4. IRC (WARNING: not secure)' +echo ' 1. VoIP' +echo ' 2. Tox Chat' +echo ' 3. IRC (WARNING: not secure)' echo '' read peer_index @@ -380,38 +357,6 @@ if [ ! $peer_index ]; then fi if [[ $peer_index == 1 ]]; then - 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 - if [ ! -d ~/.bttrack ]; then - mkdir ~/.bttrack - fi - echo '***********************************' - bttrack --port ${TRACKER_PORT} --dfile ~/.bttrack/dstate --logfile ~/.bttrack/tracker.log --nat_check 0 --scrape_allowed full & - 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 -fi - -if [[ $peer_index == 2 ]]; then if [ -f $MUMBLE_PATH ]; then echo '' echo 'To setup for the first time click "Add New", then set:' @@ -429,7 +374,7 @@ if [[ $peer_index == 2 ]]; then exit 5 fi else - if [[ $peer_index == 3 ]]; then + if [[ $peer_index == 2 ]]; then run_tox else if [ -f $IRSSI_PATH ]; then diff --git a/src/freedombone-meshweb b/src/freedombone-meshweb new file mode 100755 index 00000000..42e53cf1 --- /dev/null +++ b/src/freedombone-meshweb @@ -0,0 +1,95 @@ +#!/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" + +ZERONET_REPO='https://github.com/bashrc/ZeroNet' +ZERONET_DIR=~/zeronet +ZERONET_URL=http://127.0.0.1:43110 +TRACKER_PORT=6969 + +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 + git checkout bashrc/bootstrap-file +} + +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 + 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" + +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 + if [ ! -d ~/.bttrack ]; then + mkdir ~/.bttrack + fi + bttrack --port ${TRACKER_PORT} --dfile ~/.bttrack/dstate --logfile ~/.bttrack/tracker.log --nat_check 0 --scrape_allowed full & +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