Skip to content

Commit d47ed1b

Browse files
committed
restore.sh: ensure run as root
* allow start from any current folder * chmod logfile to allow all to read it
1 parent 0387b75 commit d47ed1b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scripts/restore.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
# vim: sw=2
23

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

17-
if [ -d "./menu.sh" ]; then
18-
echo "./menu.sh file was not found. Ensure that you are running this from IOTstack's directory."
19-
exit 1
18+
if [[ "$EUID" != 0 ]]; then
19+
# re-run as root in order to be able to restore owners correctly
20+
sudo ${BASH_SOURCE[0]} "$@"
21+
exit $?
2022
fi
2123

24+
# Allow running from everywhere, but change folder to script's IOTstack
25+
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
26+
2227
echo "Restoring from a backup will erase all existing data."
2328
read -p "Continue [y/N]? " -n 1 -r PROCEED_WITH_RESTORE
2429
echo ""
@@ -85,4 +90,6 @@ echo "" >> $LOGFILE
8590
echo "### End of log ###" >> $LOGFILE
8691
echo "" >> $LOGFILE
8792

93+
chmod a+r $LOGFILE
94+
8895
cat $LOGFILE

0 commit comments

Comments
 (0)