Guest User

/usr/bin/startx

a guest
Sep 18th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.60 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. #
  4. # This is just a sample implementation of a slightly less primitive
  5. # interface than xinit. It looks for user .xinitrc and .xserverrc
  6. # files, then system xinitrc and xserverrc files, else lets xinit choose
  7. # its default. The system xinitrc should probably do things like check
  8. # for .Xresources files and merge them in, start up a window manager,
  9. # and pop a clock and several xterms.
  10. #
  11. # Site administrators are STRONGLY urged to write nicer versions.
  12. #
  13.  
  14. unset SESSION_MANAGER
  15. userclientrc=$HOME/.xinitrc
  16. sysclientrc=/etc/X11/xinit/xinitrc
  17.  
  18. userserverrc=$HOME/.xserverrc
  19. sysserverrc=/etc/X11/xinit/xserverrc
  20. defaultclient=xterm
  21. defaultserver=/usr/bin/X
  22. defaultclientargs=""
  23. defaultserverargs=""
  24. defaultdisplay=""
  25. clientargs=""
  26. serverargs=""
  27. vtarg=""
  28. enable_xauth=1
  29.  
  30.  
  31. # Automatically determine an unused $DISPLAY
  32. d=0
  33. while true ; do
  34.     [ -e "/tmp/.X$d-lock" -o -S "/tmp/.X11-unix/X$d" ] || break
  35.     d=$(($d + 1))
  36. done
  37. defaultdisplay=":$d"
  38. unset d
  39.  
  40. whoseargs="client"
  41. while [ x"$1" != x ]; do
  42.     case "$1" in
  43.     # '' required to prevent cpp from treating "/*" as a C comment.
  44.     /''*|\./''*)
  45.  if [ "$whoseargs" = "client" ]; then
  46.      if [ x"$client" = x ] && [ x"$clientargs" = x ]; then
  47.   client="$1"
  48.      else
  49.   clientargs="$clientargs $1"
  50.      fi
  51.  else
  52.      if [ x"$server" = x ] && [ x"$serverargs" = x ]; then
  53.   server="$1"
  54.      else
  55.   serverargs="$serverargs $1"
  56.      fi
  57.  fi
  58.  ;;
  59.     --)
  60.  whoseargs="server"
  61.  ;;
  62.     *)
  63.  if [ "$whoseargs" = "client" ]; then
  64.      clientargs="$clientargs $1"
  65.  else
  66.      # display must be the FIRST server argument
  67.      if [ x"$serverargs" = x ] && \
  68.    expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then
  69.   display="$1"
  70.      else
  71.   serverargs="$serverargs $1"
  72.      fi
  73.  fi
  74.  ;;
  75.     esac
  76.     shift
  77. done
  78.  
  79. # process client arguments
  80. if [ x"$client" = x ]; then
  81.     client=$defaultclient
  82.  
  83.     # For compatibility reasons, only use startxrc if there were no client command line arguments
  84.     if [ x"$clientargs" = x ]; then
  85.         if [ -f "$userclientrc" ]; then
  86.             client=$userclientrc
  87.         elif [ -f "$sysclientrc" ]; then
  88.             client=$sysclientrc
  89.         fi
  90.     fi
  91. fi
  92.  
  93. # if no client arguments, use defaults
  94. if [ x"$clientargs" = x ]; then
  95.     clientargs=$defaultclientargs
  96. fi
  97.  
  98. # process server arguments
  99. if [ x"$server" = x ]; then
  100.     server=$defaultserver
  101.  
  102.  
  103.     # When starting the defaultserver start X on the current tty to avoid
  104.     # the startx session being seen as inactive:
  105.     # "https://bugzilla.redhat.com/show_bug.cgi?id=806491"
  106.     tty=$(tty)
  107.     if expr "$tty" : '/dev/tty[0-9][0-9]*$' > /dev/null; then
  108.         tty_num=$(echo "$tty" | grep -oE '[0-9]+$')
  109.         vtarg="vt$tty_num -keeptty"
  110.     fi
  111.  
  112.  
  113.     # For compatibility reasons, only use xserverrc if there were no server command line arguments
  114.     if [ x"$serverargs" = x -a x"$display" = x ]; then
  115.  if [ -f "$userserverrc" ]; then
  116.      server=$userserverrc
  117.  elif [ -f "$sysserverrc" ]; then
  118.      server=$sysserverrc
  119.  fi
  120.     fi
  121. fi
  122.  
  123. # if no server arguments, use defaults
  124. if [ x"$serverargs" = x ]; then
  125.     serverargs=$defaultserverargs
  126. fi
  127.  
  128. # if no vt is specified add vtarg (which may be empty)
  129. have_vtarg="no"
  130. for i in $serverargs; do
  131.     if expr "$i" : 'vt[0-9][0-9]*$' > /dev/null; then
  132.         have_vtarg="yes"
  133.     fi
  134. done
  135. if [ "$have_vtarg" = "no" ]; then
  136.     serverargs="$serverargs $vtarg"
  137. fi
  138.  
  139. # if no display, use default
  140. if [ x"$display" = x ]; then
  141.     display=$defaultdisplay
  142. fi
  143.  
  144. if [ x"$enable_xauth" = x1 ] ; then
  145.     if [ x"$XAUTHORITY" = x ]; then
  146.         XAUTHORITY=$HOME/.Xauthority
  147.         export XAUTHORITY
  148.     fi
  149.  
  150.     removelist=
  151.  
  152.     # set up default Xauth info for this machine
  153.     case `uname` in
  154.     Linux*)
  155.         if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then
  156.             hostname=`hostname -f`
  157.         else
  158.             hostname=`hostname`
  159.         fi
  160.         ;;
  161.     *)
  162.         hostname=`hostname`
  163.         ;;
  164.     esac
  165.  
  166.     authdisplay=${display:-:0}
  167.  
  168.     mcookie=`/usr/bin/mcookie`
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.     if test x"$mcookie" = x; then
  177.         echo "Couldn't create cookie"
  178.         exit 1
  179.     fi
  180.     dummy=0
  181.  
  182.     # create a file with auth information for the server. ':0' is a dummy.
  183.     xserverauthfile=`mktemp -p /tmp serverauth.XXXXXXXXXX`
  184.     trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP KILL BUS TERM
  185.     xauth -q -f "$xserverauthfile" << EOF
  186. add :$dummy . $mcookie
  187. EOF
  188.  
  189.  
  190.  
  191.  
  192.     serverargs=${serverargs}" -auth "${xserverauthfile}
  193.  
  194.  
  195.     # now add the same credentials to the client authority file
  196.     # if '$displayname' already exists do not overwrite it as another
  197.     # server may need it. Add them to the '$xserverauthfile' instead.
  198.     for displayname in $authdisplay $hostname/unix$authdisplay; do
  199.         authcookie=`xauth list "$displayname" \
  200.         | sed -n "s/.*$hostname\/unix$authdisplay[[:space:]*].*[[:space:]*]//p"` 2>/dev/null;
  201.         if [ "z${authcookie}" = "z" ] ; then
  202.             xauth -q << EOF
  203. add $displayname . $mcookie
  204. EOF
  205.         removelist="$displayname $removelist"
  206.         else
  207.             dummy=$(($dummy+1));
  208.             xauth -q -f "$xserverauthfile" << EOF
  209. add :$dummy . $authcookie
  210. EOF
  211.         fi
  212.     done
  213. fi
  214.  
  215.  
  216.  
  217.  
  218. xinit "$client" $clientargs -- "$server" $display $serverargs
  219.  
  220. retval=$?
  221.  
  222. if [ x"$enable_xauth" = x1 ] ; then
  223.     if [ x"$removelist" != x ]; then
  224.         xauth remove $removelist
  225.     fi
  226.     if [ x"$xserverauthfile" != x ]; then
  227.         rm -f "$xserverauthfile"
  228.     fi
  229. fi
  230.  
  231.  
  232.  
  233.  
  234.  
  235. if command -v deallocvt > /dev/null 2>&1; then
  236.     deallocvt
  237. fi
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. exit $retval
  245.  
Add Comment
Please, Sign In to add comment