]>
code.delx.au - monosys/blob - scripts/xuserrun
4 # Run a command as the currently active X11 user
9 # determine location of loginctl
10 LOGINCTL
=$
(command -v loginctl ||
command -v systemd-loginctl
)
11 if [[ -e LOGINCTL
]]; then
12 echo "Error: Unable to find loginctl executable"
20 eval declare -Ag $varname
21 for row
in $
(loginctl show-session
"$session"); do
22 key
="$(echo "${row}"|cut -d= -f1)"
23 val
="$(echo "${row}"|cut -d= -f2-)"
24 eval ${varname}[\"${key}\"]=\"${val}\"
34 active_session
="$(loginctl show-seat ${seat}|grep ActiveSession|cut -d= -f2)"
35 if [[ $?
-ne 0 ||
-z $active_session ]]; then
36 echo "Error: Unable to determine active session"
40 get_session_info
$active_session session_info
42 if [[ ${session_info[Type]} != "x11" ]]; then
43 echo "Error: Active session is not x11"
47 current_user
="$(id -u -n)"
49 if [[ ${current_user} == ${session_info[Name]} ]]; then
50 # already correct user, no need to su
51 DISPLAY
="${session_info[Display]}" "$@"
54 DISPLAY
="${session_info[Display]}" su
-c - "${session_info[Name]}" "$(escape "$@
")"