Skip to content

Commit

Permalink
restore.sh: ensure run as root
Browse files Browse the repository at this point in the history
* allow start from any current folder
* chmod logfile to allow all to read it
  • Loading branch information
ukkopahis committed May 31, 2022
1 parent 0387b75 commit d47ed1b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# vim: sw=2

# Usage:
# ./scripts/restore.sh [FILENAME=backup.tar.gz] {noask}
Expand All @@ -14,11 +15,15 @@
# Will restore from the backup file "./backups/some_other_backup.tar.gz" and will not warn that data will be deleted.
#

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 [[ "$EUID" != 0 ]]; then
# re-run as root in order to be able to restore owners correctly
sudo ${BASH_SOURCE[0]} "$@"
exit $?
fi

# Allow running from everywhere, but change folder to script's IOTstack
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."

echo "Restoring from a backup will erase all existing data."
read -p "Continue [y/N]? " -n 1 -r PROCEED_WITH_RESTORE
echo ""
Expand Down Expand Up @@ -85,4 +90,6 @@ echo "" >> $LOGFILE
echo "### End of log ###" >> $LOGFILE
echo "" >> $LOGFILE

chmod a+r $LOGFILE

cat $LOGFILE

0 comments on commit d47ed1b

Please sign in to comment.