tahoelafs directory

This commit is contained in:
Bob Mottram 2017-06-10 12:08:06 +01:00
parent b550080965
commit e543d160fa
1 changed files with 60 additions and 49 deletions

View File

@ -44,8 +44,9 @@ TAHOELAFS_STORAGE_PORT=50214
TAHOELAFS_ONION_PORT=8096 TAHOELAFS_ONION_PORT=8096
TAHOELAFS_STORAGE_ONION_PORT=8097 TAHOELAFS_STORAGE_ONION_PORT=8097
TAHOE_COMMAND="cd /home/tahoelafs/tahoelafs && venv/bin/tahoe" TAHOE_DIR=/home/tahoelafs
tahoelafs_storage_file=/home/tahoelafs/client/private/servers.yaml TAHOE_COMMAND="cd $TAHOE_DIR/tahoelafs && venv/bin/tahoe"
tahoelafs_storage_file=$TAHOE_DIR/client/private/servers.yaml
TAHOELAFS_SHARES_NEEDED=3 TAHOELAFS_SHARES_NEEDED=3
TAHOELAFS_SHARES_HAPPY=7 TAHOELAFS_SHARES_HAPPY=7
@ -164,13 +165,13 @@ function edit_tahoelafs_shares {
TAHOELAFS_SHARES_TOTAL=${tl_total} TAHOELAFS_SHARES_TOTAL=${tl_total}
fi fi
sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg 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" /home/tahoelafs/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" /home/tahoelafs/tahoelafs/client/tahoe.cfg sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg 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" /home/tahoelafs/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" /home/tahoelafs/tahoelafs/storage/tahoe.cfg sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
systemctl restart tahoelafs-storage systemctl restart tahoelafs-storage
systemctl restart tahoelafs-client systemctl restart tahoelafs-client
@ -263,7 +264,7 @@ function tahoelafs_setup_storage_config {
echo '[connections]' >> $config_file echo '[connections]' >> $config_file
echo 'tcp = tor' >> $config_file echo 'tcp = tor' >> $config_file
chown -R tahoelafs:debian-tor /home/tahoelafs chown -R tahoelafs:debian-tor $TAHOE_DIR
} }
function install_interactive_tahoelafs { function install_interactive_tahoelafs {
@ -272,22 +273,22 @@ function install_interactive_tahoelafs {
} }
function upgrade_tahoelafs { function upgrade_tahoelafs {
if [ ! -d /home/tahoelafs/tahoelafs ]; then if [ ! -d $TAHOE_DIR/tahoelafs ]; then
return return
fi fi
systemctl stop tahoelafs systemctl stop tahoelafs
function_check set_repo_commit function_check set_repo_commit
set_repo_commit /home/tahoelafs/tahoelafs "tahoelafs commit" "$TAHOELAFS_COMMIT" $TAHOELAFS_REPO set_repo_commit $TAHOE_DIR/tahoelafs "tahoelafs commit" "$TAHOELAFS_COMMIT" $TAHOELAFS_REPO
cd /home/tahoelafs/tahoelafs cd $TAHOE_DIR/tahoelafs
git submodule update --init --recursive git submodule update --init --recursive
virtualenv venv virtualenv venv
venv/bin/pip install --editable . venv/bin/pip install --editable .
chown -R tahoelafs:debian-tor /home/tahoelafs chown -R tahoelafs:debian-tor $TAHOE_DIR
systemctl start tahoelafs systemctl start tahoelafs
} }
function backup_local_tahoelafs { function backup_local_tahoelafs {
source_directory=/home/tahoelafs source_directory=$TAHOE_DIR
if [ ! -d $source_directory ]; then if [ ! -d $source_directory ]; then
return return
fi fi
@ -304,21 +305,21 @@ function restore_local_tahoelafs {
systemctl stop tahoelafs-client systemctl stop tahoelafs-client
temp_restore_dir=/root/temptahoelafs temp_restore_dir=/root/temptahoelafs
restore_directory_from_usb $temp_restore_dir tahoelafs restore_directory_from_usb $temp_restore_dir tahoelafs
mv /home/tahoelafs /home/tahoelafs-old mv $TAHOE_DIR ${TAHOE_DIR}-old
cp -r $temp_restore_dir/home/tahoelafs /home/tahoelafs cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
mv /home/tahoelafs-old /home/tahoelafs mv ${TAHOE_DIR}-old $TAHOE_DIR
exit 246833 exit 246833
fi fi
rm -rf /home/tahoelafs-old rm -rf ${TAHOE_DIR}-old
chown -R tahoelafs:debian-tor /home/tahoelafs chown -R tahoelafs:debian-tor $TAHOE_DIR
systemctl start tahoelafs-client systemctl start tahoelafs-client
systemctl start tahoelafs-storage systemctl start tahoelafs-storage
echo $"Restore complete" echo $"Restore complete"
} }
function backup_remote_tahoelafs { function backup_remote_tahoelafs {
source_directory=/home/tahoelafs source_directory=$TAHOE_DIR
if [ ! -d $source_directory ]; then if [ ! -d $source_directory ]; then
return return
fi fi
@ -337,14 +338,14 @@ function restore_remote_tahoelafs {
systemctl stop tahoelafs-client systemctl stop tahoelafs-client
temp_restore_dir=/root/temptahoelafs temp_restore_dir=/root/temptahoelafs
restore_directory_from_friend $temp_restore_dir tahoelafs restore_directory_from_friend $temp_restore_dir tahoelafs
mv /home/tahoelafs /home/tahoelafs-old mv $TAHOE_DIR ${TAHOE_DIR}-old
cp -r $temp_restore_dir/home/tahoelafs /home/tahoelafs cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
mv /home/tahoelafs-old /home/tahoelafs mv ${TAHOE_DIR}old $TAHOE_DIR
exit 623925 exit 623925
fi fi
rm -rf /home/tahoelafs-old rm -rf ${$TAHOE_DIR}-old
chown -R tahoelafs:debian-tor /home/tahoelafs chown -R tahoelafs:debian-tor $TAHOE_DIR
systemctl start tahoelafs-client systemctl start tahoelafs-client
systemctl start tahoelafs-storage systemctl start tahoelafs-storage
echo $"Restore complete" echo $"Restore complete"
@ -384,8 +385,8 @@ function remove_tahoelafs {
remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} $(get_tahoelafs_nick) remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} $(get_tahoelafs_nick)
sed -i '/HidServAuth /d' /etc/tor/torrc sed -i '/HidServAuth /d' /etc/tor/torrc
deluser tahoelafs deluser tahoelafs
if [ -d /home/tahoelafs ]; then if [ -d $TAHOE_DIR ]; then
rm -rf /home/tahoelafs rm -rf $TAHOE_DIR
fi fi
remove_app tahoelafs remove_app tahoelafs
if [ -f /etc/nginx/.htpasswd-tahoelafs ]; then if [ -f /etc/nginx/.htpasswd-tahoelafs ]; then
@ -398,15 +399,25 @@ function remove_tahoelafs {
function install_tahoelafs_to_directory { function install_tahoelafs_to_directory {
tahoe_dir=$1 tahoe_dir=$1
apt-get -yq install build-essential autoconf python-dev
git_clone $TAHOELAFS_REPO $tahoe_dir git_clone $TAHOELAFS_REPO $tahoe_dir
cd $tahoe_dir cd $tahoe_dir
git checkout $TAHOELAFS_COMMIT -b $TAHOELAFS_COMMIT git checkout $TAHOELAFS_COMMIT -b $TAHOELAFS_COMMIT
git submodule update --init --recursive git submodule update --init --recursive
virtualenv venv --distribute virtualenv venv --distribute
venv/bin/pip uninstall --yes setuptools venv/bin/pip uninstall --yes setuptools
venv/bin/pip install setuptools==11.3 venv/bin/pip install setuptools==36.0.1
venv/bin/pip install six==1.10.0 packaging==16.8 attrs==16.3.0 appdirs==1.4.2 pycrypto==2.1.0 cffi==1.9.1 venv/bin/pip install six==1.10.0
venv/bin/pip install cryptography==1.7.2 markerlib==0.6.0 distribute==0.7.3 venv/bin/pip install packaging==16.8
venv/bin/pip install attrs==17.2.0
venv/bin/pip install appdirs==1.4.3
venv/bin/pip install pycrypto==2.6.1
venv/bin/pip install cffi==1.9.1
venv/bin/pip install cryptography==1.7.2
venv/bin/pip install markerlib==0.6.0
venv/bin/pip install distribute==0.7.3
venv/bin/pip install txtorcon==0.18.0 venv/bin/pip install txtorcon==0.18.0
venv/bin/pip install --editable . venv/bin/pip install --editable .
} }
@ -496,7 +507,7 @@ function create_tahoelafs_client {
} }
function get_tahoelafs_furl { function get_tahoelafs_furl {
furl=$(cat /home/tahoelafs/storage/private/storage.furl) furl=$(cat $TAHOE_DIR/storage/private/storage.furl)
furl_1=$(echo "${furl}" | awk -F ' ' '{print $1}') furl_1=$(echo "${furl}" | awk -F ' ' '{print $1}')
furl_2=$(echo "${furl}" | awk -F ':' '{print $5}') furl_2=$(echo "${furl}" | awk -F ':' '{print $5}')
echo "${furl_1}:${furl_2}" echo "${furl_1}:${furl_2}"
@ -511,7 +522,7 @@ function get_tahoelafs_storage_hostname {
} }
function get_tahoelafs_public_key { function get_tahoelafs_public_key {
echo "$(cat /home/tahoelafs/storage/node.pubkey | grep 'v0-' | sed 's|pub-||g')" echo "$(cat $TAHOE_DIR/storage/node.pubkey | grep 'v0-' | sed 's|pub-||g')"
} }
function add_tahoelafs_server { function add_tahoelafs_server {
@ -572,12 +583,12 @@ function create_tahoelafs_daemon {
echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE
echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
echo "Group=debian-tor" >> $TAHOELAFS_DAEMON_FILE echo "Group=debian-tor" >> $TAHOELAFS_DAEMON_FILE
echo "WorkingDirectory=/home/tahoelafs/tahoelafs" >> $TAHOELAFS_DAEMON_FILE echo "WorkingDirectory=${TAHOE_DIR}/tahoelafs" >> $TAHOELAFS_DAEMON_FILE
echo "ExecStart=/home/tahoelafs/tahoelafs/venv/bin/tahoe run /home/tahoelafs/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE echo "ExecStart=${TAHOE_DIR}/tahoelafs/venv/bin/tahoe run ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
echo "ExecStop=/home/tahoelafs/tahoelafs/venv/bin/tahoe stop /home/tahoelafs/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE echo "ExecStop=${TAHOE_DIR}/tahoelafs/venv/bin/tahoe stop ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE
echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE
echo "Environment=\"USER=tahoelafs\" \"HOME=/home/tahoelafs\"" >> $TAHOELAFS_DAEMON_FILE echo "Environment=\"USER=tahoelafs\" \"HOME=${TAHOE_DIR}\"" >> $TAHOELAFS_DAEMON_FILE
echo '' >> $TAHOELAFS_DAEMON_FILE echo '' >> $TAHOELAFS_DAEMON_FILE
echo '[Install]' >> $TAHOELAFS_DAEMON_FILE echo '[Install]' >> $TAHOELAFS_DAEMON_FILE
echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE
@ -646,27 +657,27 @@ function install_tahoelafs {
apt-get -yq install libcrypto++-dev python-pycryptopp python-cffi python-virtualenv apt-get -yq install libcrypto++-dev python-pycryptopp python-cffi python-virtualenv
# create a user # create a user
if [ ! -d /home/tahoelafs ]; then if [ ! -d $TAHOE_DIR ]; then
# add a gogs user account # add a gogs user account
adduser --disabled-login --gecos 'tahoe-lafs' tahoelafs adduser --disabled-login --gecos 'tahoe-lafs' tahoelafs
adduser tahoelafs debian-tor adduser tahoelafs debian-tor
fi fi
if [ -d /home/tahoelafs/Maildir ]; then if [ -d $TAHOE_DIR/Maildir ]; then
rm -rf /home/tahoelafs/Maildir rm -rf $TAHOE_DIR/Maildir
fi fi
install_tahoelafs_to_directory /home/tahoelafs/tahoelafs install_tahoelafs_to_directory $TAHOE_DIR/tahoelafs
# remove files we don't need # remove files we don't need
rm -rf /home/tahoelafs/.mutt rm -rf $TAHOE_DIR/.mutt
rm /home/tahoelafs/.emacs-mutt rm $TAHOE_DIR/.emacs-mutt
rm /home/tahoelafs/.muttrc rm $TAHOE_DIR/.muttrc
rm /home/tahoelafs/.mutt-alias rm $TAHOE_DIR/.mutt-alias
rm /home/tahoelafs/.procmailrc rm $TAHOE_DIR/.procmailrc
# set permissions # set permissions
chown -R tahoelafs:debian-tor /home/tahoelafs chown -R tahoelafs:debian-tor $TAHOE_DIR
node_nick=$(get_tahoelafs_nick) node_nick=$(get_tahoelafs_nick)
client_nick=${MY_USERNAME}-client client_nick=${MY_USERNAME}-client
@ -677,14 +688,14 @@ function install_tahoelafs {
# create an onion address for client node # create an onion address for client node
TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs 80 ${TAHOELAFS_ONION_PORT}) TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs 80 ${TAHOELAFS_ONION_PORT})
create_tahoelafs_stealth_node /home/tahoelafs/storage /home/tahoelafs/client ${node_nick} ${client_nick} create_tahoelafs_stealth_node $TAHOE_DIR/storage $TAHOE_DIR/client ${node_nick} ${client_nick}
# start the storage node # start the storage node
su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/storage' - tahoelafs su -c "$TAHOE_DIR/tahoelafs/venv/bin/python2 $TAHOE_DIR/tahoelafs/venv/bin/tahoe start $TAHOE_DIR/storage" - tahoelafs
create_tahoelafs_daemon "storage" create_tahoelafs_daemon "storage"
# start the client # start the client
su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/client' - tahoelafs su -c "$TAHOE_DIR/tahoelafs/venv/bin/python2 $TAHOE_DIR/tahoelafs/venv/bin/tahoe start $TAHOE_DIR/client" - tahoelafs
add_tahoelafs_server "$(get_tahoelafs_storage_hostname)" "$(get_tahoelafs_public_key)" "${node_nick}" "$(get_tahoelafs_furl)" add_tahoelafs_server "$(get_tahoelafs_storage_hostname)" "$(get_tahoelafs_public_key)" "${node_nick}" "$(get_tahoelafs_furl)"
if ! grep -q "HidServAuth $(get_tahoelafs_storage_hostname)" /etc/tor/torrc; then if ! grep -q "HidServAuth $(get_tahoelafs_storage_hostname)" /etc/tor/torrc; then
echo $'Unable to create tahoelafs server' echo $'Unable to create tahoelafs server'