summary refs log tree commit diff
path: root/bin/wsudo
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wsudo')
-rwxr-xr-xbin/wsudo44
1 files changed, 44 insertions, 0 deletions
diff --git a/bin/wsudo b/bin/wsudo
new file mode 100755
index 0000000..1ac1e33
--- /dev/null
+++ b/bin/wsudo
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+#
+# Enable root access to x-windows system.
+#
+# Motivation: Trying to run a graphical application as root via su, sudo in a 
+# Wayland session (e.g. GParted or Gedit), will fail. Apps which use polkit to
+# request administrator permissions for just certain operations and only when 
+# needed are not affected (they are not started as root right away). 
+# [1] https://bugzilla.redhat.com/show_bug.cgi?id=1274451
+#
+# Based on a Reddit comment.
+# [2] https://www.reddit.com/r/Fedora/comments/5eb633/solution_running_graphical_app_with_sudo_in/
+
+usage() {
+    printf "usage: wsudo [-d] [command]\n"
+}
+
+# make sure there is an argument
+if (( $# == 0 )); then
+    echo "error: Illegal number of parameters." >&2
+    exit 1
+fi
+
+if ! type -p "$1" &>/dev/null; then
+    echo "$1 not found. Aborting." >&2
+    exit 1
+fi
+
+for cmd in sudo xhost; do
+    if ! type -P $cmd &>/dev/null; then
+        echo "$cmd it's not installed. Aborting." >&2
+        exit 1
+    fi
+done
+
+set -x
+
+xhost +SI:localuser:root
+SUDO_ASKPASS="`command -v askpass`" sudo -A "${@}"
+#disable root access after application terminates
+xhost -SI:localuser:root
+#print access status to allow verification that root access was removed
+xhost