Advertisement
Guest User

gimme-xauth.sh

a guest
Feb 16th, 2012
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.05 KB | None | 0 0
  1. #!/bin/sh
  2. # Script for displaying stuff in the user's screen from ssh without `xhost +`, needs root.
  3. # See comments in http://superuser.com/a/153864/19668 for more details.
  4. #
  5. # Also recommended: something like `export DISPLAY=:0` (and shellinabox for convenience!).
  6. #
  7. # CC-BY Camilo Martin (camilomm.deviantart.com)
  8.  
  9. # The first parameter is the user. If not supplied, use the current user.
  10. if [ -z "$1" ]; then
  11.     user=$(whoami)
  12. else
  13.     user=$1
  14. fi
  15.  
  16. # Check if user exists, report if doesn't.
  17. if ! id "$user" > /dev/null 2> /dev/null; then
  18.     echo The user "'$user'" does not even exist.
  19.     return 2
  20. fi
  21.  
  22. # You'll need root.
  23. for x in $(sudo ls /var/run/gdm3/); do
  24.     gdmuser=$(echo "$x" | grep auth-for-$user-)
  25.     xauth=/var/run/gdm3/$gdmuser/database
  26. done
  27.  
  28. # Maybe the user is not running X, or GDM.
  29. if [ -z "$gdmuser" ]; then
  30.     echo This user is likely either not running an X server, or is using something else than gdm3.
  31.     return 3
  32. fi
  33.  
  34. # Export it.
  35. export XAUTHORITY=$xauth
  36.  
  37. # Done.
  38. echo "\$XAUTHORITY export set, with value '$xauth'"
  39. return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement