From 5fc271a8aba72e1d6d480f5ddcd7528e25cb233d Mon Sep 17 00:00:00 2001 From: klein panic Date: Mon, 10 Feb 2025 13:34:02 -0500 Subject: [PATCH] fixed --- chroot_manager.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/chroot_manager.sh b/chroot_manager.sh index 8e49b41..ace153b 100755 --- a/chroot_manager.sh +++ b/chroot_manager.sh @@ -45,9 +45,14 @@ 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" "$@" +# If running as root via sudo (SUDO_USER is set) but the environment isn’t fully preserved, +# force a re-run with sudo -E. We use _ENV_PRESERVED as a marker to avoid an infinite loop. +if [ -n "$SUDO_USER" ] && [ -z "$_ENV_PRESERVED" ]; then + # Check for essential environment variables (you can add others if needed). + if [ -z "$DISPLAY" ] || [ -z "$XAUTHORITY" ]; then + export _ENV_PRESERVED=1 + exec sudo -E "$0" "$@" + fi fi # --- Logging Functions ---