#!/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" PEERS_FILE=/tmp/meshwebstart ZERONET_REPO='https://github.com/bashrc/ZeroNet' ZERONET_BLOG_REPO='https://github.com/HelloZeroNet/ZeroBlog' ZERONET_FORUM_REPO='https://github.com/HelloZeroNet/ZeroBoard' ZERONET_DIR=~/zeronet ZERONET_URL=http://127.0.0.1:43110 ZERONET_PORT=15441 TRACKER_PORT=6969 MY_USERNAME=$USER function install_zeronet_blog { if [ ! -f /home/$MY_USERNAME/README ]; then touch /home/$MY_USERNAME/README fi if grep -q "ZeroNet Blog address" /home/$MY_USERNAME/README; then return fi if [ ! -d /etc/avahi ]; then echo 'Avahi is not installed' exit 736 fi cd $ZERONET_DIR python zeronet.py --batch siteCreate 2> $ZERONET_DIR/blog.txt if [ ! -f $ZERONET_DIR/blog.txt ]; then echo 'Unable to create blog' exit 479 fi blog_address=$(cat blog.txt | grep "Site address" | awk -F ':' '{print $2}') blog_private_key=$(cat blog.txt | grep "Site private key" | awk -F ':' '{print $2}') ZERONET_BLOG_ADDRESS=${blog_address//[[:blank:]]/} ZERONET_BLOG_PRIVATE_KEY=${blog_private_key//[[:blank:]]/} if [ ${#ZERONET_BLOG_ADDRESS} -lt 20 ]; then echo "Address: $ZERONET_BLOG_ADDRESS" echo "Public key: $ZERONET_BLOG_PRIVATE_KEY" echo 'Unable to create zeronet blog address' exit 7358 fi if [ ${#ZERONET_BLOG_PRIVATE_KEY} -lt 20 ]; then echo "Address: $ZERONET_BLOG_ADDRESS" echo "Public key: $ZERONET_BLOG_PRIVATE_KEY" echo 'Unable to create zeronet blog private key' exit 1639 fi if [ ! -d "$ZERONET_DIR/data/$ZERONET_BLOG_ADDRESS" ]; then echo "Unable to find site directory: $ZERONET_DIR/data/$ZERONET_BLOG_ADDRESS" exit 7638 fi git clone $ZERONET_BLOG_REPO ZeroBlog if [ ! -d $ZERONET_DIR/ZeroBlog ]; then echo 'ZeroBlog repo could not be cloned' exit 6739 fi echo "Blog address: $ZERONET_BLOG_ADDRESS" echo "Blog private key: $ZERONET_BLOG_PRIVATE_KEY" cp -r $ZERONET_DIR/ZeroBlog/* $ZERONET_DIR/data/$ZERONET_BLOG_ADDRESS sed -i "s/ZeroBlog Demo/$(hostname)'s Blog/g" $ZERONET_DIR/data/$ZERONET_BLOG_ADDRESS/index.html sed -i 's|

.*|

Freedom in the Mesh

