freedombone/src/freedombone-image-mesh

916 lines
38 KiB
Plaintext
Raw Normal View History

2015-12-24 20:04:17 +01:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# This command is run on initial install in order to set up a mesh router
#
# License
# =======
#
# 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
2015-12-24 20:04:17 +01:00
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2016-02-13 23:09:27 +01:00
# GNU Affero General Public License for more details.
2015-12-24 20:04:17 +01:00
#
2016-02-13 23:09:27 +01:00
# You should have received a copy of the GNU Affero General Public License
2015-12-24 20:04:17 +01:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROJECT_NAME='freedombone'
export TEXTDOMAIN=${PROJECT_NAME}-image-mesh
export TEXTDOMAINDIR="/usr/share/locale"
2016-07-30 18:43:29 +02:00
# The browser application to use
BROWSER=iceweasel
2015-12-24 20:04:17 +01:00
MY_USERNAME='fbone'
2016-01-17 00:44:04 +01:00
PEER_ID=
INSTALL_DIR=/root/build
INSTALL_LOG=/var/log/${PROJECT_NAME}.log
2015-12-24 20:04:17 +01:00
DEFAULT_USERNAME=fbone
2016-07-17 00:11:19 +02:00
ZERONET_URL='http://127.0.0.1:43110'
ZERONET_PORT=15441
GO_VERSION=1.7
2016-05-28 17:28:31 +02:00
TOX_NODES=
#TOX_NODES=(
# '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
# '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
#)
2016-06-26 00:46:05 +02:00
MESH_INSTALL_DIR=/var/lib
2016-07-21 23:43:40 +02:00
MESH_INSTALL_COMPLETED=/root/.mesh_setup_completed
MESH_INSTALL_SETUP=/root/.initial_mesh_setup
2016-07-22 09:29:17 +02:00
MESH_AMNESIC=/root/.amnesic
FIRST_BOOT=/home/$MY_USERNAME/.first_boot
2016-06-26 00:46:05 +02:00
2016-07-28 20:58:28 +02:00
# Tomb containing logs
2016-07-30 11:54:53 +02:00
TOMB_LOG_SIZE_MB=10
2016-07-28 20:58:28 +02:00
# size of the tomb used to store qtox settings
2016-07-30 11:54:53 +02:00
TOMB_TOX_SIZE_MB=10
2016-07-28 20:58:28 +02:00
# Tomb containing tox bootstrap
2016-07-28 21:04:08 +02:00
TOMB_TOX_BOOTSTRAP_SIZE_MB=10
2016-07-28 20:58:28 +02:00
# Tomb containing zeronet
TOMB_ZERONET_CONFIG_SIZE_MB=10
2016-07-30 11:48:44 +02:00
TOMB_ZERONET_DATA_SIZE_MB=32
2016-08-03 17:17:01 +02:00
MESH_INSTALL_DIR=/var/lib
ZERONET_INSTALL=$MESH_INSTALL_DIR/zeronet
TOX_USERS_FILE=$ZERONET_INSTALL/${PROJECT_NAME}-tox-users.html
# whether to enable zeronet
ENABLE_ZERONET=
2016-09-04 11:55:24 +02:00
function create_avahi_service {
service_name=$1
service_type=$2
service_protocol=$3
service_port=$4
service_description="$5"
if [ ! -d /etc/avahi ]; then
echo $'create_avahi_service: avahi was not installed'
exit 52925
fi
echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /etc/avahi/services/${service_name}.service
echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /etc/avahi/services/${service_name}.service
echo '<service-group>' >> /etc/avahi/services/${service_name}.service
echo " <name replace-wildcards=\"yes\">%h ${service_type}</name>" >> /etc/avahi/services/${service_name}.service
echo ' <service>' >> /etc/avahi/services/${service_name}.service
echo " <type>_${service_type}._${service_protocol}</type>" >> /etc/avahi/services/${service_name}.service
echo " <port>${service_port}</port>" >> /etc/avahi/services/${service_name}.service
if [ "$service_description" ]; then
echo " <txt-record>$service_description</txt-record>" >> /tmp/zeronet-blog.service
fi
echo ' </service>' >> /etc/avahi/services/${service_name}.service
echo '</service-group>' >> /etc/avahi/services/${service_name}.service
}
2016-07-27 21:13:34 +02:00
function create_ram_disk {
2016-08-03 17:17:01 +02:00
ramdisk_size_mb=$1
if [ ! -d /mnt/ramdisk ]; then
mkdir -p /mnt/ramdisk
fi
if ! grep -q "ramdisk" /etc/fstab; then
mount -t tmpfs -o size=${ramdisk_size_mb}m tmpfs /mnt/ramdisk
echo "tmpfs /mnt/ramdisk tmpfs nodev,nosuid,noexec,nodiratime,size=${ramdisk_size_mb}M 0 0" >> /etc/fstab
fi
2016-07-27 21:13:34 +02:00
}
2016-05-30 22:05:03 +02:00
function set_hostname {
2016-08-03 17:17:01 +02:00
DEFAULT_DOMAIN_NAME="$1"
2016-05-30 22:05:03 +02:00
2016-08-03 17:17:01 +02:00
echo "$DEFAULT_DOMAIN_NAME" > /etc/hostname
hostname $DEFAULT_DOMAIN_NAME
2016-05-30 22:05:03 +02:00
2016-08-03 17:17:01 +02:00
if grep -q "127.0.1.1" /etc/hosts; then
sed -i "s/127.0.1.1.*/127.0.1.1 $DEFAULT_DOMAIN_NAME/g" /etc/hosts
else
echo "127.0.1.1 $DEFAULT_DOMAIN_NAME" >> /etc/hosts
fi
2016-05-30 22:05:03 +02:00
}
2015-12-24 20:04:17 +01:00
function change_avahi_name {
2016-08-03 17:17:01 +02:00
decarray=( 1 2 3 4 5 6 7 8 9 0 )
PEER_ID=${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}${decarray[$RANDOM%10]}
sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" /etc/avahi/avahi-daemon.conf
sed -i "s|host-name=.*|host-name=P$PEER_ID|g" /etc/avahi/avahi-daemon.conf
set_hostname P$PEER_ID
systemctl restart avahi-daemon
echo "New avahi name for this peer is P$PEER_ID"
2016-08-23 14:24:23 +02:00
echo "mesh-$PEER_ID"
2016-08-03 17:17:01 +02:00
echo $"avahi name changed to P${PEER_ID}.local" >> $INSTALL_LOG
2015-12-24 20:04:17 +01:00
}
2016-01-17 00:44:04 +01:00
function configure_zeronet {
2016-08-03 17:17:01 +02:00
sed -i "s|ExecStart=.*|ExecStart=/usr/bin/python zeronet.py --ip_external P${PEER_ID}.local --trackers_file $MESH_INSTALL_DIR/zeronet/bootstrap|g" /etc/systemd/system/zeronet.service
echo $"zeronet daemon updated to P${PEER_ID}.local" >> $INSTALL_LOG
2016-07-21 23:43:40 +02:00
}
2015-12-24 20:04:17 +01:00
function configure_zeronet_blog {
2016-08-03 17:17:01 +02:00
echo $'Updating ZeroNet Blog' >> $INSTALL_LOG
ZERONET_DEFAULT_BLOG_TITLE="${MY_USERNAME}'s Blog"
cd $MESH_INSTALL_DIR/zeronet
python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/blog.txt
if [ ! -f $MESH_INSTALL_DIR/zeronet/blog.txt ]; then
echo $'Unable to create ZeroNet blog' >> $INSTALL_LOG
exit 7386
fi
blog_address=$(cat $MESH_INSTALL_DIR/zeronet/blog.txt | grep "Site address" | awk -F ':' '{print $2}')
blog_private_key=$(cat $MESH_INSTALL_DIR/zeronet/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" >> $INSTALL_LOG
echo $"Public key: $ZERONET_BLOG_PRIVATE_KEY" >> $INSTALL_LOG
echo $'Unable to create zeronet blog address' >> $INSTALL_LOG
exit 7358
fi
if [ ${#ZERONET_BLOG_PRIVATE_KEY} -lt 20 ]; then
echo $"Address: $ZERONET_BLOG_ADDRESS" >> $INSTALL_LOG
echo $"Public key: $ZERONET_BLOG_PRIVATE_KEY" >> $INSTALL_LOG
echo $'Unable to create zeronet blog private key' >> $INSTALL_LOG
exit 1639
fi
if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS" ]; then
echo $"Unable to find site directory: $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS" >> $INSTALL_LOG
exit 7638
fi
echo $"ZeroNet Blog address: $ZERONET_BLOG_ADDRESS" >> $INSTALL_LOG
echo $"ZeroNet Blog private key: $ZERONET_BLOG_PRIVATE_KEY" >> $INSTALL_LOG
cp -r $MESH_INSTALL_DIR/zeronet/ZeroBlog/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS
if [ ! -d $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data ]; then
mkdir $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data
fi
cp $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data-default/data.json $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data
sed -i "s/MyZeroBlog/$ZERONET_DEFAULT_BLOG_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data/data.json
sed -i "s/My ZeroBlog./$ZERONET_DEFAULT_BLOG_TAGLINE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data/data.json
sed -i "s/ZeroBlog Demo/$ZERONET_DEFAULT_BLOG_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/index.html
sed -i "s|<h3 class=\"description\">.*|<h3 class=\"description\">$ZERONET_DEFAULT_BLOG_TAGLINE</h3>|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/index.html
sed -i "s/Blogging platform Demo/Blogging platform/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/content.json
python zeronet.py siteSign $ZERONET_BLOG_ADDRESS $ZERONET_BLOG_PRIVATE_KEY
# update the avahi service
echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /tmp/zeronet-blog.service
echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /tmp/zeronet-blog.service
echo '<service-group>' >> /tmp/zeronet-blog.service
echo ' <name replace-wildcards="yes">%h ZeroNet Blog</name>' >> /tmp/zeronet-blog.service
echo ' <service>' >> /tmp/zeronet-blog.service
echo ' <type>_zeronet._udp</type>' >> /tmp/zeronet-blog.service
echo " <port>$ZERONET_PORT</port>" >> /tmp/zeronet-blog.service
echo " <txt-record>$ZERONET_URL/$ZERONET_BLOG_ADDRESS</txt-record>" >> /tmp/zeronet-blog.service
echo ' </service>' >> /tmp/zeronet-blog.service
echo '</service-group>' >> /tmp/zeronet-blog.service
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
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
fi
echo "$ZERONET_URL/$ZERONET_BLOG_ADDRESS" > /home/${MY_USERNAME}/.config/zeronet/myblog
sed -i "s|ZeroNet Blog address.*|ZeroNet Blog address: $ZERONET_BLOG_ADDRESS|g" /home/${MY_USERNAME}/README
sed -i "s|ZeroNet Blog private key.*|ZeroNet Blog private key: $ZERONET_BLOG_PRIVATE_KEY|g" /home/${MY_USERNAME}/README
if [ -d ${MESH_INSTALL_DIR}/zeronet ]; then
chown -R zeronet:zeronet ${MESH_INSTALL_DIR}/zeronet
fi
echo $'Update of ZeroNet Blog completed' >> $INSTALL_LOG
2016-07-21 23:43:40 +02:00
}
2015-12-24 20:04:17 +01:00
function configure_zeronet_mail {
2016-08-03 17:17:01 +02:00
echo $'Updating ZeroNet Mail' >> $INSTALL_LOG
ZERONET_DEFAULT_MAIL_TITLE="${MY_USERNAME}'s Mail"
cd $MESH_INSTALL_DIR/zeronet
python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/mail.txt
if [ ! -f $MESH_INSTALL_DIR/zeronet/mail.txt ]; then
echo $'Unable to create ZeroNet mail' >> $INSTALL_LOG
exit 72574
fi
mail_address=$(cat $MESH_INSTALL_DIR/zeronet/mail.txt | grep "Site address" | awk -F ':' '{print $2}')
mail_private_key=$(cat $MESH_INSTALL_DIR/zeronet/mail.txt | grep "Site private key" | awk -F ':' '{print $2}')
ZERONET_MAIL_ADDRESS=${mail_address//[[:blank:]]/}
ZERONET_MAIL_PRIVATE_KEY=${mail_private_key//[[:blank:]]/}
if [ ${#ZERONET_MAIL_ADDRESS} -lt 20 ]; then
echo $"Address: $ZERONET_MAIL_ADDRESS" >> $INSTALL_LOG
echo $"Public key: $ZERONET_MAIL_PRIVATE_KEY" >> $INSTALL_LOG
echo $'Unable to create zeronet mail address' >> $INSTALL_LOG
exit 7358
fi
if [ ${#ZERONET_MAIL_PRIVATE_KEY} -lt 20 ]; then
echo $"Address: $ZERONET_MAIL_ADDRESS" >> $INSTALL_LOG
echo $"Public key: $ZERONET_MAIL_PRIVATE_KEY" >> $INSTALL_LOG
echo $'Unable to create zeronet mail private key' >> $INSTALL_LOG
exit 1639
fi
if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS" ]; then
echo $"Unable to find site directory: $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS" >> $INSTALL_LOG
exit 7638
fi
echo $"ZeroNet Mail address: $ZERONET_MAIL_ADDRESS" >> $INSTALL_LOG
echo $"ZeroNet Mail private key: $ZERONET_MAIL_PRIVATE_KEY" >> $INSTALL_LOG
cp -r $MESH_INSTALL_DIR/zeronet/ZeroMail/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS
if [ ! -d $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data ]; then
mkdir $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data
fi
cp $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data-default/data.json $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data
sed -i "s/MyZeroMail/$ZERONET_DEFAULT_MAIL_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data/data.json
sed -i "s/My ZeroMail./$ZERONET_DEFAULT_MAIL_TAGLINE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data/data.json
sed -i "s/ZeroMail Demo/$ZERONET_DEFAULT_MAIL_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/index.html
sed -i "s|<h3 class=\"description\">.*|<h3 class=\"description\">$ZERONET_DEFAULT_MAIL_TAGLINE</h3>|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/index.html
sed -i "s/Mailging platform Demo/Mailging platform/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/content.json
python zeronet.py siteSign $ZERONET_MAIL_ADDRESS $ZERONET_MAIL_PRIVATE_KEY
# Add an avahi service
echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /tmp/zeronet-mail.service
echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /tmp/zeronet-mail.service
echo '<service-group>' >> /tmp/zeronet-mail.service
echo ' <name replace-wildcards="yes">%h ZeroNet Mail</name>' >> /tmp/zeronet-mail.service
echo ' <service>' >> /tmp/zeronet-mail.service
echo ' <type>_zeronet._udp</type>' >> /tmp/zeronet-mail.service
echo " <port>$ZERONET_PORT</port>" >> /tmp/zeronet-mail.service
echo " <txt-record>$ZERONET_URL/$ZERONET_MAIL_ADDRESS</txt-record>" >> /tmp/zeronet-mail.service
echo ' </service>' >> /tmp/zeronet-mail.service
echo '</service-group>' >> /tmp/zeronet-mail.service
cp /tmp/zeronet-mail.service /etc/avahi/services/zeronet-mail.service
if [ ! -d /home/${MY_USERNAME}/.config/zeronet ]; then
mkdir -p /home/${MY_USERNAME}/.config/zeronet
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
fi
echo "$ZERONET_URL/$ZERONET_MAIL_ADDRESS" > /home/${MY_USERNAME}/.config/zeronet/mymail
sed -i "s|ZeroNet Mail address.*|ZeroNet Mail address: $ZERONET_MAIL_ADDRESS|g" /home/${MY_USERNAME}/README
sed -i "s|ZeroNet Mail private key.*|ZeroNet Mail private key: $ZERONET_MAIL_PRIVATE_KEY|g" /home/${MY_USERNAME}/README
if [ -d ${MESH_INSTALL_DIR}/zeronet ]; then
chown -R zeronet:zeronet ${MESH_INSTALL_DIR}/zeronet
fi
echo $'Update of ZeroNet Mail completed' >> $INSTALL_LOG
2016-07-21 23:43:40 +02:00
}
2015-12-24 20:04:17 +01:00
function configure_zeronet_forum {
2016-08-03 17:17:01 +02:00
echo $'Updating ZeroNet Forum' >> $INSTALL_LOG
ZERONET_DEFAULT_FORUM_TITLE="${MY_USERNAME}'s Forum"
cd $MESH_INSTALL_DIR/zeronet
python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/forum.txt
if [ ! -f $MESH_INSTALL_DIR/zeronet/forum.txt ]; then
echo $'Unable to create ZeroNet forum' >> $INSTALL_LOG
exit 47962
fi
forum_address=$(cat $MESH_INSTALL_DIR/zeronet/forum.txt | grep "Site address" | awk -F ':' '{print $2}')
forum_private_key=$(cat $MESH_INSTALL_DIR/zeronet/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" >> $INSTALL_LOG
echo $"Public key: $ZERONET_FORUM_PRIVATE_KEY" >> $INSTALL_LOG
echo $'Unable to create zeronet forum address' >> $INSTALL_LOG
exit 76352
fi
if [ ${#ZERONET_FORUM_PRIVATE_KEY} -lt 20 ]; then
echo $"Address: $ZERONET_FORUM_ADDRESS" >> $INSTALL_LOG
echo $"Public key: $ZERONET_FORUM_PRIVATE_KEY" >> $INSTALL_LOG
echo $'Unable to create zeronet forum private key' >> $INSTALL_LOG
exit 87356
fi
if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS" ]; then
echo $"Unable to find site directory: $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS" >> $INSTALL_LOG
exit 7638
fi
echo $"Forum address: $ZERONET_FORUM_ADDRESS"
echo $"Forum private key: $ZERONET_FORUM_PRIVATE_KEY"
cp -r $MESH_INSTALL_DIR/zeronet/ZeroTalk/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS
sed -i "s/ZeroBoard/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
sed -i "s/ZeroTalk/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
sed -i "s|Demo for dynamic, decentralized content publishing.|$ZERONET_DEFAULT_FORUM_TAGLINE|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
sed -i 's/Messaging Board Demo/Messaging Board/g' $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/content.json
sed -i "s/ZeroBoard/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/content.json
python zeronet.py siteSign $ZERONET_FORUM_ADDRESS $ZERONET_FORUM_PRIVATE_KEY --inner_path data/users/content.json
# Add an avahi service
echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /tmp/zeronet-forum.service
echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /tmp/zeronet-forum.service
echo '<service-group>' >> /tmp/zeronet-forum.service
echo ' <name replace-wildcards="yes">%h ZeroNet Forum</name>' >> /tmp/zeronet-forum.service
echo ' <service>' >> /tmp/zeronet-forum.service
echo ' <type>_zeronet._udp</type>' >> /tmp/zeronet-forum.service
echo " <port>$ZERONET_PORT</port>" >> /tmp/zeronet-forum.service
echo " <txt-record>$ZERONET_URL/$ZERONET_FORUM_ADDRESS</txt-record>" >> /tmp/zeronet-forum.service
echo ' </service>' >> /tmp/zeronet-forum.service
echo '</service-group>' >> /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
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
fi
echo "$ZERONET_URL/$ZERONET_FORUM_ADDRESS" > /home/${MY_USERNAME}/.config/zeronet/myforum
sed -i "s|ZeroNet Forum address.*|ZeroNet Forum address: $ZERONET_FORUM_ADDRESS|g" /home/${MY_USERNAME}/README
sed -i "s|ZeroNet Forum private key.*|ZeroNet Forum private key: $ZERONET_FORUM_PRIVATE_KEY|g" /home/${MY_USERNAME}/README
if [ -d ${MESH_INSTALL_DIR}/zeronet ]; then
chown -R zeronet:zeronet ${MESH_INSTALL_DIR}/zeronet
fi
echo $'Update of ZeroNet Forum completed' >> $INSTALL_LOG
2016-07-21 23:43:40 +02:00
}
2016-06-25 21:08:59 +02:00
function configure_zeronet_id {
2016-08-03 17:17:01 +02:00
echo $'Updating ZeroID' >> $INSTALL_LOG
cd $MESH_INSTALL_DIR/zeronet
python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/zeroid.txt
if [ ! -f $MESH_INSTALL_DIR/zeronet/zeroid.txt ]; then
echo $'Unable to create ZeroID' >> $INSTALL_LOG
exit 47962
fi
zeroid_address=$(cat $MESH_INSTALL_DIR/zeronet/zeroid.txt | grep "Site address" | awk -F ':' '{print $2}')
zeroid_private_key=$(cat $MESH_INSTALL_DIR/zeronet/zeroid.txt | grep "Site private key" | awk -F ':' '{print $2}')
ZERONET_ID_ADDRESS=${zeroid_address//[[:blank:]]/}
ZERONET_ID_PRIVATE_KEY=${zeroid_private_key//[[:blank:]]/}
if [ ${#ZERONET_ID_ADDRESS} -lt 20 ]; then
echo $"Address: $ZERONET_ID_ADDRESS" >> $INSTALL_LOG
echo $"Public key: $ZERONET_ID_PRIVATE_KEY" >> $INSTALL_LOG
echo $'Unable to create ZeroID address' >> $INSTALL_LOG
exit 76352
fi
if [ ${#ZERONET_ID_PRIVATE_KEY} -lt 20 ]; then
echo $"Address: $ZERONET_ID_ADDRESS" >> $INSTALL_LOG
echo $"Public key: $ZERONET_ID_PRIVATE_KEY" >> $INSTALL_LOG
echo $'Unable to create ZeroID private key' >> $INSTALL_LOG
exit 87356
fi
if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_ID_ADDRESS" ]; then
echo $"Unable to find site directory: $MESH_INSTALL_DIR/zeronet/data/$ZERONET_ID_ADDRESS" >> $INSTALL_LOG
exit 378434
fi
echo $"ZeroID address: $ZERONET_ID_ADDRESS"
echo $"ZeroID private key: $ZERONET_ID_PRIVATE_KEY"
cp -r $MESH_INSTALL_DIR/zeronet/ZeroID/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_ID_ADDRESS
# TODO
sed -i "s///g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_ID_ADDRESS/content.json
python zeronet.py siteSign $ZERONET_ID_ADDRESS $ZERONET_ID_PRIVATE_KEY --inner_path data/users/content.json
# Add an avahi service
echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /tmp/zeronet-id.service
echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /tmp/zeronet-id.service
echo '<service-group>' >> /tmp/zeronet-id.service
echo ' <name replace-wildcards="yes">%h ZeroNet ID Service</name>' >> /tmp/zeronet-id.service
echo ' <service>' >> /tmp/zeronet-id.service
echo ' <type>_zeronet._udp</type>' >> /tmp/zeronet-id.service
echo " <port>$ZERONET_PORT</port>" >> /tmp/zeronet-id.service
echo " <txt-record>$ZERONET_URL/$ZERONET_ID_ADDRESS</txt-record>" >> /tmp/zeronet-id.service
echo ' </service>' >> /tmp/zeronet-id.service
echo '</service-group>' >> /tmp/zeronet-id.service
sudo cp /tmp/zeronet-id.service /etc/avahi/services/zeronet-id.service
if [ ! -d /home/${MY_USERNAME}/.config/zeronet ]; then
mkdir -p /home/${MY_USERNAME}/.config/zeronet
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
fi
echo "$ZERONET_URL/$ZERONET_ID_ADDRESS" > /home/${MY_USERNAME}/.config/zeronet/myzeroid
sed -i "s|ZeroID address.*|ZeroID address: $ZERONET_ID_ADDRESS|g" /home/${MY_USERNAME}/README
sed -i "s|ZeroID private key.*|ZeroID private key: $ZERONET_ID_PRIVATE_KEY|g" /home/${MY_USERNAME}/README
if [ -d ${MESH_INSTALL_DIR}/zeronet ]; then
chown -R zeronet:zeronet ${MESH_INSTALL_DIR}/zeronet
fi
echo $'Update of ZeroID completed' >> $INSTALL_LOG
2016-06-25 21:08:59 +02:00
}
function configure_toxcore {
2016-08-03 17:17:01 +02:00
echo $'Configuring toxcore' >> $INSTALL_LOG
TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
if [ -f $MESH_AMNESIC ]; then
# change to the amnesic mount
sed -i 's|/var/lib/tox-bootstrapd|/media/tox-bootstrapd|g' /etc/tox-bootstrapd.conf
systemctl stop tox-bootstrapd.service
sed -i 's|WorkingDirectory=.*|WorkingDirectory=/media/tox-bootstrapd|g' /etc/systemd/system/tox-bootstrapd.service
systemctl daemon-reload
userdel -r tox-bootstrapd
useradd --home-dir /media/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
chmod 700 /media/tox-bootstrapd
fi
echo $'Enabling toxcore daemon' >> $INSTALL_LOG
systemctl enable tox-bootstrapd.service
echo $'Regenerating Tox bootstrap node keys' >> $INSTALL_LOG
systemctl stop tox-bootstrapd.service
if [ -f /var/lib/tox-bootstrapd/keys ]; then
rm /var/lib/tox-bootstrapd/keys
fi
systemctl start tox-bootstrapd.service
# sleep for a while so that the tox keys can be generated
sleep 30
TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt
if [ -f $MESH_AMNESIC ]; then
TOX_BOOTSTRAP_ID_FILE=/media/tox-bootstrapd/pubkey.txt
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
echo $'WARNING: Could not obtain the tox node public key' >> $INSTALL_LOG
exit 46362
fi
# save the public key for later reference
echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
echo $'Configured toxcore' >> $INSTALL_LOG
2015-12-24 20:04:17 +01:00
}
2016-07-29 19:59:19 +02:00
function create_tox_user {
# remove any existing user
if [ -f /home/${MY_USERNAME}/.config/tox/data.tox ]; then
rm -f /home/${MY_USERNAME}/.config/tox/data*
fi
if [ -d /home/${MY_USERNAME}/.config/tox/avatars ]; then
rm -rf /home/${MY_USERNAME}/.config/tox/avatars
2016-08-03 17:17:01 +02:00
fi
if [ ! -f /home/${MY_USERNAME}/.first_boot ]; then
touch /home/${MY_USERNAME}/.first_boot
fi
2016-08-03 17:17:01 +02:00
if [ ! -d /home/$MY_USERNAME/Desktop ]; then
return
fi
2016-09-01 00:54:49 +02:00
toxid -u $MY_USERNAME -n data
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config/tox
2016-08-23 14:18:18 +02:00
chmod +x /home/$MY_USERNAME/Desktop/*.desktop
2016-08-03 17:17:01 +02:00
chown ${MY_USERNAME}:${MY_USERNAME} /home/$MY_USERNAME/Desktop/*
2016-08-31 00:25:17 +02:00
echo $'Created Tox user' >> $INSTALL_LOG
2016-07-30 14:12:32 +02:00
}
function show_desktop_icons {
2016-08-03 17:17:01 +02:00
if [ ! -d /home/$MY_USERNAME/Desktop ]; then
return
fi
#echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/users.desktop
#echo 'Name=Users' >> /home/$MY_USERNAME/Desktop/users.desktop
#echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/users.desktop
#echo 'Comment=Users on the system' >> /home/$MY_USERNAME/Desktop/users.desktop
#echo "Exec=$BROWSER $TOX_USERS_FILE" >> /home/$MY_USERNAME/Desktop/users.desktop
#echo "Icon=$BROWSER" >> /home/$MY_USERNAME/Desktop/users.desktop
#echo 'StartupNotify=true' >> /home/$MY_USERNAME/Desktop/users.desktop
2016-08-03 17:17:01 +02:00
#echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/mesh.desktop
#echo 'Name=Mesh' >> /home/$MY_USERNAME/Desktop/mesh.desktop
#echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/mesh.desktop
#echo 'Comment=Browse the mesh' >> /home/$MY_USERNAME/Desktop/mesh.desktop
#echo 'TryExec=meshweb' >> /home/$MY_USERNAME/Desktop/mesh.desktop
#echo 'Exec=meshweb' >> /home/$MY_USERNAME/Desktop/mesh.desktop
#echo "Icon=$BROWSER" >> /home/$MY_USERNAME/Desktop/mesh.desktop
#echo 'StartupNotify=true' >> /home/$MY_USERNAME/Desktop/mesh.desktop
echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/new_identity.desktop
echo 'Version=1.0' >> /home/$MY_USERNAME/Desktop/new_identity.desktop
echo 'Name=New Identity' >> /home/$MY_USERNAME/Desktop/new_identity.desktop
echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/new_identity.desktop
echo 'Comment=Create a new identity' >> /home/$MY_USERNAME/Desktop/new_identity.desktop
echo 'Exec=mate-terminal -e freedombone-mesh-reset' >> /home/$MY_USERNAME/Desktop/new_identity.desktop
echo 'Icon=user-away' >> /home/$MY_USERNAME/Desktop/new_identity.desktop
echo 'Terminal=false' >> /home/$MY_USERNAME/Desktop/new_identity.desktop
echo 'Categories=Application;' >> /home/$MY_USERNAME/Desktop/new_identity.desktop
# set permissions
2016-08-23 14:18:18 +02:00
chmod +x /home/$MY_USERNAME/Desktop/*.desktop
2016-08-03 17:17:01 +02:00
chown ${MY_USERNAME}:${MY_USERNAME} /home/$MY_USERNAME/Desktop/*
chown ${MY_USERNAME}:${MY_USERNAME} /home/$MY_USERNAME/.config
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/$MY_USERNAME/.config/tox
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/$MY_USERNAME/.config/zeronet
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/$MY_USERNAME/.config/autostart
chown ${MY_USERNAME}:${MY_USERNAME} /home/$MY_USERNAME/*.sh
# link to Tahoe-LAFS Magic folder
#ln -s /home/${MY_USERNAME}/Desktop/${TAHOELAFS_SHARED_DIR} /home/${MY_USERNAME}/${TAHOELAFS_SHARED_DIR}
2016-08-03 17:17:01 +02:00
# restart caja
killall caja
killall mate-panel
2016-07-29 19:59:19 +02:00
}
2016-06-26 13:41:12 +02:00
function enable_batman_daemon {
2016-08-03 17:17:01 +02:00
systemctl enable batman
systemctl daemon-reload
2016-06-26 13:41:12 +02:00
}
2016-07-22 09:29:17 +02:00
function mesh_amnesic {
2016-08-03 17:17:01 +02:00
if [ ! -f $MESH_AMNESIC ]; then
return
fi
echo '#!/bin/bash' > /usr/bin/amnesic
echo '' >> /usr/bin/amnesic
echo 'MY_USERNAME=$1' >> /usr/bin/amnesic
echo 'tomb slam all' >> /usr/bin/amnesic
echo "if [ -f /home/${MY_USERNAME}/.bash_history ]; then" >> /usr/bin/amnesic
echo " shred -zu /home/${MY_USERNAME}/.bash_history" >> /usr/bin/amnesic
echo 'fi' >> /usr/bin/amnesic
echo "if [ -f /home/${MY_USERNAME}/.xsession-errors ]; then" >> /usr/bin/amnesic
echo " shred -zu /home/${MY_USERNAME}/.xsession-errors" >> /usr/bin/amnesic
echo 'fi' >> /usr/bin/amnesic
echo '' >> /usr/bin/amnesic
echo 'exit 0' >> /usr/bin/amnesic
chmod +x /usr/bin/amnesic
if [ ! -f /etc/systemd/system/amnesic.service ]; then
echo '[Unit]' > /etc/systemd/system/amnesic.service
echo 'Description=Amnesic Mesh' >> /etc/systemd/system/amnesic.service
echo '' >> /etc/systemd/system/amnesic.service
echo '[Service]' >> /etc/systemd/system/amnesic.service
echo 'User=root' >> /etc/systemd/system/amnesic.service
echo 'Group=root' >> /etc/systemd/system/amnesic.service
echo 'Type=oneshot' >> /etc/systemd/system/amnesic.service
echo 'RemainAfterExit=true' >> /etc/systemd/system/amnesic.service
echo 'ExecStart=/bin/true' >> /etc/systemd/system/amnesic.service
echo "ExecStop=/usr/bin/amnesic $MY_USERNAME" >> /etc/systemd/system/amnesic.service
echo '' >> /etc/systemd/system/amnesic.service
echo '[Install]' >> /etc/systemd/system/amnesic.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/amnesic.service
systemctl daemon-reload
fi
systemctl enable amnesic
systemctl start amnesic
2016-07-22 09:29:17 +02:00
}
2016-07-22 10:39:21 +02:00
function mesh_restart_daemons {
2016-08-03 17:17:01 +02:00
systemctl restart avahi-daemon
systemctl restart tox-bootstrapd
if [ $ENABLE_ZERONET ]; then
systemctl restart zeronet
fi
2016-08-03 17:17:01 +02:00
echo $'Daemons restarted' >> $INSTALL_LOG
2016-07-22 10:39:21 +02:00
}
2016-07-28 19:51:11 +02:00
function create_tomb {
2016-08-03 17:17:01 +02:00
tomb_name=$1
tomb_size=$2
if [ -f /tmp/${tomb_name}.tomb ]; then
tomb slam /tmp/${tomb_name}.tomb
fi
# make a temporary password
tomb dig -s ${tomb_size} /tmp/${tomb_name}.tomb
if [ ! -f /tmp/${tomb_name}.tomb ]; then
echo "WARNING: ${tomb_name} tomb did not install properly" >> /var/log/${PROJECT_NAME}.log
tomb >> /var/log/${PROJECT_NAME}.log
fi
TOMB_TEMP_PASSWORD="$(openssl rand -base64 32 | cut -c1-30)"
tomb forge /mnt/ramdisk/${tomb_name}.tomb.key --tomb-pwd "${TOMB_TEMP_PASSWORD}" --unsafe
tomb lock /tmp/${tomb_name}.tomb -k /mnt/ramdisk/${tomb_name}.tomb.key --tomb-pwd "${TOMB_TEMP_PASSWORD}" --unsafe
tomb open /tmp/${tomb_name}.tomb -k /mnt/ramdisk/${tomb_name}.tomb.key --tomb-pwd "${TOMB_TEMP_PASSWORD}" --unsafe
# stop stuff from popping up
pkill caja
# clear the temporary password
TOMB_TEMP_PASSWORD=
}
function setup_amnesic_data {
2016-08-03 17:17:01 +02:00
if [ ! -f $MESH_AMNESIC ]; then
return
fi
if [ ! -d /mnt/ramdisk ]; then
return
fi
# clear crypttab
if [ -f /etc/crypttab ]; then
shred -zu /etc/crypttab
touch /etc/crypttab
fi
tomb_name=log
create_tomb ${tomb_name} $TOMB_LOG_SIZE_MB
if [ -d /media/${tomb_name} ]; then
if [ -d /var/log ]; then
if [ ! -d /var/log_base ]; then
mv /var/log /var/log_base
fi
fi
ln -s /media/${tomb_name} /var/log
if [ -d /var/log_base ]; then
cp -rp /var/log_base/* /media/${tomb_name}
fi
echo "${tomb_name} tomb created" >> $INSTALL_LOG
else
echo "WARNING: ${tomb_name} tomb not found" >> $INSTALL_LOG
fi
tomb_name=tox-bootstrapd
if [ -f /etc/systemd/system/${tomb_name}.service ]; then
systemctl stop ${tomb_name}
fi
create_tomb ${tomb_name} $TOMB_TOX_BOOTSTRAP_SIZE_MB
if [ -d /media/${tomb_name} ]; then
if [ -d /var/lib/tox-bootstrapd ]; then
if [ ! -d /var/lib/tox-bootstrapd_base ]; then
mv /var/lib/tox-bootstrapd /var/lib/tox-bootstrapd_base
fi
fi
if [ -d /var/lib/tox-bootstrapd ]; then
shred -zu /var/lib/tox-bootstrapd/*
rm -rf /var/lib/tox-bootstrapd
fi
ln -s /media/${tomb_name} /var/lib/tox-bootstrapd
if [ -d /var/lib/tox-bootstrapd_base ]; then
cp -rp /var/lib/tox-bootstrapd_base/* /media/${tomb_name}
fi
echo "${tomb_name} tomb created" >> $INSTALL_LOG
else
echo "WARNING: ${tomb_name} tomb not found" >> $INSTALL_LOG
fi
tomb_name=tox
create_tomb ${tomb_name} $TOMB_TOX_SIZE_MB
if [ -d /media/${tomb_name} ]; then
if [ ! -d /home/${MY_USERNAME}/.config ]; then
mkdir -p /home/${MY_USERNAME}/.config
chown ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
fi
if [ -d /home/${MY_USERNAME}/.config/${tomb_name} ]; then
rm -rf /home/${MY_USERNAME}/.config/${tomb_name}
fi
ln -s /media/${tomb_name} /home/${MY_USERNAME}/.config/${tomb_name}
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config/${tomb_name}
chown -R ${MY_USERNAME}:${MY_USERNAME} /media/${tomb_name}
echo "${tomb_name} tomb created" >> $INSTALL_LOG
else
echo "WARNING: ${tomb_name} tomb not found" >> $INSTALL_LOG
fi
tomb_name=zeronet-config
create_tomb ${tomb_name} $TOMB_ZERONET_CONFIG_SIZE_MB
if [ -d /media/${tomb_name} ]; then
if [ ! -d /home/${MY_USERNAME}/.config ]; then
mkdir -p /home/${MY_USERNAME}/.config
chown ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config
fi
if [ -d /home/${MY_USERNAME}/.config/zeronet ]; then
rm -rf /home/${MY_USERNAME}/.config/zeronet
fi
ln -s /media/${tomb_name} /home/${MY_USERNAME}/.config/zeronet
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.config/zeronet
chown -R ${MY_USERNAME}:${MY_USERNAME} /media/${tomb_name}
echo "${tomb_name} tomb created" >> $INSTALL_LOG
else
echo "WARNING: ${tomb_name} tomb not found" >> $INSTALL_LOG
fi
tomb_name=zeronet-data
create_tomb ${tomb_name} $TOMB_ZERONET_DATA_SIZE_MB
if [ -d /media/${tomb_name} ]; then
if [ -d /var/lib/zeronet ]; then
if [ ! -d /var/lib/zeronet_base ]; then
mv /var/lib/zeronet /var/lib/zeronet_base
fi
fi
ln -s /media/${tomb_name} /var/lib/zeronet
if [ -d /var/lib/zeronet_base ]; then
cp -rp /var/lib/zeronet_base/* /media/${tomb_name}
fi
echo "${tomb_name} tomb created" >> $INSTALL_LOG
else
echo "WARNING: ${tomb_name} tomb not found" >> $INSTALL_LOG
fi
}
2016-08-12 14:32:23 +02:00
function setup_ipfs {
2016-08-13 20:36:56 +02:00
IPFS_PATH=/usr/bin
2016-08-12 14:32:23 +02:00
IPFS_KEY_LENGTH=2048
2016-08-14 23:04:34 +02:00
IPFS_COMMAND=$IPFS_PATH/ipfs
2016-09-04 17:12:12 +02:00
IPFS_PUBLIC=/home/$MY_USERNAME/.ipfs-public
2016-08-12 14:32:23 +02:00
2016-09-03 18:10:17 +02:00
su -c "systemctl --user enable ipfs" - $MY_USERNAME
su -c "systemctl --user start ipfs" - $MY_USERNAME
2016-09-04 17:12:12 +02:00
if [ -d /home/$MY_USERNAME/Public ]; then
rm -rf /home/$MY_USERNAME/Public
fi
if [ -d /home/$MY_USERNAME/.ipfs ]; then
2016-09-04 17:12:12 +02:00
shred -zu /home/$MY_USERNAME/.ipfs/config
rm -rf /home/$MY_USERNAME/.ipfs
fi
2016-09-03 16:51:10 +02:00
if [ -f /home/$MY_USERNAME/.ipfs-id ]; then
2016-09-04 17:12:12 +02:00
shred -zu /home/$MY_USERNAME/.ipfs-id
fi
if [ -f /home/$MY_USERNAME/.ipfs-public ]; then
shred -zu /home/$MY_USERNAME/.ipfs-public
2016-09-03 16:51:10 +02:00
fi
2016-09-04 11:55:24 +02:00
if [ -f /home/$MY_USERNAME/.ipfs-users ]; then
2016-09-04 17:12:12 +02:00
shred -zu /home/$MY_USERNAME/.ipfs-users
2016-09-04 11:55:24 +02:00
fi
2016-08-14 23:04:34 +02:00
su -c "$IPFS_COMMAND init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
2016-08-12 22:42:23 +02:00
if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
2016-08-12 14:32:23 +02:00
echo "IPFS could not be initialised for user $MY_USERNAME" >> $INSTALL_LOG
return
2016-08-12 14:32:23 +02:00
fi
2016-08-12 22:42:23 +02:00
MY_IPFS_ID=/home/$MY_USERNAME/.ipfs-id
2016-09-03 16:51:10 +02:00
su -c "echo \$($IPFS_COMMAND id | grep '\"ID\":' | awk -F '\"' '{print \$4}') > $MY_IPFS_ID" - $MY_USERNAME
2016-08-12 22:42:23 +02:00
if [ ! -f $MY_IPFS_ID ]; then
2016-08-12 14:32:23 +02:00
echo 'No IPFS identity was created' >> $INSTALL_LOG
return
2016-08-12 14:32:23 +02:00
fi
2016-08-12 22:42:23 +02:00
IPFS_PEER_ID=$(cat $MY_IPFS_ID)
2016-08-12 14:32:23 +02:00
if [ ${#IPFS_PEER_ID} -lt 10 ]; then
echo 'Invalid IPFS peer ID' >> $INSTALL_LOG
echo "$IPFS_PEER_ID" >> $INSTALL_LOG
return
2016-08-12 14:32:23 +02:00
fi
2016-09-04 17:12:12 +02:00
# make a public directory
if [ -d /home/$MY_USERNAME/Desktop ]; then
if [ ! -d /home/$MY_USERNAME/Public ]; then
mkdir /home/$MY_USERNAME/Public
chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Public
su -c "echo \$($IPFS_COMMAND add -rq /home/$MY_USERNAME/Public | tail -n 1) > $IPFS_PUBLIC" - $MY_USERNAME
if [ ! -f $IPFS_PUBLIC ]; then
echo $'Unable to create public IPFS directory' >> $INSTALL_LOG
exit 368225
fi
fi
fi
2016-09-04 11:55:24 +02:00
TOX_ID=$(su -c 'toxid' - $MY_USERNAME)
2016-09-04 17:12:12 +02:00
create_avahi_service ipfs "ipfs" udp $IPFS_PORT "${IPFS_PEER_ID}:${TOX_ID}"
2016-09-04 11:55:24 +02:00
2016-08-12 14:32:23 +02:00
echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG
}
2016-08-28 00:40:21 +02:00
function setup_tahoelafs {
reconfigure_tahoelafs
TAHOELAFS_CONFIG=/home/${MY_USERNAME}/.tahoe/tahoe.cfg
if [ ! -f ${TAHOELAFS_CONFIG} ]; then
exit 673923
fi
2016-08-31 00:25:17 +02:00
echo $'Configured Tahoe-LAFS' >> $INSTALL_LOG
2016-08-28 00:40:21 +02:00
}
2016-07-21 23:43:40 +02:00
# whether to reset the identity
2016-07-22 10:39:21 +02:00
set_new_identity=
2016-07-21 23:43:40 +02:00
if [ $2 ]; then
2016-08-03 17:17:01 +02:00
if [[ "$2" == $"new"* ]]; then
if [ ! -f $MESH_INSTALL_SETUP ]; then
touch $MESH_INSTALL_SETUP
fi
set_new_identity=1
fi
if [[ "$2" == $"amnesic"* ]]; then
if [ ! -f $MESH_AMNESIC ]; then
touch $MESH_AMNESIC
fi
if [ ! -f $MESH_INSTALL_SETUP ]; then
touch $MESH_INSTALL_SETUP
fi
set_new_identity=1
fi
2016-07-21 23:43:40 +02:00
fi
if [ -f $MESH_INSTALL_SETUP ]; then
2016-08-03 17:17:01 +02:00
if [ $1 ]; then
MY_USERNAME=$1
fi
if [ ! $set_new_identity ]; then
# sleep in order to allow other daemons to start up
sleep 15
fi
# clear the install log
if [ -f $INSTALL_LOG ]; then
rm $INSTALL_LOG
fi
echo $'Beginning mesh node setup' >> $INSTALL_LOG
if [ -d /home/$MY_USERNAME/.config ]; then
chown ${MY_USERNAME}:${MY_USERNAME} /home/$MY_USERNAME/.config
fi
tomb slam all
enable_batman_daemon
create_ram_disk 1
setup_amnesic_data
change_avahi_name
if [ $ENABLE_ZERONET ]; then
configure_zeronet_blog
configure_zeronet_mail
configure_zeronet_forum
configure_zeronet_id
configure_zeronet
fi
2016-08-03 17:17:01 +02:00
configure_toxcore
create_tox_user
2016-08-31 00:25:17 +02:00
#setup_tahoelafs
2016-08-12 14:32:23 +02:00
setup_ipfs
2016-08-03 17:17:01 +02:00
mesh_amnesic
if [ ! -f $MESH_AMNESIC ]; then
rm $MESH_INSTALL_SETUP
systemctl disable mesh-setup.service
fi
show_desktop_icons
mesh_restart_daemons
if [ ! -f $MESH_INSTALL_COMPLETED ]; then
echo $'Mesh node setup complete' >> $INSTALL_LOG
touch $MESH_INSTALL_COMPLETED
if [ -d /home/$MY_USERNAME/Desktop ]; then
touch $FIRST_BOOT
chown ${MY_USERNAME}:${MY_USERNAME} $FIRST_BOOT
fi
# set the desktop background
if [ -d /home/$MY_USERNAME/Desktop ]; then
MESH_DESKTOP_BACKGROUND_IMAGE=/usr/local/share/${PROJECT_NAME}_mesh_background.png
cp $MESH_DESKTOP_BACKGROUND_IMAGE /usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png
rm /usr/share/images/desktop-base/desktop-background
ln -s /usr/share/images/desktop-base/${PROJECT_NAME}_mesh_background.png /usr/share/images/desktop-base/desktop-background
fi
reboot
2016-08-03 17:17:01 +02:00
fi
2016-01-11 12:27:08 +01:00
fi
2015-12-24 20:04:17 +01:00
exit 0