From 2d7007c191e289606d8a4cd887550d70cca940e1 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Sat, 29 Aug 2015 17:48:43 +0100
Subject: [PATCH] Handle client installs of zeronet

---
 src/freedombone-client |  7 +++++--
 src/freedombone-mesh   | 39 +++++++++++++++++++++++++++++++++++----
 src/zeronetavahi       |  8 ++++++--
 3 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/src/freedombone-client b/src/freedombone-client
index f448ca882..b21827202 100755
--- a/src/freedombone-client
+++ b/src/freedombone-client
@@ -48,6 +48,7 @@ SSH_KEX="curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256"
 SSH_HOST_KEY_ALGORITHMS="ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-ed25519,ssh-rsa"
 
 ZERONET_PORT=15441
+TRACKER_PORT=51413
 
 # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
 function ssh_remove_small_moduli {
@@ -143,7 +144,7 @@ function mesh_babel {
   echo '        return' >> $babel_script
   echo '    fi' >> $batman_script
   echo '    # install avahi' >> $babel_script
-  echo '    apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd' >> $babel_script
+  echo '    apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd transmission-daemon' >> $babel_script
   echo '    sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
   echo '    sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $babel_script
   echo '    if [ -f /bin/systemctl ]; then' >> $babel_script
@@ -228,7 +229,7 @@ function mesh_batman {
   echo '' >> $batman_script
   echo 'if [[ $1 == "start" ]]; then' >> $batman_script
   echo '    # install avahi' >> $batman_script
-  echo '    apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd' >> $batman_script
+  echo '    apt-get -y install avahi-utils avahi-autoipd avahi-daemon avahi-dnsconfd transmission-daemon' >> $batman_script
   echo '    sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
   echo '    sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
   echo '    sed -i "s|use-ipv4=.*|use-ipv4=yes|g" /etc/avahi/avahi-daemon.conf' >> $batman_script
@@ -339,6 +340,7 @@ function mesh_batman {
   echo '    iptables -A INPUT -p udp --dport 5354 -j ACCEPT' >> $batman_script
   echo "    iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $batman_script
   echo "    iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $batman_script
+  echo "    iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $batman_script
   echo '' >> $batman_script
   echo '    if [ -f /bin/systemctl ]; then' >> $batman_script
   echo '        systemctl restart avahi-daemon' >> $batman_script
@@ -379,6 +381,7 @@ function mesh_batman {
   echo '    iptables -D INPUT -p udp --dport 5354 -j ACCEPT' >> $batman_script
   echo "    iptables -D INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $batman_script
   echo "    iptables -D INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $batman_script
+  echo "    iptables -D INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $batman_script
   echo '' >> $batman_script
   echo '    if [ -f /bin/systemctl ]; then' >> $batman_script
   echo '        systemctl restart network-manager' >> $batman_script
diff --git a/src/freedombone-mesh b/src/freedombone-mesh
index a1bdd63a1..16bb31db1 100755
--- a/src/freedombone-mesh
+++ b/src/freedombone-mesh
@@ -46,6 +46,23 @@ 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_URL=http://127.0.0.1:43110
+
+function install_zeronet {
+  sudo apt-get -y install python python-msgpack python-gevent
+  sudo apt-get -y install python-pip transmission-daemon
+  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
@@ -237,6 +254,7 @@ if [[ $SERVER_INSTALLATION == "no" ]]; then
     if [ ! -f /tmp/meshtype ]; then
         install_toxcore
         install_toxid
+        install_zeronet
         sudo batman start
         if [ ! "$?" = "0" ]; then
             exit 2
@@ -341,9 +359,10 @@ fi
 
 echo ''
 echo 'Choose communication service:'
-echo '    1. VoIP'
-echo '    2. Tox Chat'
-echo '    3. IRC (WARNING: not secure)'
+echo '    1. Web'
+echo '    2. VoIP'
+echo '    3. Tox Chat'
+echo '    4. IRC (WARNING: not secure)'
 echo ''
 
 read peer_index
@@ -356,6 +375,18 @@ if [ ! $peer_index ]; then
 fi
 
 if [[ $peer_index == 1 ]]; then
+    cd ZERONET_DIR
+    zeronetavahi
+    python zeronet.py &
+    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:'
@@ -373,7 +404,7 @@ if [[ $peer_index == 1 ]]; then
         exit 5
     fi
 else
-    if [[ $peer_index == 2 ]]; then
+    if [[ $peer_index == 3 ]]; then
         run_tox
     else
         if [ -f $IRSSI_PATH ]; then
diff --git a/src/zeronetavahi b/src/zeronetavahi
index b05d3bb4e..d803d4856 100755
--- a/src/zeronetavahi
+++ b/src/zeronetavahi
@@ -32,7 +32,11 @@ TRACKER_PORT=51413
 BOOTSTRAP_FILE=/opt/zeronet/bootstrap
 
 if [ ! -d /opt/zeronet ]; then
-    exit 0
+    if [ -d ~/zeronet ]; then
+        BOOTSTRAP_FILE=~/zeronet/bootstrap
+    else
+        exit 0
+    fi
 fi
 
 if [ ! -d /etc/avahi ]; then
@@ -70,6 +74,6 @@ done < "$TEMPFILE"
 rm -f $TEMPFILE
 cp -f $BOOTSTRAP_FILE.new $BOOTSTRAP_FILE
 rm -f $BOOTSTRAP_FILE.new
-sudo chown zeronet:zeronet /opt/zeronet/bootstrap
+sudo chown zeronet:zeronet $BOOTSTRAP_FILE
 
 exit 0
-- 
GitLab