diff options
| author | Robert Günzler <r@gnzler.io> | 2020-01-26 17:16:07 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2020-01-26 18:00:59 +0100 |
| commit | f5d56602df70950de6b7d40966b00c9939c81763 (patch) | |
| tree | b50ffeb5496fe3525cc1bab2629389ced95435b7 /bin/wsudo | |
Intial commit of v2
See https://drewdevault.com/2019/12/30/dotfiles.html
Diffstat (limited to 'bin/wsudo')
| -rwxr-xr-x | bin/wsudo | 44 |
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 |