From f03cd446bf54bfbdaf46ff4b3ee7fc94e866be40 Mon Sep 17 00:00:00 2001 From: Seppo Enarvi Date: Thu, 8 Apr 2021 07:49:06 +0300 Subject: [PATCH 1/2] Correctly check current directory and try changing to ~/IOTstack --- scripts/backup.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 6856c1d78..47503c2ef 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -25,15 +25,18 @@ # sudo bash ./scripts/backup.sh 2 pi # This will only produce a backup in the rollowing folder and change all the permissions to the 'pi' user. -if [ -d "./menu.sh" ]; then - echo "./menu.sh file was not found. Ensure that you are running this from IOTstack's directory." - exit 1 +if [ ! -f "menu.sh" ]; then + cd "$HOME/IOTstack" + if [ ! -f "menu.sh" ]; then + echo "menu.sh file was not found from the current directory. Ensure that you are running this from IOTstack's directory." + exit 1 + fi fi BACKUPTYPE=${1:-"3"} if [[ "$BACKUPTYPE" -ne "1" && "$BACKUPTYPE" -ne "2" && "$BACKUPTYPE" -ne "3" ]]; then - echo "Unknown backup type '$BACKUPTYPE', can only be 1, 2 or 3" + echo "Unknown backup type '$BACKUPTYPE', can only be 1, 2 or 3" exit 1 fi From c333d8044c6af08d4eddf158a83c0cbb37282232 Mon Sep 17 00:00:00 2001 From: Seppo Enarvi Date: Thu, 13 May 2021 21:55:24 +0300 Subject: [PATCH 2/2] cd to the parent directory, to avoid hardcoding the IOTstack directory --- scripts/backup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 47503c2ef..0e48253fd 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -26,7 +26,8 @@ # This will only produce a backup in the rollowing folder and change all the permissions to the 'pi' user. if [ ! -f "menu.sh" ]; then - cd "$HOME/IOTstack" + script_path=$(readlink -f "${BASH_SOURCE[0]}") + cd "${script_path%/*}/.." if [ ! -f "menu.sh" ]; then echo "menu.sh file was not found from the current directory. Ensure that you are running this from IOTstack's directory." exit 1