summaryrefslogtreecommitdiff
path: root/x11/xsudo
blob: 03a01c4da81a752e74a914f708ea8cc2d1680818 (plain)
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
#!/bin/sh

printhelp() {
cat << HELPDOC "
usage: $(basename "$0") command"
usage: $(basename "$0") [-gh]"

options:
  -g, --get-pass    print password to stdout and exit. will output blank if in 'nopass' mode
  -h, --help        show this help page and exit
HELPDOC
}

# get password
sudo=${SUDO:-sudo}
while ! echo "$pass" | $sudo -n true; do
	pass="$(dmenu -p 'Password: ' <&-)" # Ask user for password pass is incorrect (skipped if nopass in enabled)
	[ "$pass" = '' ] && exit 0
done


# options
[ -z "$1" ] && printhelp && exit 1

case "$1" in
	-g|--get-pass) printf "$pass" && exit 0 ;;
	-h|--help)     printhelp      && exit 0 ;;
esac

# xpsuedo magic
echo "$pass" | $sudo xauth -f /root/.Xauthority add $(xauth list $DISPLAY) \
	&& echo "$pass" | $sudo "$@"