|g' $ZERONET_DIR/data/$ZERONET_BLOG_ADDRESS/index.html sed -i "s/Blogging platform Demo/Blogging platform/g" $ZERONET_DIR/data/$ZERONET_BLOG_ADDRESS/content.json python zeronet.py siteSign $ZERONET_BLOG_ADDRESS $ZERONET_BLOG_PRIVATE_KEY # Add an avahi service echo '' > /tmp/zeronet-blog.service echo '' >> /tmp/zeronet-blog.service echo '' >> /tmp/zeronet-blog.service echo ' %h ZeroNet Blog' >> /tmp/zeronet-blog.service echo ' ' >> /tmp/zeronet-blog.service echo ' _zeronet._udp' >> /tmp/zeronet-blog.service echo " $ZERONET_PORT" >> /tmp/zeronet-blog.service echo " $ZERONET_URL/$ZERONET_BLOG_ADDRESS" >> /tmp/zeronet-blog.service echo ' ' >> /tmp/zeronet-blog.service echo '' >> /tmp/zeronet-blog.service sudo cp /tmp/zeronet-blog.service /etc/avahi/services/zeronet-blog.service if [ ! -d /home/$MY_USERNAME/.config/zeronet ]; then mkdir -p /home/$MY_USERNAME/.config/zeronet fi echo "$ZERONET_URL/$ZERONET_BLOG_ADDRESS" > /home/$MY_USERNAME/.config/zeronet/myblog if ! grep -q "ZeroNet Blog address" /home/$MY_USERNAME/README; then echo '' >> /home/$MY_USERNAME/README echo "ZeroNet Blog address: $ZERONET_BLOG_ADDRESS" >> /home/$MY_USERNAME/README echo "ZeroNet Blog private key: $ZERONET_BLOG_PRIVATE_KEY" >> /home/$MY_USERNAME/README fi echo 'Zeronet blog installed' } function install_zeronet_forum { if [ ! -f /home/$MY_USERNAME/README ]; then touch /home/$MY_USERNAME/README fi if grep -q "ZeroNet Forum address" /home/$MY_USERNAME/README; then return fi if [ ! -d /etc/avahi ]; then echo 'Avahi is not installed' exit 736 fi cd $ZERONET_DIR python zeronet.py --batch siteCreate 2> $ZERONET_DIR/forum.txt if [ ! -f $ZERONET_DIR/forum.txt ]; then echo 'Unable to create forum' exit 479 fi forum_address=$(cat forum.txt | grep "Site address" | awk -F ':' '{print $2}') forum_private_key=$(cat forum.txt | grep "Site private key" | awk -F ':' '{print $2}') ZERONET_FORUM_ADDRESS=${forum_address//[[:blank:]]/} ZERONET_FORUM_PRIVATE_KEY=${forum_private_key//[[:blank:]]/} if [ ${#ZERONET_FORUM_ADDRESS} -lt 20 ]; then echo "Address: $ZERONET_FORUM_ADDRESS" echo "Public key: $ZERONET_FORUM_PRIVATE_KEY" echo 'Unable to create zeronet forum address' exit 76352 fi if [ ${#ZERONET_FORUM_PRIVATE_KEY} -lt 20 ]; then echo "Address: $ZERONET_FORUM_ADDRESS" echo "Public key: $ZERONET_FORUM_PRIVATE_KEY" echo 'Unable to create zeronet forum private key' exit 87356 fi if [ ! -d "$ZERONET_DIR/data/$ZERONET_FORUM_ADDRESS" ]; then echo "Unable to find site directory: $ZERONET_DIR/data/$ZERONET_FORUM_ADDRESS" exit 7638 fi git clone $ZERONET_FORUM_REPO ZeroTalk if [ ! -d $ZERONET_DIR/ZeroTalk ]; then echo 'ZeroTalk repo could not be cloned' exit 6739 fi echo "Forum address: $ZERONET_FORUM_ADDRESS" echo "Forum private key: $ZERONET_FORUM_PRIVATE_KEY" cp -r $ZERONET_DIR/ZeroTalk/* $ZERONET_DIR/data/$ZERONET_FORUM_ADDRESS sed -i "s/ZeroBoard/$(hostname)'s Forum/g" $ZERONET_DIR/data/$ZERONET_FORUM_ADDRESS/index.html sed -i "s/ZeroTalk/$(hostname)'s Forum/g" $ZERONET_DIR/data/$ZERONET_FORUM_ADDRESS/index.html sed -i 's|

.*|

Freedom in the Mesh

|g' $ZERONET_DIR/data/$ZERONET_FORUM_ADDRESS/index.html sed -i "s/Messaging Board Demo/Messaging Board/g" $ZERONET_DIR/data/$ZERONET_FORUM_ADDRESS/content.json python zeronet.py siteSign $ZERONET_FORUM_ADDRESS $ZERONET_FORUM_PRIVATE_KEY # Add an avahi service echo '' > /tmp/zeronet-forum.service echo '' >> /tmp/zeronet-forum.service echo '' >> /tmp/zeronet-forum.service echo ' %h ZeroNet Forum' >> /tmp/zeronet-forum.service echo ' ' >> /tmp/zeronet-forum.service echo ' _zeronet._udp' >> /tmp/zeronet-forum.service echo " $ZERONET_PORT" >> /tmp/zeronet-forum.service echo " $ZERONET_URL/$ZERONET_FORUM_ADDRESS" >> /tmp/zeronet-forum.service echo ' ' >> /tmp/zeronet-forum.service echo '' >> /tmp/zeronet-forum.service sudo cp /tmp/zeronet-forum.service /etc/avahi/services/zeronet-forum.service if [ ! -d /home/$MY_USERNAME/.config/zeronet ]; then mkdir -p /home/$MY_USERNAME/.config/zeronet fi echo "$ZERONET_URL/$ZERONET_FORUM_ADDRESS" > /home/$MY_USERNAME/.config/zeronet/myforum if ! grep -q "ZeroNet Forum address" /home/$MY_USERNAME/README; then echo '' >> /home/$MY_USERNAME/README echo "ZeroNet Forum address: $ZERONET_FORUM_ADDRESS" >> /home/$MY_USERNAME/README echo "ZeroNet Forum private key: $ZERONET_FORUM_PRIVATE_KEY" >> /home/$MY_USERNAME/README fi echo 'Zeronet forum installed' } 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 } 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 sudo apt-get update install_web_server install_zeronet install_zeronet_blog install_zeronet_forum 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" rm $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 --ipv6_enabled 0 & fi ZERONET_INDEX=/home/$MY_USERNAME/mesh.html sleep 5 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_INDEX elif which gnome-open > /dev/null; then gnome-open $ZERONET_INDEX fi exit 0