]> git.xonotic.org Git - xonotic/xonotic.git/blob - xonotic-linux-sdl.sh
Enable menu hotfix pk3
[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 # prefer locally built binary if available (see: Makefile)
21 xonotic="xonotic-local-${mode}"
22 [ -x "$xonotic" ] || xonotic="xonotic-${arch}-${mode}"
23 echo "Executing: $xonotic ${@}"
24
25 set -- ./${xonotic} "${@}"
26
27 xserver=
28 xlayout=
29
30 setdisplay()
31 {
32         VALUE=$1
33         VALUE=${VALUE#\"}
34         VALUE=${VALUE%\"}
35         case "$VALUE" in
36                 :*)
37                         ;;
38                 *)
39                         VALUE=:$VALUE
40                         ;;
41         esac
42         VALUE="$VALUE/"
43         xserver="${VALUE%%/*}"
44         xserver=${xserver#:}
45         xlayout=${VALUE#*/}
46         xlayout=${xlayout%/}
47 }
48
49 # now how do we execute it?
50 if [ -r ~/.xonotic/data/config.cfg ]; then
51         while read -r CMD KEY VALUE; do
52                 case "$CMD:$KEY" in
53                         seta:vid_x11_display)
54                                 setdisplay "$VALUE"
55                                 ;;
56                 esac
57         done < ~/.xonotic/data/config.cfg
58 fi
59
60 m=0
61 for X in "$@"; do
62         case "$m:$X" in
63                 0:+vid_x11_display)
64                         m=1
65                         ;;
66                 0:+vid_x11_display\ *)
67                         setdisplay "${X#+vid_x11_display }"
68                         ;;
69                 1:*)
70                         setdisplay "$X"
71                         m=0
72                         ;;
73                 *)
74                         ;;
75         esac
76 done
77
78 case "$xserver" in
79         '')
80                 ;;
81         *[!0-9]*)
82                 echo "Not using display ':$xserver': evil characters"
83                 ;;
84         *)
85                 msg=
86                 lf='
87 '
88                 prefix=
89
90                 # check for a listening X server on that socket
91                 if netstat -nl | grep -F " /tmp/.X11-unix/X$xserver" >/dev/null; then
92                         # X server already exists
93                         export DISPLAY=:$xserver
94                         prefix="DISPLAY=:$xserver "
95                         msg=$msg$lf"- Running Xonotic on already existing display :$xserver"
96                 else
97                         set -- startx "$@" -fullscreen -- ":$xserver"
98                         msg=$msg$lf"- Running Xonotic on a newly created X server :$xserver."
99                         case "$xlayout" in
100                                 '')
101                                         ;;
102                                 *[!A-Za-z0-9]*)
103                                         echo >&2 "Not using layout '$xlayout': evil characters"
104                                         xlayout=
105                                         ;;
106                                 *)
107                                         set -- "$@" -layout "$xlayout"
108                                         msg=$msg$lf"- Using the ServerLayout section named $xlayout."
109                                         ;;
110                         esac
111                 fi
112
113                 echo "X SERVER OVERRIDES IN EFFECT:$msg"
114                 echo
115                 echo "Resulting command line:"
116                 echo "  $prefix$*"
117                 echo
118                 echo "To undo these overrides, edit ~/.xonotic/data/config.cfg and remove the line"
119                 echo "starting with 'seta vid_x11_display'."
120                 echo
121                 echo
122                 ;;
123 esac
124
125 exec "$@"