From 11b5c4f5c9463b829080cf91f4946462a09ffb73 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Tue, 4 Sep 2018 18:14:26 -0600 Subject: [PATCH] Added run-as-root check (disabled) Add in-script elevation for testing. --- root/scripts/borgbackup.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/root/scripts/borgbackup.sh b/root/scripts/borgbackup.sh index 0aeb6f4..5d919b0 100644 --- a/root/scripts/borgbackup.sh +++ b/root/scripts/borgbackup.sh @@ -75,3 +75,20 @@ logFile=/var/log/borgbackup.log ### Do NOT edit below this line + +## Ensure script is running as root (required) otherwise, exit +#if [ $(id -u) -ne 0 ]; then +# echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`] This script MUST" \ +# "be run as ROOT." +# echo -e "\e[4;31mScript aborted\e[0;31m.\e[0m" +# exit 1 +#fi + + +### elevate script -- used during program testing +if [ $EUID != 0 ]; then + sudo "$0" "$scriptPath" + exit $? +fi + +