From bae08f832478eab33e434534bc5d9b000d80d937 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Sko=C5=99epa?= <jakub@skorepa.info>
Date: Sat, 16 Apr 2016 18:23:23 +0200
Subject: [PATCH] Fix upload script

It wasn't working when run from different directory than one it was
stored in

And update it to work in correct directory
---
 upload | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/upload b/upload
index 3a7c012f..1217c365 100755
--- a/upload
+++ b/upload
@@ -6,6 +6,14 @@ then
 fi
 export PASSWORD=$LFTP_PASSWORD
 
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+  SOURCE="$(readlink "$SOURCE")"
+  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+done
+DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+
 USER=ok1kvk.cz-www-nove
 HOST=krios.blueboard.cz
 MAX_RETRIES=2
@@ -15,7 +23,7 @@ echo "======================================================================"
 echo "Uploading to $HOST"
 if [ "$1" == "ftp" ]; then
     echo "Using FTP"
-    time lftp -e "set cmd:fail-exit yes;\
+    /usr/bin/time -f "Upload took %e" -- lftp -e "set cmd:fail-exit yes;\
                   set net:timeout 5;\
                   set net:reconnect-interval-base $RECONNECT_INTERVAL;\
                   set net:max-retries $MAX_RETRIES;\
@@ -27,7 +35,7 @@ if [ "$1" == "ftp" ]; then
     echo "LFTP finished with return code $RET"
 else
     echo "Using SFTP"
-    /usr/bin/time -f "Upload took %e" -- node sftp-sync.js --sourcedir build --server $HOST --user $USER --remotedir /test --port 2121
+    /usr/bin/time -f "Upload took %e" -- node $DIR/sftp-sync.js --sourcedir build --server $HOST --user $USER --remotedir / --port 2121
 fi
 exit 0
 
-- 
GitLab