From 3063b41206a5ecd40830c5b9bf0676a981862333 Mon Sep 17 00:00:00 2001 From: klein panic Date: Mon, 10 Feb 2025 13:28:50 -0500 Subject: [PATCH] added function to force script to preserve the environment when ran as root --- chroot_manager.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/chroot_manager.sh b/chroot_manager.sh index 86cea0e..8e49b41 100755 --- a/chroot_manager.sh +++ b/chroot_manager.sh @@ -45,6 +45,11 @@ DAEMON_LOG_DIR="$(pwd)/chroot_daemon_logs" # List of trivial commands to ignore in daemon logs (basename only) IGNORE_LIST=(bash sh ls cat echo grep mount umount) +# Force the script to run as root while preserving the environment +if [ "$EUID" -ne 0 ]; then + exec sudo -E "$0" "$@" +fi + # --- Logging Functions --- function log_info() { echo "[INFO] $(date +'%F %T') $*" | tee -a "$LOGFILE"