Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly check current directory and try changing to ~/IOTstack #311

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd "$(dirname $(readlink -f $0))/.." Does this work for you instead? Trying not to lock IOTstack to ~/IOTstack

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking some time to reply @Slyke . It's of course a lot better to avoid hardcoding the IOTstack directory. I did something similar that I think should also work in the unlikely case that the path contains spaces.

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

Expand Down