Skip to content

Commit 1262515

Browse files
authored
Merge pull request #49 from buildplan/rerun_with_sudo
Re-run the script with sudo if not already root
2 parents 038890b + 76b9c48 commit 1262515

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

backup_script.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# ===================== v0.35 - 2025.08.21 ========================
2+
# ===================== v0.36 - 2025.08.29 ========================
33
#
44
# Example backup.conf:
55
# BACKUP_DIRS="/home/user/test/./ /var/www/./"
@@ -59,10 +59,12 @@ else
5959
C_CYAN=''
6060
fi
6161

62-
# Check if the script is being run as root
63-
if (( EUID != 0 )); then
64-
echo "❌ This script must be run as root or with sudo." >&2
65-
exit 1
62+
# Re-run the script with sudo if not already root
63+
if [[ $EUID -ne 0 ]]; then
64+
echo -e "${C_BOLD}${C_YELLOW}This script requires root privileges to function correctly.${C_RESET}"
65+
echo -e "${C_YELLOW}Attempting to re-run with sudo. You may be prompted for your password.${C_RESET}"
66+
echo "----------------------------------------------------------------"
67+
exec sudo "$0" "$@"
6668
fi
6769

6870
# --- Determine script's location to load the config file ---

backup_script.sh.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4175a7e1000fc6ecf3d94f11758b9d5b5ed86e3a88c0e0b973212a79780d6a8d backup_script.sh
1+
2ce03d52c44801851ab0d17e5f6bea8c21ab59511e54c1131fda0ddcdfa2af1d backup_script.sh

0 commit comments

Comments
 (0)