#!/bin/bash # # .---. . . # | | | # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-' # ' ' --' --' -' - -' ' ' -' -' -' ' - --' # # Freedom in the Cloud # # Distributed storage system introducer # http://tahoe-lafs.readthedocs.io/en/latest/anonymity-configuration.html # # License # ======= # # Copyright (C) 2014-2016 Bob Mottram # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # 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 # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . VARIANTS='full full-vim cloud' IN_DEFAULT_INSTALL=0 SHOW_ON_ABOUT=1 TAHOELAFS_REPO="https://github.com/tahoe-lafs/tahoe-lafs" TAHOELAFS_COMMIT='bb782b0331a60de438136a593bba18338d8d866b' TAHOELAFS_PORT=50213 TAHOELAFS_ONION_PORT=8096 TAHOELAFS_SHARED_DIR='Shared' TAHOE_COMMAND="cd /var/lib/tahoelafs && venv/bin/tahoe" tahoelafs_variables=(ONION_ONLY TAHOELAFS_REPO TAHOELAFS_PORT) function tahoelafs_setup_config { config_file=$1 if ! grep -q "[node]" $config_file; then echo '' >> $config_file echo '[node]' >> $config_file fi if ! grep -q "[connections]" $config_file; then echo '' >> $config_file echo '[connections]' >> $config_file fi if ! grep -q "reveal-IP-address" $config_file; then sed -i '/[node]/a reveal-IP-address = False' $config_file else sed -i 's|reveal-IP-address.*|reveal-IP-address = False|g' >> $config_file fi if ! grep -q "tcp =" $config_file; then sed -i '/[connections]/a tcp = tor' $config_file else sed -i 's|tcp =.*|tcp = tor|g' >> $config_file fi if ! grep -q "tub.location =" $config_file; then sed -i '/[node]/a tub.location = disabled' >> $config_file fi if ! grep -q "tub.port =" $config_file; then sed -i "/[node]/a tub.port = tcp:${TAHOELAFS_ONION_PORT}:interface=127.0.0.1" >> $config_file fi sed -i "s|tub.port.*|tub.port = tcp:${TAHOELAFS_ONION_PORT}:interface=127.0.0.1|g" >> $config_file sed -i "s|tub.location.*|tub.location = tor:${TAHOELAFS_ONION_HOSTNAME}:${TAHOELAFS_PORT}|g" >> $config_file sed -i "s|nickname =.*|nickname = $HOSTNAME|g" $config_file if ! grep -q "[storage]" $config_file; then echo '' >> $config_file echo '[storage]' >> $config_file echo 'enabled = false' >> $config_file fi } function install_interactive_tahoelafs { echo -n '' APP_INSTALLED=1 } function upgrade_tahoelafs { systemctl stop tahoelafs function_check set_repo_commit set_repo_commit /home/tahoelafs/tahoelafs "tahoelafs commit" "$TAHOELAFS_COMMIT" $TAHOELAFS_REPO cd /home/tahoelafs/tahoelafs git submodule update --init --recursive virtualenv venv venv/bin/pip install --editable . chown -R tahoelafs:tahoelafs /home/tahoelafs systemctl start tahoelafs } function backup_local_tahoelafs { source_directory=/home/tahoelafs/.tahoe-introducer if [ ! -d $source_directory ]; then return fi systemctl stop tahoelafs dest_directory=tahoelafs function_check backup_directory_to_usb backup_directory_to_usb $source_directory $dest_directory systemctl start tahoelafs } function restore_local_tahoelafs { echo $"Restoring Tahoe-LAFS introducer" systemctl stop tahoelafs temp_restore_dir=/root/temptahoelafs restore_directory_from_usb $temp_restore_dir tahoelafs mv /home/tahoelafs/.tahoe-introducer /home/tahoelafs/.tahoe-introducer-old cp -r $temp_restore_dir/home/tahoelafs/.tahoe-introducer /home/tahoelafs/ if [ ! "$?" = "0" ]; then mv /home/tahoelafs/.tahoe-introducer-old /home/tahoelafs/.tahoe-introducer exit 246833 fi rm -rf /home/tahoelafs/.tahoe-introducer chown -R tahoelafs:tahoelafs /home/tahoelafs systemctl start tahoelafs echo $"Restore complete" } function backup_remote_tahoelafs { source_directory=/home/tahoelafs/.tahoe-introducer if [ ! -d $source_directory ]; then return fi systemctl stop tahoelafs dest_directory=tahoelafs function_check backup_directory_to_usb backup_directory_to_friend $source_directory $dest_directory systemctl start tahoelafs } function restore_remote_tahoelafs { echo $"Restoring Tahoe-LAFS introducer" systemctl stop tahoelafs temp_restore_dir=/root/temptahoelafs restore_directory_from_friend $temp_restore_dir tahoelafs mv /home/tahoelafs/.tahoe-introducer /home/tahoelafs/.tahoe-introducer-old cp -r $temp_restore_dir/home/tahoelafs/.tahoe-introducer /home/tahoelafs/ if [ ! "$?" = "0" ]; then mv /home/tahoelafs/.tahoe-introducer-old /home/tahoelafs/.tahoe-introducer exit 623925 fi rm -rf /home/tahoelafs/.tahoe-introducer-old chown -R tahoelafs:tahoelafs /home/tahoelafs systemctl start tahoelafs echo $"Restore complete" } function reconfigure_tahoelafs { echo -n '' } function remove_tahoelafs { firewall_remove ${TAHOELAFS_PORT} rm -rf /var/lib/tahoelafs remove_completion_param install_tahoelafs remove_completion_param configure_firewall_for_tahoelafs function_check remove_onion_service remove_onion_service tahoelafs ${TAHOELAFS_ONION_PORT} deluser tahoelafs remove_app tahoelafs } function configure_firewall_for_tahoelafs { if [[ $(is_completed $FUNCNAME) == "1" ]]; then return fi firewall_add Tahoe-LAFS ${TAHOELAFS_PORT} mark_completed $FUNCNAME } function install_tahoelafs { if [ $INSTALLING_MESH ]; then return fi apt-get -yq install build-essential python-pip python-dev libffi-dev libssl-dev apt-get -yq install libcrypto++-dev python-virtualenv # create a user to run the introducer if [ ! -d /home/tahoelafs ]; then # add a gogs user account adduser --disabled-login --gecos 'tahoe-lafs' tahoelafs fi if [ -d /home/tahoelafs/Maildir ]; then rm -rf /home/tahoelafs/Maildir fi if [ ! -d /home/tahoelafs/.tahoe-introducer ]; then mkdir /home/tahoelafs/.tahoe-introducer fi git_clone $TAHOELAFS_REPO /home/tahoelafs/tahoelafs cd /home/tahoelafs/tahoelafs git checkout $TAHOELAFS_COMMIT -b $TAHOELAFS_COMMIT git submodule update --init --recursive virtualenv venv venv/bin/pip install six packaging appdirs pycrypto==2.1.0 venv/bin/pip install --editable . configure_firewall_for_tahoelafs su -c "cd $TAHOE_COMMAND create-introducer /home/tahoelafs/.tahoe-introducer" - tahoelafs TAHOELAFS_CONFIG=/home/tahoelafs/.tahoe-introducer/tahoe.cfg if [ ! -f $TAHOELAFS_CONFIG ]; then exit 62831 fi TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs ${TAHOELAFS_PORT} ${TAHOELAFS_ONION_PORT}) tahoelafs_setup_config $TAHOELAFS_CONFIG chown -R tahoelafs:tahoelafs /home/tahoelafs TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs.service echo '[Unit]' > $TAHOELAFS_DAEMON_FILE echo 'Description=Tahoe-LAFS introducer' >> $TAHOELAFS_DAEMON_FILE echo 'After=syslog.target' >> $TAHOELAFS_DAEMON_FILE echo 'After=network.target' >> $TAHOELAFS_DAEMON_FILE echo '' >> $TAHOELAFS_DAEMON_FILE echo '[Service]' >> $TAHOELAFS_DAEMON_FILE echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE echo "Group=tahoelafs" >> $TAHOELAFS_DAEMON_FILE echo "WorkingDirectory=/home/tahoelafs" >> $TAHOELAFS_DAEMON_FILE echo "ExecStart=venv/bin/tahoe start /home/tahoelafs/.tahoe-introducer" >> $TAHOELAFS_DAEMON_FILE echo "ExecStop=venv/bin/tahoe stop /home/tahoelafs/.tahoe-introducer" >> $TAHOELAFS_DAEMON_FILE echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE echo "Environment=\"USER=tahoelafs\" \"HOME=/home/tahoelafs\"" >> $TAHOELAFS_DAEMON_FILE echo '' >> $TAHOELAFS_DAEMON_FILE echo '[Install]' >> $TAHOELAFS_DAEMON_FILE echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE systemctl enable tahoelafs systemctl daemon-reload systemctl start tahoelafs set_completion_param "tahoelafs commit" "$TAHOELAFS_COMMIT" APP_INSTALLED=1 } # NOTE: deliberately no exit 0