new cvar vid_x11_display for use by nexuiz-linux-*.sh
[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 "$(uname -m)" in
10   x86_64)       nexuiz="nexuiz-linux-x86_64-glx" ;;
11   *)            nexuiz="nexuiz-linux-686-glx" ;;
12 esac
13
14 set -- ./${nexuiz} "${@}"
15
16 xserver=
17 xlayout=
18
19 # now how do we execute it?
20 if [ -r ~/.nexuiz/data/config.cfg ]; then
21         while read -r CMD KEY VALUE; do
22                 VALUE=${VALUE#\"}
23                 VALUE=${VALUE%\"}
24                 case "$CMD:$KEY" in
25                         seta:vid_x11_display)
26                                 case "$VALUE" in
27                                         :*)
28                                                 ;;
29                                         *)
30                                                 VALUE=:$VALUE
31                                                 ;;
32                                 esac
33                                 VALUE="$VALUE "
34                                 xserver="${VALUE%% *}"
35                                 xserver=${xserver#:}
36                                 xlayout=${VALUE#* }
37                                 xlayout=${xlayout% }
38                                 ;;
39                 esac
40         done < ~/.nexuiz/data/config.cfg
41 fi
42
43 case "$xserver" in
44         '')
45                 ;;
46         *[!0-9]*)
47                 echo "Not using display ':$xserver': evil characters"
48                 ;;
49         *)
50                 msg=
51                 lf='
52 '
53                 prefix=
54
55                 # check for a listening X server on that socket
56                 if netstat -nl | grep -F " /tmp/.X11-unix/X$xserver" >/dev/null; then
57                         # X server already exists
58                         export DISPLAY=:$xserver
59                         prefix="DISPLAY=:$xserver "
60                         msg=$msg$lf"- Running Nexuiz on already existing display :$xserver"
61                 else
62                         set -- startx "$@" -- ":$xserver"
63                         msg=$msg$lf"- Running Nexuiz on a newly created X server :$xserver."
64                         case "$xlayout" in
65                                 '')
66                                         ;;
67                                 *[!A-Za-z0-9]*)
68                                         echo >&2 "Not using layout '$xlayout': evil characters"
69                                         xlayout=
70                                         ;;
71                                 *)
72                                         set -- "$@" -layout "$xlayout"
73                                         msg=$msg$lf"- Using the ServerLayout section named $xlayout."
74                                         ;;
75                         esac
76                 fi
77
78                 echo "X SERVER OVERRIDES IN EFFECT:$msg"
79                 echo
80                 echo "Resulting command line:"
81                 echo "  $prefix$*"
82                 echo
83                 echo "To undo these overrides, edit ~/.nexuiz/data/config.cfg and remove the line"
84                 echo "starting with 'seta vid_x11_display'."
85                 echo
86                 echo
87                 ;;
88 esac
89
90 exec "$@"