Guest User

startx

a guest
Sep 16th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 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 DBUS_SESSION_BUS_ADDRESS
  15. unset SESSION_MANAGER
  16.  
  17.  
  18. userclientrc=$HOME/.xinitrc
  19. sysclientrc=/etc/X11/xinit/xinitrc
  20.  
  21.  
  22. userserverrc=$HOME/.xserverrc
  23. sysserverrc=/etc/X11/xinit/xserverrc
  24. defaultclient=xterm
  25. defaultserver=/usr/bin/X
  26. defaultclientargs=""
  27. defaultserverargs=""
  28. defaultdisplay=":0"
  29. clientargs=""
  30. serverargs=""
  31.  
  32. enable_xauth=1
  33.  
  34. # Automatically determine an unused $DISPLAY
  35. d=0
  36. while true ; do
  37. [ -e /tmp/.X$d-lock ] || break
  38. d=$(($d + 1))
  39. done
  40. defaultdisplay=":$d"
  41. unset d
  42. whoseargs="client"
  43. while [ x"$1" != x ]; do
  44. case "$1" in
  45. # '' required to prevent cpp from treating "/*" as a C comment.
  46. /''*|\./''*)
  47. if [ "$whoseargs" = "client" ]; then
  48. if [ x"$client" = x ] && [ x"$clientargs" = x ]; then
  49. client="$1"
  50. else
  51. clientargs="$clientargs $1"
  52. fi
  53. else
  54. if [ x"$server" = x ] && [ x"$serverargs" = x ]; then
  55. server="$1"
  56. else
  57. serverargs="$serverargs $1"
  58. fi
  59. fi
  60. ;;
  61. --)
  62. whoseargs="server"
  63. ;;
  64. *)
  65. if [ "$whoseargs" = "client" ]; then
  66. clientargs="$clientargs $1"
  67. else
  68. # display must be the FIRST server argument
  69. if [ x"$serverargs" = x ] && \
  70. expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then
  71. display="$1"
  72. else
  73. serverargs="$serverargs $1"
  74. fi
  75. fi
  76. ;;
  77. esac
  78. shift
  79. done
  80.  
  81. # process client arguments
  82. if [ x"$client" = x ]; then
  83. client=$defaultclient
  84.  
  85. # For compatibility reasons, only use startxrc if there were no client command line arguments
  86. if [ x"$clientargs" = x ]; then
  87. if [ -f "$userclientrc" ]; then
  88. client=$userclientrc
  89. elif [ -f "$sysclientrc" ]; then
  90. client=$sysclientrc
  91. fi
  92. fi
  93. fi
  94.  
  95. # if no client arguments, use defaults
  96. if [ x"$clientargs" = x ]; then
  97. clientargs=$defaultclientargs
  98. fi
  99.  
  100. # process server arguments
  101. if [ x"$server" = x ]; then
  102. server=$defaultserver
  103.  
  104. # For compatibility reasons, only use xserverrc if there were no server command line arguments
  105. if [ x"$serverargs" = x -a x"$display" = x ]; then
  106. if [ -f "$userserverrc" ]; then
  107. server=$userserverrc
  108. elif [ -f "$sysserverrc" ]; then
  109. server=$sysserverrc
  110. fi
  111. fi
  112. fi
  113.  
  114. # if no server arguments, use defaults
  115. if [ x"$serverargs" = x ]; then
  116. serverargs=$defaultserverargs
  117. fi
  118.  
  119. # if no display, use default
  120. if [ x"$display" = x ]; then
  121. display=$defaultdisplay
  122. fi
  123.  
  124. if [ x"$enable_xauth" = x1 ] ; then
  125. if [ x"$XAUTHORITY" = x ]; then
  126. XAUTHORITY=$HOME/.Xauthority
  127. export XAUTHORITY
  128. fi
  129.  
  130. removelist=
  131.  
  132. # set up default Xauth info for this machine
  133. case `uname` in
  134. Linux*)
  135. if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then
  136. hostname=`hostname -f`
  137. else
  138. hostname=`hostname`
  139. fi
  140. ;;
  141. *)
  142. hostname=`hostname`
  143. ;;
  144. esac
  145.  
  146. authdisplay=${display:-:0}
  147.  
  148. mcookie=`/usr/bin/mcookie`
  149. if test x"$mcookie" = x; then
  150. echo "Couldn't create cookie"
  151. exit 1
  152. fi
  153. dummy=0
  154.  
  155. # create a file with auth information for the server. ':0' is a dummy.
  156. xserverauthfile=$HOME/.serverauth.$$
  157. trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP KILL BUS TERM
  158. xauth -q -f "$xserverauthfile" << EOF
  159. add :$dummy . $mcookie
  160. EOF
  161. serverargs=${serverargs}" -auth "${xserverauthfile}
  162.  
  163.  
  164. # now add the same credentials to the client authority file
  165. # if '$displayname' already exists do not overwrite it as another
  166. # server man need it. Add them to the '$xserverauthfile' instead.
  167. for displayname in $authdisplay $hostname$authdisplay; do
  168. authcookie=`xauth list "$displayname" \
  169. | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p"` 2>/dev/null;
  170. if [ "z${authcookie}" = "z" ] ; then
  171. xauth -q << EOF
  172. add $displayname . $mcookie
  173. EOF
  174. removelist="$displayname $removelist"
  175. else
  176. dummy=$(($dummy+1));
  177. xauth -q -f "$xserverauthfile" << EOF
  178. add :$dummy . $authcookie
  179. EOF
  180. fi
  181. done
  182. fi
  183.  
  184. xinit "$client" $clientargs -- "$server" $display $serverargs
  185.  
  186. retval=$?
  187.  
  188. if [ x"$enable_xauth" = x1 ] ; then
  189. if [ x"$removelist" != x ]; then
  190. xauth remove $removelist
  191. fi
  192. if [ x"$xserverauthfile" != x ]; then
  193. rm -f "$xserverauthfile"
  194. fi
  195. fi
  196. exit $retval
Advertisement
Add Comment
Please, Sign In to add comment