From d47ed1b8a28e8bd4ecad129e23c685e033a7bdaa Mon Sep 17 00:00:00 2001 From: ukkopahis <95980324+ukkopahis@users.noreply.github.com> Date: Mon, 9 May 2022 23:41:30 +0300 Subject: [PATCH] restore.sh: ensure run as root * allow start from any current folder * chmod logfile to allow all to read it --- scripts/restore.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/restore.sh b/scripts/restore.sh index 782084467..8bedc807f 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -1,4 +1,5 @@ #!/bin/bash +# vim: sw=2 # Usage: # ./scripts/restore.sh [FILENAME=backup.tar.gz] {noask} @@ -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 "" @@ -85,4 +90,6 @@ echo "" >> $LOGFILE echo "### End of log ###" >> $LOGFILE echo "" >> $LOGFILE +chmod a+r $LOGFILE + cat $LOGFILE