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