3 # abort on error(non-0 return code) and abort on unset variable
6 # refuse to run on Windows' MINGW due to symlinking issues
7 # `ln -s "$PWD" data/xonotic-data.pk3dir` seems to not work in any form
8 # even with fully relative paths or `ln -s ../ xonotic-data.pk3dir`
11 MINGW*) printf "%s\n%s\n" "This file is not suitable for Windows' MINGW" \
12 "without modifications due to the lack of proper symlink support"; exit 1 ;;
15 printf "Testing for dependencies\n"
16 # command -q / --quiet one day? :(
17 command -V awk > /dev/null
18 command -V chmod > /dev/null
19 command -V git > /dev/null
20 command -V grep > /dev/null
21 command -V make > /dev/null
22 command -V md5sum > /dev/null
23 command -V mkdir > /dev/null
24 command -V mktemp > /dev/null
25 command -V rm > /dev/null
26 command -V rmdir > /dev/null
27 command -V sed > /dev/null
28 command -V tee > /dev/null
29 command -V test > /dev/null
30 command -V true > /dev/null
31 command -V printf > /dev/null
32 command -V wget > /dev/null
33 printf "All dependencies found\n"
36 # check if a file's creation date is today
37 if [ "$(stat -c '%y' "$1" | cut -d ' ' -f 1)" = "$(date -I)" ]
39 #echo "$1 was created today"
42 #echo "$1 was not created today"
48 # allow for error return codes in this function as this may be ran on interrupt
49 # right after starting where all files to clean up don't exist yet
53 trap - EXIT INT QUIT TERM
55 # Few files' removal has been disabled for file reuse
56 # It's possible to get rate limited with enough testing
59 rm data/darkplaces_history.txt
60 rm data/xonotic-data.pk3dir
61 #rm data/stormkeep.pk3
62 rm data/data/defaultSVQC.cfg
63 rm data/data/hits---1.plot
64 rm data/data/hits---2.plot
65 rm data/data/hits---3.plot
66 rm data/data/notifications_dump.cfg
67 rm data/data/server.db
69 #rm data/maps/_init.bsp
70 #rm data/maps/stormkeep.mapinfo
71 #rm data/maps/stormkeep.waypoints
72 #rm data/maps/stormkeep.waypoints.cache
77 trap "hashtestcleanup" EXIT INT QUIT TERM
79 # cd xonotic-data.pk3dir
80 cd "$(dirname "$0")/../../"
86 # if xonotic-data.pk3dir/data/xonotic-data.pk3dir isn't a symlink then link it
87 if [ -e data/xonotic-data.pk3dir ]
89 if ! [ -L data/xonotic-data.pk3dir ]
90 then # file exists but it's not a symlink, replace it
91 if [ -d data/xonotic-data.pk3dir ]
93 rmdir data/xonotic-data.pk3dir
94 ln -s "$PWD" data/xonotic-data.pk3dir
96 rm data/xonotic-data.pk3dir
97 ln -s "$PWD" data/xonotic-data.pk3dir
99 else # it is a symlink, verify where it points
100 if [ "$(realpath data/xonotic-data.pk3dir)" != "$PWD" ]
101 then # wrong place, recreate it
102 rm data/xonotic-data.pk3dir
103 ln -s "$PWD" data/xonotic-data.pk3dir
106 else # no file exists there
107 ln -s "$PWD" data/xonotic-data.pk3dir
112 printf "%s\n" "MAKEFLAGS=$MAKEFLAGS"
113 export CC="gcc -pipe"
115 # precompiled binary is executable and its creation date is today
116 if [ -x "$TMPDIR/gmqcc-bin" ] && createdtoday "$TMPDIR/gmqcc-bin"
118 export QCC="$TMPDIR/gmqcc-bin"
119 else # previously compiled is executable and its creation date is today
120 if [ -x "$TMPDIR/gmqcc/gmqcc" ] && createdtoday "$TMPDIR/gmqcc/gmqcc"
122 export QCC="$TMPDIR/gmqcc/gmqcc"
123 else # nothing reusable exists
124 # prefer a precompiled binary
125 if wget -nv https://beta.xonotic.org/pipeline-bin/gmqcc -O "$TMPDIR/gmqcc-bin"
127 export QCC="$TMPDIR/gmqcc-bin"
130 if [ -d "$TMPDIR/gmqcc" ]
137 git clone --depth=1 --branch=main https://gitlab.com/xonotic/gmqcc.git "$TMPDIR/gmqcc"
139 make -C "$TMPDIR/gmqcc" || exit 1
140 export QCC="$TMPDIR/gmqcc/gmqcc"
145 # Makefile: don't complain about lack of tags (fetching them is slow)
146 export QCCFLAGS_WATERMARK=gitlab_pipeline
147 # Makefile: don't compress anything or complain about lack of zip program
151 if [ "$(uname):$(uname -m)" = "Linux:x86_64" ] && [ -x "$TMPDIR/xonotic-linux64-dedicated" ] && createdtoday "$TMPDIR/xonotic-linux64-dedicated"
152 then # precompiled binary is executable and its creation date is today
153 export ENGINE="$TMPDIR/xonotic-linux64-dedicated"
155 if [ -x "$TMPDIR/darkplaces/darkplaces-dedicated" ] && createdtoday "$TMPDIR/darkplaces/darkplaces-dedicated"
156 then # previously compiled is executable and its creation date is today
157 export ENGINE="$TMPDIR/darkplaces/darkplaces-dedicated -xonotic"
158 else # nothing reusable exists
159 # prefer a precompiled binary
160 if [ "$(uname):$(uname -m)" = "Linux:x86_64" ] && wget -nv https://beta.xonotic.org/pipeline-bin/xonotic-linux64-dedicated -O "$TMPDIR/xonotic-linux64-dedicated"
162 export ENGINE="$TMPDIR/xonotic-linux64-dedicated"
165 if [ -d "$TMPDIR/darkplaces" ]
167 cd "$TMPDIR/darkplaces"
172 git clone --depth=1 https://gitlab.com/xonotic/darkplaces.git "$TMPDIR/darkplaces"
174 make -C "$TMPDIR/darkplaces" sv-release || exit 1
175 export ENGINE="$TMPDIR/darkplaces/darkplaces-dedicated -xonotic"
179 export ENGINE="$ENGINE -noconfig -nohome"
185 createdtoday "data/maps/_init.bsp" \
186 || wget -nv -O data/maps/_init.bsp https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/_init/_init.bsp
190 printf "%s\n" "$LINE"
191 [ "$LINE" = "All tests OK" ] && PASS=1
192 done < <(${ENGINE} +developer 1 +map _init +sv_cmd runtest +wait +quit)
193 test "$PASS" = "1" || { printf 'sv_cmd runtest failed!'; exit 1; }
195 ${ENGINE} +map _init +sv_cmd dumpnotifs +wait +quit
196 diff notifications.cfg data/data/notifications_dump.cfg ||
197 { printf "Please update notifications.cfg using \`dumpnotifs\`!"; exit 1; }
199 createdtoday "data/stormkeep.pk3" \
200 || wget -nv -O data/stormkeep.pk3 https://beta.xonotic.org/pipeline-bin/stormkeep.pk3
201 createdtoday "data/maps/stormkeep.mapinfo" \
202 || wget -nv -O data/maps/stormkeep.mapinfo https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.mapinfo
203 createdtoday "data/maps/stormkeep.waypoints" \
204 || wget -nv -O data/maps/stormkeep.waypoints https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints
205 createdtoday "data/maps/stormkeep.waypoints.cache" \
206 || wget -nv -O data/maps/stormkeep.waypoints.cache https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints.cache
211 # find the line with expected hash from .gitlab-ci.yml, extract the hash and remove carriage return
212 EXPECT="$(grep 'EXPECT=' './.gitlab-ci.yml' | cut -d '=' -f 2 | tr -d $'\r')"
215 HASH=$(${ENGINE} +exec serverbench.cfg \
218 | grep -v '^:gamestart:' \
219 | grep -v '^:anticheat:' \
220 | md5sum | awk '{ print $1 }')
224 if [ "$HASH" = "$EXPECT" ]
225 then # green ok print
226 printf "\033[32m%s\033[0m\n" "expected: $EXPECT"
227 printf "\033[32m%s\033[0m\n" " actual: $HASH"
228 printf "\033[32m%s\033[0m\n" "hashes match"
230 else # red error print
231 printf "\033[32m%s\033[0m\n" "expected: $EXPECT"
232 printf "\033[32m%s\033[0m\n" " actual: $HASH"
233 printf "\033[31m%s\033[0m\n" "!!! ERROR: HASHES DO NOT MATCH !!!"