summary refs log tree commit diff
path: root/bin/wsudo
blob: 1ac1e33902d96d84f454f04fcca2254a811ef284 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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