freedomboneeee/src/freedombone-app-tahoelafs

679 lines
23 KiB
Plaintext
Raw Normal View History

2016-08-28 00:40:21 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
2017-03-07 00:59:18 +01:00
# Tahow-LAFS data storage grid implemented via Tor
# https://k0rx.com/blog/2017/01/lafs.html
2017-03-04 00:25:38 +01:00
# http://tahoe-lafs.readthedocs.io/en/latest/anonymity-configuration.html
2016-08-28 00:40:21 +02:00
#
# License
# =======
#
# Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
2016-08-28 00:40:21 +02:00
#
# 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 <http://www.gnu.org/licenses/>.
2017-03-03 19:48:33 +01:00
VARIANTS='full full-vim cloud'
2016-08-28 00:40:21 +02:00
IN_DEFAULT_INSTALL=0
2017-03-07 01:02:05 +01:00
SHOW_ON_ABOUT=1
2017-03-10 00:33:41 +01:00
SHOW_ICANN_ADDRESS_ON_ABOUT=0
2016-08-28 00:40:21 +02:00
TAHOELAFS_PORT=50213
2017-03-07 00:59:18 +01:00
TAHOELAFS_STORAGE_PORT=50214
2017-03-04 00:25:38 +01:00
TAHOELAFS_ONION_PORT=8096
2017-03-07 00:59:18 +01:00
TAHOELAFS_STORAGE_ONION_PORT=8097
2017-03-03 19:56:32 +01:00
2017-06-10 13:08:06 +02:00
TAHOE_DIR=/home/tahoelafs
2017-06-10 14:00:01 +02:00
TAHOE_COMMAND='/usr/bin/tahoe'
2017-06-10 13:08:06 +02:00
tahoelafs_storage_file=$TAHOE_DIR/client/private/servers.yaml
2016-08-28 00:40:21 +02:00
2017-03-07 11:15:06 +01:00
TAHOELAFS_SHARES_NEEDED=3
TAHOELAFS_SHARES_HAPPY=7
TAHOELAFS_SHARES_TOTAL=10
2017-03-04 00:25:38 +01:00
tahoelafs_variables=(ONION_ONLY
2017-03-07 00:59:18 +01:00
MY_USERNAME
2017-03-07 11:15:06 +01:00
TAHOELAFS_PORT
TAHOELAFS_SHARES_NEEDED
TAHOELAFS_SHARES_HAPPY
TAHOELAFS_SHARES_TOTAL)
2016-10-05 23:33:41 +02:00
function add_user_tahoelafs {
if [[ $(app_is_installed tahoelafs) == "0" ]]; then
echo '0'
return
fi
new_username="$1"
new_user_password="$2"
${PROJECT_NAME}-pass -u $new_username -a tahoelafs -p "$new_user_password"
if grep "${new_username}:" /etc/nginx/.htpasswd-tahoelafs; then
sed -i '/${new_username}:/d' /etc/nginx/.htpasswd-tahoelafs
fi
echo "${new_user_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${new_username}
echo '0'
}
function remove_user_tahoelafs {
remove_username="$1"
${PROJECT_NAME}-pass -u $remove_username --rmapp tahoelafs
if grep "${remove_username}:" /etc/nginx/.htpasswd-tahoelafs; then
sed -i '/${remove_username}:/d' /etc/nginx/.htpasswd-tahoelafs
fi
}
function change_password_tahoelafs {
change_username="$1"
change_password="$2"
${PROJECT_NAME}-pass -u $change_username -a tahoelafs -p "$change_password"
if grep "${change_username}:" /etc/nginx/.htpasswd-tahoelafs; then
sed -i '/tahoe-${change_username}:/d' /etc/nginx/.htpasswd-tahoelafs
fi
echo "${change_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${change_username}
}
2017-03-07 00:59:18 +01:00
function add_tahoelafs_storage_node_interactive {
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Configuration" \
--title $"Add Tahoe-LAFS storage node" \
--form $"\nEnter the storage node details which can be found on the About screen of another server" 13 75 5 \
$"Hostname:" 1 1 "" 1 14 53 40 \
$"Public Key:" 2 1 "" 2 14 53 255 \
$"Nickname:" 3 1 "" 3 14 53 255 \
$"FURL:" 4 1 "" 4 14 53 255 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
storage_hostname=$(cat $data | sed -n 1p)
public_key="$(cat $data | sed -n 2p)"
nick=$(cat $data | sed -n 3p)
furl=$(cat $data | sed -n 4p)
if [ ${#public_key} -eq 0 ]; then
return
2017-03-04 00:25:38 +01:00
fi
2017-03-07 00:59:18 +01:00
add_tahoelafs_server "${storage_hostname}" "${public_key}" "${nick}" "${furl}"
2017-03-04 00:25:38 +01:00
2017-03-07 11:15:06 +01:00
if grep -q "$public_key" ${tahoelafs_storage_file}; then
2017-03-07 00:59:18 +01:00
dialog --title $"Add Tahoe-LAFS storage node" \
--msgbox $"Storage node added" 6 40
2017-03-04 00:25:38 +01:00
fi
2017-03-07 00:59:18 +01:00
}
2017-03-04 00:25:38 +01:00
2017-03-07 00:59:18 +01:00
function edit_tahoelafs_nodes {
editor $tahoelafs_storage_file
chown tahoelafs:debian-tor $tahoelafs_storage_file
systemctl restart tahoelafs-client
}
2017-03-04 00:25:38 +01:00
2017-03-07 11:15:06 +01:00
function edit_tahoelafs_shares {
read_config_param TAHOELAFS_SHARES_NEEDED
read_config_param TAHOELAFS_SHARES_HAPPY
read_config_param TAHOELAFS_SHARES_TOTAL
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Configuration" \
--title $"Tahoe-LAFS shares" \
--form $"\nEnter the storage node details which can be found on the About screen of another server" 13 40 3 \
$"Needed:" 1 1 "${TAHOELAFS_SHARES_NEEDED}" 1 14 4 4 \
$"Happy:" 2 1 "${TAHOELAFS_SHARES_HAPPY}" 2 14 4 4 \
$"Total:" 3 1 "${TAHOELAFS_SHARES_TOTAL}" 3 14 4 4 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
tl_needed="$(cat $data | sed -n 1p)"
tl_happy="$(cat $data | sed -n 2p)"
tl_total="$(cat $data | sed -n 3p)"
if [ ${#tl_needed} -gt 0 ]; then
TAHOELAFS_SHARES_NEEDED=${tl_needed}
fi
if [ ${#tl_happy} -gt 0 ]; then
TAHOELAFS_SHARES_HAPPY=${tl_happy}
fi
if [ ${#tl_total} -gt 0 ]; then
TAHOELAFS_SHARES_TOTAL=${tl_total}
fi
2017-06-10 13:08:06 +02:00
sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
2017-03-07 11:15:06 +01:00
2017-06-10 13:08:06 +02:00
sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
2017-03-07 11:15:06 +01:00
systemctl restart tahoelafs-storage
systemctl restart tahoelafs-client
dialog --title $"Tahoe-LAFS shares" \
--msgbox $"Shares settings changed" 6 40
}
2017-03-07 00:59:18 +01:00
function configure_interactive_tahoelafs {
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Configuration" \
--title $"Tahoe-LAFS" \
2017-03-09 19:01:35 +01:00
--radiolist $"The least authority is always the best" 11 50 5 \
2017-03-07 00:59:18 +01:00
1 "Add a storage node" off \
2 "Manually edit storage nodes" off \
2017-03-07 11:15:06 +01:00
3 "Shares settings" off \
4 "Back to main menu" on 2> $data
2017-03-07 00:59:18 +01:00
sel=$?
case $sel in
1) exit 1;;
255) exit 1;;
esac
case $(cat $data) in
1) add_tahoelafs_storage_node_interactive;;
2) edit_tahoelafs_nodes;;
2017-03-07 11:15:06 +01:00
3) edit_tahoelafs_shares;;
2017-03-07 00:59:18 +01:00
esac
}
function tahoelafs_setup_client_config {
config_file=$1
nick="$2"
echo '[node]' > $config_file
echo "nickname = $nick" >> $config_file
echo 'reveal-IP-address = false' >> $config_file
2017-03-07 11:32:24 +01:00
echo "web.port = tcp:${TAHOELAFS_PORT}:interface=127.0.0.1" >> $config_file
2017-03-07 00:59:18 +01:00
echo 'web.static = public_html' >> $config_file
echo 'tub.port = disabled' >> $config_file
echo 'tub.location = disabled' >> $config_file
echo '' >> $config_file
echo '[client]' >> $config_file
echo 'introducer.furl =' >> $config_file
2017-03-07 11:15:06 +01:00
echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
2017-03-07 00:59:18 +01:00
echo '' >> $config_file
echo '[storage]' >> $config_file
echo 'enabled = false' >> $config_file
echo 'reserved_space = 3G' >> $config_file
echo '' >> $config_file
echo '[helper]' >> $config_file
echo 'enabled = false' >> $config_file
echo '' >> $config_file
echo '[connections]' >> $config_file
echo 'tcp = tor' >> $config_file
}
function tahoelafs_setup_storage_config {
config_file=$1
nick="$2"
2017-03-04 00:25:38 +01:00
2017-03-07 00:59:18 +01:00
echo '[node]' > $config_file
echo "nickname = $nick" >> $config_file
echo 'reveal-IP-address = false' >> $config_file
echo 'web.port =' >> $config_file
echo 'web.static = public_html' >> $config_file
echo "tub.port = tcp:${TAHOELAFS_STORAGE_ONION_PORT}:interface=127.0.0.1" >> $config_file
echo "tub.location = tor:${TAHOELAFS_STORAGE_ONION_HOSTNAME}:${TAHOELAFS_STORAGE_PORT}" >> $config_file
echo '' >> $config_file
echo '[client]' >> $config_file
echo 'introducer.furl =' >> $config_file
echo 'helper.furl =' >> $config_file
echo '' >> $config_file
2017-03-07 11:15:06 +01:00
echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
2017-03-07 00:59:18 +01:00
echo '' >> $config_file
echo '[storage]' >> $config_file
echo 'enabled = true' >> $config_file
echo 'reserved_space = 3G' >> $config_file
echo 'expire.enabled = true' >> $config_file
echo 'expire.mode = age' >> $config_file
echo 'expire.override_lease_duration = 3 months' >> $config_file
echo '' >> $config_file
echo '[helper]' >> $config_file
echo 'enabled = false' >> $config_file
echo '' >> $config_file
echo '[connections]' >> $config_file
echo 'tcp = tor' >> $config_file
2017-03-04 00:25:38 +01:00
2017-06-10 13:08:06 +02:00
chown -R tahoelafs:debian-tor $TAHOE_DIR
2017-03-04 00:25:38 +01:00
}
function install_interactive_tahoelafs {
echo -n ''
APP_INSTALLED=1
}
2016-08-28 00:40:21 +02:00
function upgrade_tahoelafs {
2017-06-10 14:00:01 +02:00
echo -n ''
2016-08-28 00:40:21 +02:00
}
function backup_local_tahoelafs {
2017-06-10 13:08:06 +02:00
source_directory=$TAHOE_DIR
2016-08-29 12:04:37 +02:00
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
2016-08-28 00:40:21 +02:00
}
function restore_local_tahoelafs {
echo $"Restoring Tahoe-LAFS"
2017-03-05 20:49:18 +01:00
systemctl stop tahoelafs-storage
systemctl stop tahoelafs-client
2016-08-29 12:04:37 +02:00
temp_restore_dir=/root/temptahoelafs
restore_directory_from_usb $temp_restore_dir tahoelafs
2017-06-10 13:08:06 +02:00
mv $TAHOE_DIR ${TAHOE_DIR}-old
cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
2016-08-29 12:21:39 +02:00
if [ ! "$?" = "0" ]; then
2017-06-10 13:08:06 +02:00
mv ${TAHOE_DIR}-old $TAHOE_DIR
2016-08-29 12:21:39 +02:00
exit 246833
fi
2017-06-10 13:08:06 +02:00
rm -rf ${TAHOE_DIR}-old
chown -R tahoelafs:debian-tor $TAHOE_DIR
systemctl start tahoelafs-client
2017-03-05 20:49:18 +01:00
systemctl start tahoelafs-storage
2016-08-29 12:21:39 +02:00
echo $"Restore complete"
2016-08-28 00:40:21 +02:00
}
function backup_remote_tahoelafs {
2017-06-10 13:08:06 +02:00
source_directory=$TAHOE_DIR
2016-08-29 12:21:39 +02:00
if [ ! -d $source_directory ]; then
return
fi
2017-03-05 20:49:18 +01:00
systemctl stop tahoelafs-storage
systemctl stop tahoelafs-client
2016-08-29 12:21:39 +02:00
dest_directory=tahoelafs
function_check backup_directory_to_usb
backup_directory_to_friend $source_directory $dest_directory
systemctl start tahoelafs-client
2017-03-05 20:49:18 +01:00
systemctl start tahoelafs-storage
2016-08-28 00:40:21 +02:00
}
function restore_remote_tahoelafs {
echo $"Restoring Tahoe-LAFS"
2017-03-05 20:49:18 +01:00
systemctl stop tahoelafs-storage
systemctl stop tahoelafs-client
2016-08-29 12:21:39 +02:00
temp_restore_dir=/root/temptahoelafs
restore_directory_from_friend $temp_restore_dir tahoelafs
2017-06-10 13:08:06 +02:00
mv $TAHOE_DIR ${TAHOE_DIR}-old
cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
2016-08-29 12:21:39 +02:00
if [ ! "$?" = "0" ]; then
2017-06-10 13:08:06 +02:00
mv ${TAHOE_DIR}old $TAHOE_DIR
2016-08-29 12:21:39 +02:00
exit 623925
fi
2017-06-10 13:08:06 +02:00
rm -rf ${$TAHOE_DIR}-old
chown -R tahoelafs:debian-tor $TAHOE_DIR
systemctl start tahoelafs-client
2017-03-05 20:49:18 +01:00
systemctl start tahoelafs-storage
2016-08-29 12:21:39 +02:00
echo $"Restore complete"
2016-08-28 00:40:21 +02:00
}
2017-03-04 00:30:55 +01:00
function reconfigure_tahoelafs {
2017-03-07 00:59:18 +01:00
if [ -f $tahoelafs_storage_file ]; then
shred -zu $tahoelafs_storage_file
fi
sed -i '/HidServAuth /d' /etc/tor/torrc
2017-03-04 00:30:55 +01:00
}
2016-08-28 00:40:21 +02:00
function remove_tahoelafs {
2017-03-05 13:09:45 +01:00
if [ -f /etc/nginx/sites-available/tahoelafs ]; then
nginx_dissite tahoelafs
rm /etc/nginx/sites-available/tahoelafs
if [ -d /var/www/tahoelafs ]; then
rm -rf /var/www/tahoelafs
fi
systemctl reload nginx
fi
2017-03-05 20:49:18 +01:00
systemctl stop tahoelafs-storage
systemctl disable tahoelafs-storage
2017-03-08 18:26:37 +01:00
rm /etc/systemd/system/tahoelafs-storage.service
2017-03-04 18:52:15 +01:00
2017-03-07 00:59:18 +01:00
systemctl stop tahoelafs-client
systemctl disable tahoelafs-client
2017-03-08 18:26:37 +01:00
rm /etc/systemd/system/tahoelafs-client.service
2017-03-05 20:49:18 +01:00
2017-06-10 14:17:25 +02:00
pip uninstall tahoe-lafs[tor]
2017-06-10 14:00:01 +02:00
apt-get -yq remove tahoe-lafs
2017-03-07 00:59:18 +01:00
if [ -d /var/lib/tahoelafs ]; then
rm -rf /var/lib/tahoelafs
fi
2016-10-17 15:44:49 +02:00
remove_completion_param install_tahoelafs
2017-03-04 00:25:38 +01:00
function_check remove_onion_service
remove_onion_service tahoelafs ${TAHOELAFS_ONION_PORT}
2017-03-07 16:12:34 +01:00
remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} $(get_tahoelafs_nick)
2017-03-07 00:59:18 +01:00
sed -i '/HidServAuth /d' /etc/tor/torrc
2017-03-04 00:25:38 +01:00
deluser tahoelafs
2017-06-10 13:08:06 +02:00
if [ -d $TAHOE_DIR ]; then
rm -rf $TAHOE_DIR
2017-03-04 18:52:15 +01:00
fi
2017-03-04 00:28:52 +01:00
remove_app tahoelafs
if [ -f /etc/nginx/.htpasswd-tahoelafs ]; then
shred -zu /etc/nginx/.htpasswd-tahoelafs
fi
systemctl restart tor
2016-08-28 00:40:21 +02:00
}
2017-03-07 00:59:18 +01:00
function create_tahoelafs_stealth_node {
node_dir="$1"
client_dir="$2"
node_nick="$3"
client_nick="$4"
if [ ${#node_dir} -eq 0 ]; then
echo $'No tahoe-LAFS storage node directory given'
exit 783522
fi
if [ ${#client_dir} -eq 0 ]; then
echo $'No tahoe-LAFS client directory given'
exit 368935
fi
if [ ${#node_nick} -eq 0 ]; then
echo $'No tahoe-LAFS node nick given'
exit 672351
fi
if [ ${#client_nick} -eq 0 ]; then
echo $'No tahoe-LAFS client nick given'
exit 682362
fi
if [ ! -f ${node_dir}/tahoe.cfg ]; then
su -c "mkdir ${node_dir}" - tahoelafs
su -c "$TAHOE_COMMAND create-node -C ${node_dir} --hostname=fixme" - tahoelafs
tahoelafs_setup_storage_config ${node_dir}/tahoe.cfg ${node_nick}
fi
if [ ! -f ${client_dir}/tahoe.cfg ]; then
su -c "mkdir ${client_dir}" - tahoelafs
su -c "$TAHOE_COMMAND create-client -C ${client_dir}" - tahoelafs
tahoelafs_setup_client_config ${client_dir}/tahoe.cfg ${client_nick}
fi
}
2017-03-05 20:49:18 +01:00
function create_tahoelafs_introducer {
introducer_dir="$1"
2017-03-05 21:38:37 +01:00
if [ -f ${introducer_dir}/tahoe.cfg ]; then
2017-03-05 20:49:18 +01:00
return
fi
2017-03-05 21:46:53 +01:00
su -c "mkdir ${introducer_dir}" - tahoelafs
2017-03-05 20:49:18 +01:00
su -c "$TAHOE_COMMAND create-introducer -C ${introducer_dir} --hide-ip --hostname=127.0.0.1" - tahoelafs
}
2017-03-05 14:07:45 +01:00
2017-03-05 20:49:18 +01:00
function create_tahoelafs_storage_node {
# Nodes can store data
2017-03-05 20:49:18 +01:00
node_dir="$1"
furl="$2"
if [ ${#furl} -eq 0 ]; then
return
2017-03-05 14:07:45 +01:00
fi
2017-03-05 20:49:18 +01:00
2017-03-05 21:38:37 +01:00
if [ -f ${node_dir}/tahoe.cfg ]; then
2017-03-05 20:49:18 +01:00
return
fi
2017-03-05 21:46:53 +01:00
su -c "mkdir ${node_dir}" - tahoelafs
2017-03-05 22:23:14 +01:00
su -c "$TAHOE_COMMAND create-node -C ${node_dir} --introducer=\"$furl\" --listen=tor --hide-ip" - tahoelafs
2017-03-05 20:49:18 +01:00
}
function create_tahoelafs_client {
# Clients have no storage
client_dir="$1"
furl="$2"
if [ ${#furl} -eq 0 ]; then
return
fi
2017-03-05 21:38:37 +01:00
if [ -f ${client_dir}/tahoe.cfg ]; then
2017-03-05 20:49:18 +01:00
return
fi
2017-03-05 21:46:53 +01:00
su -c "mkdir ${client_dir}" - tahoelafs
2017-03-05 20:49:18 +01:00
su -c "$TAHOE_COMMAND create-client -C ${client_dir} --introducer=\"$furl\" --listen=tor --hide-ip --hostname=127.0.0.1" - tahoelafs
sed -i 's|reveal-IP-address =.*|reveal-IP-address = False|g' $client_dir/tahoe.cfg
sed -i 's|tub.port =.*|tub.port = disabled|g' $client_dir/tahoe.cfg
sed -i 's|tub.location =.*|tub.location = disabled|g' $client_dir/tahoe.cfg
}
2017-03-07 00:59:18 +01:00
function get_tahoelafs_furl {
2017-06-10 13:08:06 +02:00
furl=$(cat $TAHOE_DIR/storage/private/storage.furl)
2017-03-08 19:45:40 +01:00
furl_1=$(echo "${furl}" | awk -F ' ' '{print $1}')
furl_2=$(echo "${furl}" | awk -F ':' '{print $5}')
2017-03-08 19:41:24 +01:00
echo "${furl_1}:${furl_2}"
2017-03-07 00:59:18 +01:00
}
function get_tahoelafs_nick {
echo "${MY_USERNAME}-node"
}
function get_tahoelafs_storage_hostname {
2017-03-07 16:20:25 +01:00
echo "$(cat /var/lib/tor/hidden_service_storage-tahoelafs/hostname)"
2017-03-07 00:59:18 +01:00
}
function get_tahoelafs_public_key {
2017-06-10 13:08:06 +02:00
echo "$(cat $TAHOE_DIR/storage/node.pubkey | grep 'v0-' | sed 's|pub-||g')"
2017-03-07 00:59:18 +01:00
}
function add_tahoelafs_server {
storage_hostname="$1"
public_key="$2"
nick="$3"
furl="$4"
if [ ${#storage_hostname} -eq 0 ]; then
2017-03-07 16:16:45 +01:00
echo $'No storage hostname'
2017-03-07 00:59:18 +01:00
return
fi
if [ ${#public_key} -eq 0 ]; then
2017-03-07 16:16:45 +01:00
echo $'No public key'
2017-03-07 00:59:18 +01:00
return
fi
if [ ${#nick} -eq 0 ]; then
2017-03-07 16:16:45 +01:00
echo $'No nick'
2017-03-07 00:59:18 +01:00
return
fi
if [ ${#furl} -eq 0 ]; then
2017-03-07 16:16:45 +01:00
echo $'No furl'
2017-03-07 00:59:18 +01:00
return
fi
2017-03-07 15:48:18 +01:00
if [ ! -f ${tahoelafs_storage_file} ]; then
echo 'storage:' > ${tahoelafs_storage_file}
2017-03-07 00:59:18 +01:00
else
2017-03-07 15:48:18 +01:00
if grep -q "${public_key}" ${tahoelafs_storage_file}; then
2017-03-07 16:16:45 +01:00
echo $'Public key already exists'
2017-03-07 15:48:18 +01:00
return
fi
echo '# storage' >> ${tahoelafs_storage_file}
2017-03-07 00:59:18 +01:00
fi
2017-03-07 17:22:54 +01:00
echo " ${public_key}:" >> ${tahoelafs_storage_file}
2017-03-07 15:48:18 +01:00
echo " ann:" >> ${tahoelafs_storage_file}
echo " nickname: ${nick}" >> ${tahoelafs_storage_file}
echo " anonymous-storage-FURL: ${furl}" >> ${tahoelafs_storage_file}
chown tahoelafs:debian-tor ${tahoelafs_storage_file}
2017-03-07 00:59:18 +01:00
if ! grep -q "HidServAuth ${storage_hostname}" /etc/tor/torrc; then
echo "HidServAuth ${storage_hostname}" >> /etc/tor/torrc
fi
2017-03-05 20:49:18 +01:00
}
function create_tahoelafs_daemon {
daemon_name=$1
2017-03-05 22:11:15 +01:00
TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs-${daemon_name}.service
2017-03-05 22:05:03 +01:00
echo "Creating daemon: $TAHOELAFS_DAEMON_FILE"
2017-03-05 20:49:18 +01:00
echo '[Unit]' > $TAHOELAFS_DAEMON_FILE
echo "Description=Tahoe-LAFS ${daemon_name}" >> $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
2017-03-05 22:09:38 +01:00
echo "Group=debian-tor" >> $TAHOELAFS_DAEMON_FILE
2017-06-10 13:08:06 +02:00
echo "WorkingDirectory=${TAHOE_DIR}/tahoelafs" >> $TAHOELAFS_DAEMON_FILE
echo "ExecStart=${TAHOE_DIR}/tahoelafs/venv/bin/tahoe run ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
echo "ExecStop=${TAHOE_DIR}/tahoelafs/venv/bin/tahoe stop ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
2017-03-05 20:49:18 +01:00
echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE
echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE
2017-06-10 13:08:06 +02:00
echo "Environment=\"USER=tahoelafs\" \"HOME=${TAHOE_DIR}\"" >> $TAHOELAFS_DAEMON_FILE
2017-03-05 20:49:18 +01:00
echo '' >> $TAHOELAFS_DAEMON_FILE
echo '[Install]' >> $TAHOELAFS_DAEMON_FILE
echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE
systemctl enable tahoelafs-${daemon_name}
systemctl daemon-reload
systemctl start tahoelafs-${daemon_name}
2017-03-05 14:07:45 +01:00
}
2017-03-07 00:59:18 +01:00
function create_tahoelafs_web {
if [ ! -d /var/www/tahoelafs/htdocs ]; then
mkdir -p /var/www/tahoelafs/htdocs
fi
2017-03-08 18:33:06 +01:00
TAHOELAFS_LOGIN_TEXT=$'Tahoe-LAFS login'
2017-03-07 00:59:18 +01:00
tahoelafs_nginx_site=/etc/nginx/sites-available/tahoelafs
echo 'server {' > $tahoelafs_nginx_site
echo " listen 127.0.0.1:$TAHOELAFS_ONION_PORT default_server;" >> $tahoelafs_nginx_site
echo " server_name $TAHOELAFS_ONION_HOSTNAME;" >> $tahoelafs_nginx_site
echo '' >> $tahoelafs_nginx_site
function_check nginx_disable_sniffing
nginx_disable_sniffing tahoelafs
echo '' >> $tahoelafs_nginx_site
echo ' # Logs' >> $tahoelafs_nginx_site
echo ' access_log /dev/null;' >> $tahoelafs_nginx_site
echo ' error_log /dev/null;' >> $tahoelafs_nginx_site
echo '' >> $tahoelafs_nginx_site
echo ' # Root' >> $tahoelafs_nginx_site
echo " root /var/www/tahoelafs/htdocs;" >> $tahoelafs_nginx_site
echo '' >> $tahoelafs_nginx_site
echo ' location / {' >> $tahoelafs_nginx_site
echo " auth_basic \"${TAHOELAFS_LOGIN_TEXT}\";" >> $tahoelafs_nginx_site
echo ' auth_basic_user_file /etc/nginx/.htpasswd-tahoelafs;' >> $tahoelafs_nginx_site
2017-03-07 00:59:18 +01:00
function_check nginx_limits
nginx_limits tahoelafs '15m'
echo ' rewrite /(.*) /$1 break;' >> $tahoelafs_nginx_site
echo ' proxy_set_header X-Real-IP $remote_addr;' >> $tahoelafs_nginx_site
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $tahoelafs_nginx_site
echo ' proxy_set_header Host $http_host;' >> $tahoelafs_nginx_site
echo ' proxy_set_header X-NginX-Proxy true;' >> $tahoelafs_nginx_site
echo " proxy_pass http://localhost:${TAHOELAFS_PORT};" >> $tahoelafs_nginx_site
echo ' proxy_redirect off;' >> $tahoelafs_nginx_site
echo ' }' >> $tahoelafs_nginx_site
echo '}' >> $tahoelafs_nginx_site
TAHOELAFS_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
${PROJECT_NAME}-pass -u $MY_USERNAME -a tahoelafs -p "$TAHOELAFS_ADMIN_PASSWORD"
if [ ! -f /etc/nginx/.htpasswd-tahoelafs ]; then
touch /etc/nginx/.htpasswd-tahoelafs
fi
if grep "${MY_USERNAME}:" /etc/nginx/.htpasswd-tahoelafs; then
sed -i '/${MY_USERNAME}:/d' /etc/nginx/.htpasswd-tahoelafs
fi
echo "${TAHOELAFS_ADMIN_PASSWORD}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${MY_USERNAME}
2017-03-07 00:59:18 +01:00
function_check nginx_ensite
nginx_ensite tahoelafs
systemctl reload nginx
}
2016-08-28 00:40:21 +02:00
function install_tahoelafs {
if [ $INSTALLING_MESH ]; then
return
fi
2017-03-04 18:49:44 +01:00
apt-get -yq install build-essential python-pip python-dev libffi-dev libssl-dev
2017-03-04 19:18:07 +01:00
apt-get -yq install libcrypto++-dev python-pycryptopp python-cffi python-virtualenv
2017-06-10 14:00:01 +02:00
apt-get -yq install tahoe-lafs
2017-06-10 14:17:25 +02:00
pip install tahoe-lafs[tor]
# create a user
2017-06-10 13:08:06 +02:00
if [ ! -d $TAHOE_DIR ]; then
# add a gogs user account
adduser --disabled-login --gecos 'tahoe-lafs' tahoelafs
2017-03-05 15:01:44 +01:00
adduser tahoelafs debian-tor
fi
2017-06-10 13:08:06 +02:00
if [ -d $TAHOE_DIR/Maildir ]; then
rm -rf $TAHOE_DIR/Maildir
fi
2017-03-04 21:45:19 +01:00
# remove files we don't need
2017-06-10 13:08:06 +02:00
rm -rf $TAHOE_DIR/.mutt
rm $TAHOE_DIR/.emacs-mutt
rm $TAHOE_DIR/.muttrc
rm $TAHOE_DIR/.mutt-alias
rm $TAHOE_DIR/.procmailrc
2017-03-04 21:45:19 +01:00
# set permissions
2017-06-10 13:08:06 +02:00
chown -R tahoelafs:debian-tor $TAHOE_DIR
2017-03-04 21:45:19 +01:00
2017-03-07 00:59:18 +01:00
node_nick=$(get_tahoelafs_nick)
client_nick=${MY_USERNAME}-client
2017-03-07 00:59:18 +01:00
# create an onion address for storage node
TAHOELAFS_STORAGE_ONION_HOSTNAME=$(add_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_PORT} ${TAHOELAFS_STORAGE_ONION_PORT} ${node_nick})
2017-03-07 00:59:18 +01:00
# create an onion address for client node
2017-03-08 17:09:34 +01:00
TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs 80 ${TAHOELAFS_ONION_PORT})
2017-06-10 13:08:06 +02:00
create_tahoelafs_stealth_node $TAHOE_DIR/storage $TAHOE_DIR/client ${node_nick} ${client_nick}
2017-03-05 15:01:44 +01:00
# start the storage node
2017-06-10 14:00:01 +02:00
su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/storage" - tahoelafs
create_tahoelafs_daemon "storage"
2017-03-07 16:50:14 +01:00
# start the client
2017-06-10 14:00:01 +02:00
su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/client" - tahoelafs
2017-03-07 00:59:18 +01:00
add_tahoelafs_server "$(get_tahoelafs_storage_hostname)" "$(get_tahoelafs_public_key)" "${node_nick}" "$(get_tahoelafs_furl)"
2017-03-07 15:48:18 +01:00
if ! grep -q "HidServAuth $(get_tahoelafs_storage_hostname)" /etc/tor/torrc; then
echo $'Unable to create tahoelafs server'
exit 738752
fi
2017-03-07 15:59:17 +01:00
if [ ! -f ${tahoelafs_storage_file} ]; then
echo $'tahoelafs server file missing'
exit 529362
fi
2017-03-07 00:59:18 +01:00
create_tahoelafs_daemon "client"
set_completion_param "tahoelafs onion domain" "$TAHOELAFS_ONION_HOSTNAME"
2017-03-05 13:09:45 +01:00
2017-03-07 00:59:18 +01:00
create_tahoelafs_web
2017-03-08 18:52:03 +01:00
systemctl restart tor
APP_INSTALLED=1
2016-08-28 00:40:21 +02:00
}
# NOTE: deliberately no exit 0