Created
August 18, 2015 12:57
-
-
Save belminf/e9f0ea251591f7b50754 to your computer and use it in GitHub Desktop.
Export xauth stuff when switching users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Help | |
usage() { | |
echo -e "Usage: $0 <user to switch to>" | |
} | |
# Check if we have enough args | |
if [ $# -ne 1 ] | |
then | |
usage | |
exit 1 | |
fi | |
# User sudo'ing to | |
sudo_user=$1 | |
# Variables needed | |
display_name=`sed -e 's/^.*://' -e 's/\.[0-9]*//' <<< $DISPLAY` | |
auth_entry=`xauth list | grep ":$display_name"` | |
auth_name=`echo $auth_entry | cut -d' ' -f1` | |
default_shell=`getent passwd $sudo_user | cut -d: -f7` | |
# Open new shell with xauth stuff exported | |
sudo su - $sudo_user --session-command "xauth add $auth_entry; DISPLAY=$DISPLAY $default_shell -; xauth remove $auth_name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment