]> de.git.xonotic.org Git - xonotic/xonotic.git/blob - xonotic-linux-sdl.sh
Fix macOS SDL2 framework permissions
[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}" || exit 1
8
9 case "${0##*/}" in
10   *dedicated*)  mode="dedicated" ;;
11   *)            mode="sdl" ;;
12 esac
13
14 case $(uname):$(uname -m) in
15   Linux:x86_64)  arch="linux64" ;;
16   *)             arch="local"   ;;  # Not pre-built but you can build your own
17 esac
18
19 # prefer locally built binary if available (see: Makefile)
20 xonotic="xonotic-local-${mode}"
21 [ -x "$xonotic" ] || xonotic="xonotic-${arch}-${mode}"
22 echo "Executing: $xonotic ${*}"
23
24 set -- ./${xonotic} "${@}"
25
26 xserver=
27 xlayout=
28
29 setdisplay()
30 {
31         VALUE=$1
32         VALUE=${VALUE#\"}
33         VALUE=${VALUE%\"}
34         case "$VALUE" in
35                 :*)
36                         ;;
37                 *)
38                         VALUE=:$VALUE
39                         ;;
40         esac
41         VALUE="$VALUE/"
42         xserver="${VALUE%%/*}"
43         xserver=${xserver#:}
44         xlayout=${VALUE#*/}
45         xlayout=${xlayout%/}
46 }
47
48 # now how do we execute it?
49 if [ -r ~/.xonotic/data/config.cfg ]; then
50         while read -r CMD KEY VALUE; do
51                 case "$CMD:$KEY" in
52                         seta:vid_x11_display)
53                                 setdisplay "$VALUE"
54                                 ;;
55                 esac
56         done < ~/.xonotic/data/config.cfg
57 fi
58
59 m=0
60 for X in "$@"; do
61         case "$m:$X" in
62                 0:+vid_x11_display)
63                         m=1
64                         ;;
65                 0:+vid_x11_display\ *)
66                         setdisplay "${X#+vid_x11_display }"
67                         ;;
68                 1:*)
69                         setdisplay "$X"
70                         m=0
71                         ;;
72                 *)
73                         ;;
74         esac
75 done
76
77 case "$xserver" in
78         '')
79                 ;;
80         *[!0-9]*)
81                 echo "Not using display ':$xserver': evil characters"
82                 ;;
83         *)
84                 msg=
85                 lf='
86 '
87                 prefix=
88
89                 # check for a listening X server on that socket
90                 if netstat -nl | grep -F " /tmp/.X11-unix/X$xserver" >/dev/null; then
91                         # X server already exists
92                         export DISPLAY=:$xserver
93                         prefix="DISPLAY=:$xserver "
94                         msg=$msg$lf"- Running Xonotic on already existing display :$xserver"
95                 else
96                         set -- startx "$@" -fullscreen -- ":$xserver"
97                         msg=$msg$lf"- Running Xonotic on a newly created X server :$xserver."
98                         case "$xlayout" in
99                                 '')
100                                         ;;
101                                 *[!A-Za-z0-9]*)
102                                         echo >&2 "Not using layout '$xlayout': evil characters"
103                                         xlayout=
104                                         ;;
105                                 *)
106                                         set -- "$@" -layout "$xlayout"
107                                         msg=$msg$lf"- Using the ServerLayout section named $xlayout."
108                                         ;;
109                         esac
110                 fi
111
112                 echo "X SERVER OVERRIDES IN EFFECT:$msg"
113                 echo
114                 echo "Resulting command line:"
115                 echo "  $prefix$*"
116                 echo
117                 echo "To undo these overrides, edit ~/.xonotic/data/config.cfg and remove the line"
118                 echo "starting with 'seta vid_x11_display'."
119                 echo
120                 echo
121                 ;;
122 esac
123
124 if which "$1" > /dev/null
125 then
126         exec "$@"
127 else
128         echo "Could not find $1 to exec"
129         if [ "$arch" = "local" ]
130         then
131                 printf "%b\n%b\n" "Xonotic does not currently provide pre-built $(uname):$(uname -m) builds, please compile one using make" \
132                         "More info is available at \e[1;36mhttps://gitlab.com/xonotic/xonotic/-/wikis/Compiling\e[m"
133         fi
134 fi