]> icculus.org git repositories - divverent/nexuiz.git/blob - nexuiz-linux-glx.sh
improve fallback code
[divverent/nexuiz.git] / nexuiz-linux-glx.sh
1 #!/bin/sh
2
3 path=`dirname "${0}"`
4 link=`readlink "${0}"`
5
6 [ -n "${link}" ] && path=`dirname "${link}"`
7 cd "${path}"
8
9 case "${0##*/}" in
10   *sdl*)        mode="sdl" ;;
11   *)            mode="glx" ;;
12 esac
13
14 case "$(uname -m)" in
15   x86_64)       arch="x86_64" ;;
16   *)            arch="686" ;;
17 esac
18
19 nexuiz="nexuiz-linux-${arch}-${mode}"
20
21 set -- ./${nexuiz} "${@}"
22
23 xserver=
24 xlayout=
25
26 setdisplay()
27 {
28         VALUE=$1
29         VALUE=${VALUE#\"}
30         VALUE=${VALUE%\"}
31         case "$VALUE" in
32                 :*)
33                         ;;
34                 *)
35                         VALUE=:$VALUE
36                         ;;
37         esac
38         VALUE="$VALUE/"
39         xserver="${VALUE%%/*}"
40         xserver=${xserver#:}
41         xlayout=${VALUE#*/}
42         xlayout=${xlayout%/}
43 }
44
45 # now how do we execute it?
46 if [ -r ~/.nexuiz/data/config.cfg ]; then
47         while read -r CMD KEY VALUE; do
48                 case "$CMD:$KEY" in
49                         seta:vid_x11_display)
50                                 setdisplay "$VALUE"
51                                 ;;
52                 esac
53         done < ~/.nexuiz/data/config.cfg
54 fi
55
56 m=0
57 for X in "$@"; do
58         case "$m:$X" in
59                 0:+vid_x11_display)
60                         m=1
61                         ;;
62                 0:+vid_x11_display\ *)
63                         setdisplay "${X#+vid_x11_display }"
64                         ;;
65                 1:*)
66                         setdisplay "$X"
67                         m=0
68                         ;;
69                 *)
70                         ;;
71         esac
72 done
73
74 case "$xserver" in
75         '')
76                 ;;
77         *[!0-9]*)
78                 echo "Not using display ':$xserver': evil characters"
79                 ;;
80         *)
81                 msg=
82                 lf='
83 '
84                 prefix=
85
86                 # check for a listening X server on that socket
87                 if netstat -nl | grep -F " /tmp/.X11-unix/X$xserver" >/dev/null; then
88                         # X server already exists
89                         export DISPLAY=:$xserver
90                         prefix="DISPLAY=:$xserver "
91                         msg=$msg$lf"- Running Nexuiz on already existing display :$xserver"
92                 else
93                         set -- startx "$@" -fullscreen -- ":$xserver"
94                         msg=$msg$lf"- Running Nexuiz on a newly created X server :$xserver."
95                         case "$xlayout" in
96                                 '')
97                                         ;;
98                                 *[!A-Za-z0-9]*)
99                                         echo >&2 "Not using layout '$xlayout': evil characters"
100                                         xlayout=
101                                         ;;
102                                 *)
103                                         set -- "$@" -layout "$xlayout"
104                                         msg=$msg$lf"- Using the ServerLayout section named $xlayout."
105                                         ;;
106                         esac
107                 fi
108
109                 echo "X SERVER OVERRIDES IN EFFECT:$msg"
110                 echo
111                 echo "Resulting command line:"
112                 echo "  $prefix$*"
113                 echo
114                 echo "To undo these overrides, edit ~/.nexuiz/data/config.cfg and remove the line"
115                 echo "starting with 'seta vid_x11_display'."
116                 echo
117                 echo
118                 ;;
119 esac
120
121 exec "$@"