Files
snigdhaos-pkgbuilds/snigdhaos-libs/pkexec-gui

33 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Ensure pkexec is available
if ! command -v pkexec &>/dev/null; then
echo "Error: pkexec is not installed. Please install PolicyKit."
exit 1
fi
# Check if running as root
if [[ $EUID -ne 0 ]]; then
# Attempt to execute the script as root via pkexec
exec pkexec /usr/lib/snigdhaos/pkexec-gui "$@"
exit 1
fi
# Shellcheck disable: Read environment variables from parent process
# shellcheck disable=SC2163
# Read the necessary environment variables from the parent process
while IFS= read -rd '' var; do
export "$var"
done < <(grep --null-data -ae "^\($XDG_CURRENT_DESKTOP\|WAYLAND_DISPLAY\|XDG_RUNTIME_DIR\|XDG_SESSION_TYPE\|XCURSOR_SIZE\|LC_*\|LANG\|LANGUAGE\|QT_WAYLAND_FORCE_DPI\|QT_QPA_PLATFORMTHEME\|QT_STYLE-OVERRIDE\|\)=.*\$" /proc/$PPID/environ)
# Adjust WAYLAND_DISPLAY if running on Wayland
if [[ -n "$WAYLAND_DISPLAY" ]]; then
export WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
fi
# Set the root user's XDG_RUNTIME_DIR
export XDG_RUNTIME_DIR="/run/user/0"
# Execute the provided command with root privileges
exec "$@"