B1KMusic

userlaunch

Feb 3rd, 2018
225
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Launches, on your X11 desktop, a program running under another user.
  3. # Example usage:
  4. #   sudo useradd socko
  5. #   sudo passwd socko
  6. #   sudo mkdir /home/socko
  7. #   ./userlaunch socko chromium-browser
  8. # Doing this, you could have multiple chromium-browsers under multiple users running concurrently on one single desktop.
  9.  
  10. ul_user=$1
  11. ul_program=$2
  12. ul_display=$3
  13.  
  14. if test -z "$ul_program" || test -z "$ul_user"; then
  15.     echo "usage: $0 user program [display]"
  16.     echo "if no display is specified, I will assume it's already defined."
  17.     exit 1
  18. fi
  19.  
  20. test -z "$ul_display" && ul_display=$DISPLAY
  21.  
  22. chmod o+r ~/.Xauthority
  23. su $ul_user -c "XAUTHORITY=$HOME/.Xauthority DISPLAY=$ul_display $ul_program"
  24. chmod o-r ~/.Xauthority
RAW Paste Data