From 48a912caa8eb1c632b8fffc0f11a868e9376ac30 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Fri, 4 May 2012 21:18:24 +0200 Subject: [PATCH] Now actually works, and exits if the configuration wasn't saved (or modified). --- setup.sh | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/setup.sh b/setup.sh index 70a721f..4a960f0 100755 --- a/setup.sh +++ b/setup.sh @@ -4,8 +4,8 @@ echo "Enter the hostname of the server you want to set up:" read HOST ssh -t -T "root@$HOST" 2>/dev/null <<'ENDSSH' echo "[!] Your final chance to abort before installation starts..." -echo "[!] Hit ctrl+C to abort, or wait 2 seconds for the installation to start." -sleep 2s +echo "[!] Hit ctrl+C to abort, or wait 4 seconds for the installation to start." +sleep 4s echo "[!] Installing dependencies..." apt-get install -y build-essential python python-dev >/dev/null 2>/dev/null if [ $? -ne 0 ]; then echo "[X] Installing dependencies failed."; exit 1; fi @@ -15,34 +15,34 @@ useradd -m tahoe >/dev/null 2>/dev/null if [ $? -ne 0 ]; then echo "[X] Adding tahoe user failed."; exit 1; fi echo "[+] Added tahoe user." -su tahoe -if [ $? -ne 0 ]; then echo "[X] Switching to tahoe user failed."; exit 1; exit 1; fi +exec su tahoe +if [ $? -ne 0 ]; then echo "[X] Switching to tahoe user failed."; exit 1; fi cd ~ -if [ $? -ne 0 ]; then echo "[X] Navigation to home directory failed."; exit 1; exit 1; fi +if [ $? -ne 0 ]; then echo "[X] Navigation to home directory failed."; exit 1; fi wget https://tahoe-lafs.org/source/tahoe-lafs/releases/allmydata-tahoe-1.9.1.tar.gz >/dev/null 2>/dev/null -if [ $? -ne 0 ]; then echo "[X] Downloading Tahoe-LAFS failed."; exit 1; exit 1; fi +if [ $? -ne 0 ]; then echo "[X] Downloading Tahoe-LAFS failed."; exit 1; fi echo "[+] Downloaded Tahoe-LAFS." tar -xzvf allmydata-tahoe-1.9.1.tar.gz >/dev/null 2>/dev/null -if [ $? -ne 0 ]; then echo "[X] Unpacking Tahoe-LAFS failed."; exit 1; exit 1; fi +if [ $? -ne 0 ]; then echo "[X] Unpacking Tahoe-LAFS failed."; exit 1; fi echo "[+] Unpacked Tahoe-LAFS." cd allmydata-tahoe-1.9.1 -if [ $? -ne 0 ]; then echo "[X] Navigating to Tahoe-LAFS source directory failed."; exit 1; exit 1; fi +if [ $? -ne 0 ]; then echo "[X] Navigating to Tahoe-LAFS source directory failed."; exit 1; fi echo "[!] I am now going to build Tahoe-LAFS, this is going to take a while. It's recommended to use this time to retrieve a beverage of your choice :)" echo "[!] Building..." python setup.py build >/dev/null 2>/dev/null -if [ $? -ne 0 ]; then echo "[X] Building Tahoe-LAFS failed."; exit 1; exit 1; fi +if [ $? -ne 0 ]; then echo "[X] Building Tahoe-LAFS failed."; exit 1; fi echo "[+] Successfully built Tahoe-LAFS." cd bin -if [ $? -ne 0 ]; then echo "[X] Navigation to Tahoe-LAFS binary directory failed."; exit 1; exit 1; fi +if [ $? -ne 0 ]; then echo "[X] Navigation to Tahoe-LAFS binary directory failed."; exit 1; fi ./tahoe create-node >/dev/null 2>/dev/null -if [ $? -ne 0 ]; then echo "[X] Creation of Tahoe-LAFS storage node failed."; exit 1; exit 1; fi +if [ $? -ne 0 ]; then echo "[X] Creation of Tahoe-LAFS storage node failed."; exit 1; fi echo "[+] Storage node created." stat --format=%Y ~/.tahoe/tahoe.cfg > ~/tahoe_setup_time @@ -59,25 +59,21 @@ read echo "[ ] There goes..." ssh -t "root@$HOST" 2>/dev/null nano /home/tahoe/.tahoe/tahoe.cfg ssh -t -T "root@$HOST" 2>/dev/null <<'ENDSSH' -su tahoe +exec su tahoe OLDTIME="$(cat ~/tahoe_setup_time)" rm ~/tahoe_setup_time -if [ "$(stat --format=%Y ~/.tahoe/tahoe.cfg)" == $OLDTIME ]; then echo "[X] You did not save the config file, cancellation assumed and installation aborted."; exit; exit 1; fi +if [ "$(stat --format=%Y ~/.tahoe/tahoe.cfg)" == $OLDTIME ]; then echo "[X] You did not save the config file, cancellation assumed and installation aborted."; exit 1; fi echo "[+] Configuration done." cd ~/allmydata-tahoe-1.9.1/bin ./tahoe start >/dev/null 2>/dev/null -if [ $? -ne 0 ]; then echo "[X] Starting the Tahoe-LAFS node failed, something went wrong."; exit 1; exit 1; fi +if [ $? -ne 0 ]; then echo "[X] Starting the Tahoe-LAFS node failed, something went wrong."; exit 1; fi ENDSSH -RESULT=$? - -echo "$RESULT" - -if [ $RESULT -ne 0 ]; then +if [ $? -ne 0 ]; then echo "[X] An error occurred during setup, the script will now exit." exit 1 fi