| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | # $Xorg: startx.cpp,v 1.3 2000/08/17 19:54:29 cpqbld Exp $ |
|---|
| 4 | # |
|---|
| 5 | # This is just a sample implementation of a slightly less primitive |
|---|
| 6 | # interface than xinit. It looks for user .xinitrc and .xserverrc |
|---|
| 7 | # files, then system xinitrc and xserverrc files, else lets xinit choose |
|---|
| 8 | # its default. The system xinitrc should probably do things like check |
|---|
| 9 | # for .Xresources files and merge them in, startup up a window manager, |
|---|
| 10 | # and pop a clock and serveral xterms. |
|---|
| 11 | # |
|---|
| 12 | # Site administrators are STRONGLY urged to write nicer versions. |
|---|
| 13 | # |
|---|
| 14 | # $XFree86: xc/programs/xinit/startx.cpp,v 3.16tsi Exp $ |
|---|
| 15 | |
|---|
| 16 | unset DBUS_SESSION_BUS_ADDRESS |
|---|
| 17 | unset SESSION_MANAGER |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | # Check for /usr/bin/X11 and BINDIR in the path, if not add them. |
|---|
| 22 | # This allows startx to be placed in a place like /usr/bin or /usr/local/bin |
|---|
| 23 | # and people may use X without changing their PATH. |
|---|
| 24 | # Note that we put our own bin directory at the front of the path, and |
|---|
| 25 | # the standard system path at the back, since if you are using the Xorg |
|---|
| 26 | # server theres a pretty good chance you want to bias the Xorg clients |
|---|
| 27 | # over the old system's clients. |
|---|
| 28 | |
|---|
| 29 | # First our compiled path |
|---|
| 30 | bindir=/usr/X11/bin |
|---|
| 31 | |
|---|
| 32 | case $PATH in |
|---|
| 33 | *:$bindir | *:$bindir:* | $bindir:*) ;; |
|---|
| 34 | *) PATH=$bindir:$PATH ;; |
|---|
| 35 | esac |
|---|
| 36 | |
|---|
| 37 | # Now the "old" compiled path |
|---|
| 38 | |
|---|
| 39 | oldbindir=/usr/X11R6/bin |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | if [ -d "$oldbindir" ] ; then |
|---|
| 45 | case $PATH in |
|---|
| 46 | *:$oldbindir | *:$oldbindir:* | $oldbindir:*) ;; |
|---|
| 47 | *) PATH=$PATH:$oldbindir ;; |
|---|
| 48 | esac |
|---|
| 49 | fi |
|---|
| 50 | |
|---|
| 51 | # Bourne shell does not automatically export modified environment variables |
|---|
| 52 | # so export the new PATH just in case the user changes the shell |
|---|
| 53 | export PATH |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | userclientrc=$HOME/.xinitrc |
|---|
| 57 | sysclientrc=/usr/X11/lib/X11/xinit/xinitrc |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | userserverrc=$HOME/.xserverrc |
|---|
| 61 | sysserverrc=/usr/X11/lib/X11/xinit/xserverrc |
|---|
| 62 | defaultclient=xterm |
|---|
| 63 | defaultserver=/usr/X11/bin/X |
|---|
| 64 | defaultclientargs="" |
|---|
| 65 | defaultserverargs="" |
|---|
| 66 | defaultdisplay=":0" |
|---|
| 67 | clientargs="" |
|---|
| 68 | serverargs="" |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | # Initialize defaults (this will cut down on "safe" error messages) |
|---|
| 73 | if ! defaults read org.x.X11 cache_fonts >& /dev/null ; then |
|---|
| 74 | defaults write org.x.X11 cache_fonts -bool true |
|---|
| 75 | fi |
|---|
| 76 | |
|---|
| 77 | if ! defaults read org.x.X11 no_auth >& /dev/null ; then |
|---|
| 78 | defaults write org.x.X11 no_auth -bool false |
|---|
| 79 | fi |
|---|
| 80 | |
|---|
| 81 | if ! defaults read org.x.X11 nolisten_tcp >& /dev/null ; then |
|---|
| 82 | defaults write org.x.X11 nolisten_tcp -bool true |
|---|
| 83 | fi |
|---|
| 84 | |
|---|
| 85 | # First, start caching fonts |
|---|
| 86 | if [ x`defaults read org.x.X11 cache_fonts` = x1 ] ; then |
|---|
| 87 | if [ -x /usr/X11/bin/font_cache ] ; then |
|---|
| 88 | /usr/X11/bin/font_cache & |
|---|
| 89 | elif [ -x /usr/X11/bin/font_cache.sh ] ; then |
|---|
| 90 | /usr/X11/bin/font_cache.sh & |
|---|
| 91 | elif [ -x /usr/X11/bin/fc-cache ] ; then |
|---|
| 92 | /usr/X11/bin/fc-cache & |
|---|
| 93 | fi |
|---|
| 94 | fi |
|---|
| 95 | |
|---|
| 96 | if [ -x /usr/X11/lib/X11/xinit/privileged_startx ] ; then |
|---|
| 97 | # Don't push this into the background becasue it can cause |
|---|
| 98 | # a race to create /tmp/.X11-unix |
|---|
| 99 | /usr/X11/lib/X11/xinit/privileged_startx |
|---|
| 100 | fi |
|---|
| 101 | |
|---|
| 102 | if [ x`defaults read org.x.X11 no_auth` = x0 ] ; then |
|---|
| 103 | enable_xauth=1 |
|---|
| 104 | else |
|---|
| 105 | enable_xauth=0 |
|---|
| 106 | fi |
|---|
| 107 | |
|---|
| 108 | if [ x`defaults read org.x.X11 nolisten_tcp` = x1 ] ; then |
|---|
| 109 | defaultserverargs="$defaultserverargs -nolisten tcp" |
|---|
| 110 | fi |
|---|
| 111 | |
|---|
| 112 | for ((d=0; ; d++)) ; do |
|---|
| 113 | [[ -e /tmp/.X$d-lock ]] || break |
|---|
| 114 | done |
|---|
| 115 | defaultdisplay=":$d" |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | whoseargs="client" |
|---|
| 123 | while [ x"$1" != x ]; do |
|---|
| 124 | case "$1" in |
|---|
| 125 | # '' required to prevent cpp from treating "/*" as a C comment. |
|---|
| 126 | /''*|\./''*) |
|---|
| 127 | if [ "$whoseargs" = "client" ]; then |
|---|
| 128 | if [ x"$clientargs" = x ]; then |
|---|
| 129 | client="$1" |
|---|
| 130 | else |
|---|
| 131 | clientargs="$clientargs $1" |
|---|
| 132 | fi |
|---|
| 133 | else |
|---|
| 134 | if [ x"$serverargs" = x ]; then |
|---|
| 135 | server="$1" |
|---|
| 136 | else |
|---|
| 137 | serverargs="$serverargs $1" |
|---|
| 138 | fi |
|---|
| 139 | fi |
|---|
| 140 | ;; |
|---|
| 141 | --) |
|---|
| 142 | whoseargs="server" |
|---|
| 143 | ;; |
|---|
| 144 | *) |
|---|
| 145 | if [ "$whoseargs" = "client" ]; then |
|---|
| 146 | clientargs="$clientargs $1" |
|---|
| 147 | else |
|---|
| 148 | # display must be the FIRST server argument |
|---|
| 149 | if [ x"$serverargs" = x ] && \ |
|---|
| 150 | expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then |
|---|
| 151 | display="$1" |
|---|
| 152 | else |
|---|
| 153 | serverargs="$serverargs $1" |
|---|
| 154 | fi |
|---|
| 155 | fi |
|---|
| 156 | ;; |
|---|
| 157 | esac |
|---|
| 158 | shift |
|---|
| 159 | done |
|---|
| 160 | |
|---|
| 161 | # process client arguments |
|---|
| 162 | if [ x"$client" = x ]; then |
|---|
| 163 | client=$defaultclient |
|---|
| 164 | |
|---|
| 165 | # if no client arguments either, use rc file instead |
|---|
| 166 | if [ x"$clientargs" = x ]; then |
|---|
| 167 | if [ -f "$userclientrc" ]; then |
|---|
| 168 | client=$userclientrc |
|---|
| 169 | elif [ -f "$sysclientrc" ]; then |
|---|
| 170 | client=$sysclientrc |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | fi |
|---|
| 178 | |
|---|
| 179 | clientargs=$defaultclientargs |
|---|
| 180 | fi |
|---|
| 181 | fi |
|---|
| 182 | |
|---|
| 183 | # process server arguments |
|---|
| 184 | if [ x"$server" = x ]; then |
|---|
| 185 | server=$defaultserver |
|---|
| 186 | |
|---|
| 187 | # if no server arguments or display either, use defaults |
|---|
| 188 | if [ x"$serverargs" = x -a x"$display" = x ]; then |
|---|
| 189 | # For compatibility reasons, only use xserverrc if there were no server command line arguments |
|---|
| 190 | if [ -f "$userserverrc" ]; then |
|---|
| 191 | server=$userserverrc |
|---|
| 192 | elif [ -f "$sysserverrc" ]; then |
|---|
| 193 | server=$sysserverrc |
|---|
| 194 | fi |
|---|
| 195 | |
|---|
| 196 | serverargs=$defaultserverargs |
|---|
| 197 | display=$defaultdisplay |
|---|
| 198 | fi |
|---|
| 199 | fi |
|---|
| 200 | |
|---|
| 201 | if [ x"$enable_xauth" = x1 ] ; then |
|---|
| 202 | if [ x"$XAUTHORITY" = x ]; then |
|---|
| 203 | XAUTHORITY=$HOME/.Xauthority |
|---|
| 204 | export XAUTHORITY |
|---|
| 205 | fi |
|---|
| 206 | |
|---|
| 207 | removelist= |
|---|
| 208 | |
|---|
| 209 | # set up default Xauth info for this machine |
|---|
| 210 | case `uname` in |
|---|
| 211 | Linux*) |
|---|
| 212 | if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then |
|---|
| 213 | hostname=`hostname -f` |
|---|
| 214 | else |
|---|
| 215 | hostname=`hostname` |
|---|
| 216 | fi |
|---|
| 217 | ;; |
|---|
| 218 | *) |
|---|
| 219 | hostname=`hostname` |
|---|
| 220 | ;; |
|---|
| 221 | esac |
|---|
| 222 | |
|---|
| 223 | authdisplay=${display:-:0} |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | if [ -r /dev/urandom ]; then |
|---|
| 228 | mcookie=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | hexdump -e \\"%08x\\"` |
|---|
| 229 | else |
|---|
| 230 | mcookie=`dd if=/dev/random bs=16 count=1 2>/dev/null | hexdump -e \\"%08x\\"` |
|---|
| 231 | fi |
|---|
| 232 | |
|---|
| 233 | if test x"$mcookie" = x; then |
|---|
| 234 | echo "Couldn't create cookie" |
|---|
| 235 | exit 1 |
|---|
| 236 | fi |
|---|
| 237 | dummy=0 |
|---|
| 238 | |
|---|
| 239 | # create a file with auth information for the server. ':0' is a dummy. |
|---|
| 240 | xserverauthfile=$HOME/.serverauth.$$ |
|---|
| 241 | trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP KILL BUS TERM |
|---|
| 242 | xauth -q -f "$xserverauthfile" << EOF |
|---|
| 243 | add :$dummy . $mcookie |
|---|
| 244 | EOF |
|---|
| 245 | serverargs=${serverargs}" -auth '"${xserverauthfile}"'" |
|---|
| 246 | |
|---|
| 247 | # now add the same credentials to the client authority file |
|---|
| 248 | # if '$displayname' already exists do not overwrite it as another |
|---|
| 249 | # server man need it. Add them to the '$xserverauthfile' instead. |
|---|
| 250 | for displayname in $authdisplay $hostname$authdisplay; do |
|---|
| 251 | authcookie=`xauth list "$displayname" \ |
|---|
| 252 | | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p"` 2>/dev/null; |
|---|
| 253 | if [ "z${authcookie}" = "z" ] ; then |
|---|
| 254 | xauth -q << EOF |
|---|
| 255 | add $displayname . $mcookie |
|---|
| 256 | EOF |
|---|
| 257 | removelist="$displayname $removelist" |
|---|
| 258 | else |
|---|
| 259 | dummy=$(($dummy+1)); |
|---|
| 260 | xauth -q -f "$xserverauthfile" << EOF |
|---|
| 261 | add :$dummy . $authcookie |
|---|
| 262 | EOF |
|---|
| 263 | fi |
|---|
| 264 | done |
|---|
| 265 | fi |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | eval xinit "$client" $clientargs -- "$server" $display $serverargs |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | if [ x"$enable_xauth" = x1 ] ; then |
|---|
| 278 | if [ x"$removelist" != x ]; then |
|---|
| 279 | xauth remove $removelist |
|---|
| 280 | fi |
|---|
| 281 | if [ x"$xserverauthfile" != x ]; then |
|---|
| 282 | rm -f "$xserverauthfile" |
|---|
| 283 | fi |
|---|
| 284 | fi |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|