]> git.xonotic.org Git - xonotic/xonotic.git/blob - all
322764b8c9df4d2dd2021364042309866e610c43
[xonotic/xonotic.git] / all
1 #!/bin/sh
2 # vim: filetype=zsh
3
4 set -e
5
6 # I use this in EVERY shell script ;)
7 LF="
8 "
9
10 d00=`pwd`
11 while ! [ -f ./all ]; do
12         if [ x"`pwd`" = x"/" ]; then
13                 echo "Cannot find myself."
14                 echo "Please run this script with the working directory inside a Xonotic checkout."
15                 exit 1
16         fi
17         cd ..
18 done
19 export d0=`pwd`
20 SELF="$d0/all"
21
22 # If we are on WINDOWS:
23 case "$0" in
24         all|*/all)
25                 case "`uname`" in
26                         MINGW*|Win*)
27                                 # Windows hates users. So this script has to copy itself elsewhere first...
28                                 cp "$SELF" ../all.xonotic.sh
29                                 export WE_HATE_OUR_USERS=1
30                                 exec ../all.xonotic.sh "$@"
31                                 ;;
32                 esac
33                 ;;
34 esac
35
36 msg()
37 {
38         echo >&2 "\e[1m$*\e[m"
39 }
40
41 self=`git hash-object "$SELF"`
42 checkself()
43 {
44         self_new=`git hash-object "$SELF"`
45         if [ x"$self" != x"$self_new" ]; then
46                 msg "./all has changed."
47                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
48                         msg "Rerunning the requested operation to make sure."
49                         export XONOTIC_FORBID_RERUN_ALL=1
50                         exec "$SELF" "$@"
51                 else
52                         msg "Please try $SELF update, and then retry your requested operation."
53                         exit 1
54                 fi
55         fi
56         return 0
57 }
58
59 verbose()
60 {
61         msg "+ $*"
62         "$@"
63 }
64
65 visible_repo_name()
66 {
67         case "$1" in
68                 .)
69                         echo "the root directory"
70                         ;;
71                 *)
72                         echo "\"$1\""
73                         ;;
74         esac
75 }
76
77 check_mergeconflict()
78 {
79         if git ls-files -u | grep ' 1   '; then
80                 echo
81                 echo "MERGE CONFLICT."
82                 echo "change into the \"$1\" project directory, and then:"
83                 echo "- edit the files mentioned above with your favorite editor,"
84                 echo "  and fix the conflicts (marked with <<<<<<< blocks)"
85                 echo "- for binary files, you can select the files using"
86                 echo "  git checkout --ours or git checkout --theirs"
87                 echo "- when done with a file, 'git add' the file"
88                 echo "- when done, 'git commit'"
89                 echo
90                 exit 1
91         fi
92 }
93
94 yesno()
95 {
96         yesno=
97         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
98                 eval "$2"
99                 echo "$1"
100                 IFS= read -r yesno
101         done
102         [ x"$yesno" = x"y" ]
103 }
104
105 enter()
106 {
107         $2 cd "$1" || exit 1
108         check_mergeconflict "$1"
109 }
110
111 repos_urls="
112 .                             |                                                   | master      |
113 data/xonotic-data.pk3dir      |                                                   | master      |
114 data/xonotic-maps.pk3dir      |                                                   | master      |
115 data/xonotic-music.pk3dir     |                                                   | master      |
116 data/xonotic-nexcompat.pk3dir |                                                   | master      | no
117 mediasource                   |                                                   | master      | no
118 darkplaces                    |                                                   | div0-stable | svn
119 fteqcc                        | git://github.com/Blub/qclib.git                   | master      |
120 div0-gittools                 |                                                   | master      | no
121 netradiant                    |                                                   | master      |
122 "
123 # todo: in darkplaces, change repobranch to div0-stable
124
125 repos=`echo "$repos_urls" | grep . | cut -d '|' -f 1 | tr -d ' '`
126
127 base=`git config remote.origin.url`
128 case "$base" in
129         */xonotic.git)
130                 base=${base%xonotic.git}
131                 ;;
132         *)
133                 echo "The main repo is not xonotic.git, what have you done?"
134                 exit 1
135                 ;;
136 esac
137
138 repourl()
139 {
140         repo_t=`echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 2 | tr -d ' '`
141         if [ -n "$repo_t" ]; then
142                 case "$repo_t" in
143                         *://*)
144                                 echo "$repo_t"
145                                 ;;
146                         *)
147                                 echo "$base$repo_t"
148                                 ;;
149                 esac
150         else
151                 if [ x"$1" = x"." ]; then
152                         echo "$base""xonotic.git"
153                 else
154                         echo "$base${1##*/}.git"
155                 fi
156         fi
157 }
158
159 repobranch()
160 {
161         repo_t=`echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 3 | tr -d ' '`
162         if [ -n "$repo_t" ]; then
163                 echo "$repo_t"
164         else
165                 echo "master"
166         fi
167 }
168
169 repoflags()
170 {
171         echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 4 | tr -d ' '
172 }
173
174 listrepos()
175 {
176         for d in $repos; do
177                 p="${d%dir}"
178                 f="`repoflags "$d"`"
179                 # if we have the dir, always keep it
180                 if [ -d "$d" ]; then
181                         msg "Repository $d enabled because it already exists"
182                         echo "$d"
183                         continue
184                 fi
185                 # if .yes file exists, always keep it
186                 if [ -f "$d.yes" ]; then
187                         msg "Repository $d enabled by a .yes file"
188                         echo "$d"
189                         continue
190                 fi
191                 # if we have .no file, skip
192                 if [ -f "$d.no" ]; then
193                         msg "Repository $d disabled by a .no file, delete $p.no to enable"
194                         continue
195                 fi
196                 # if we have matching pk3, skip
197                 if [ x"$p" != x"$d" ] && [ -f "$p" ]; then
198                         msg "Repository $d disabled by matching .pk3 file, delete $p or create $d.yes to enable"
199                         continue
200                 fi
201                 # if "no" flag is set, skip
202                 case ",$f," in
203                         *,no,*)
204                                 msg "Repository $d disabled by default, create $d.yes to enable"
205                                 continue
206                                 ;;
207                 esac
208                 # default: enable
209                 msg "Repository $d enabled by default"
210                 echo "$d"
211         done
212 }
213
214 repos=`listrepos`
215
216 if [ "$#" = 0 ]; then
217         set -- help
218 fi
219 cmd=$1
220 shift
221
222 fix_upstream_rebase()
223 {
224         if [ -z "$r_me" ] || [ -z "$r_other" ]; then
225                 return
226         fi
227         r_base=`git merge-base "$r_me" "$r_other"`
228
229         # no merge-base? upstream did filter-branch
230         if [ -n "$r_base" ]; then
231                 # otherwise, check if the two histories are "similar"
232                 r_l_me=`git log --pretty="format:%s" "$r_other".."$r_me" | grep -v "^Merge" | sort -u`
233                 r_l_other=`git log --pretty="format:%s" "$r_me".."$r_other" | grep -v "^Merge" | sort -u`
234
235                 # heuristics: upstream rebase/filter-branch if more than 50% of the commits of one of the sides are in the other too
236                 r_lc_me=`echo "$r_l_me" | wc -l`
237                 r_lc_other=`echo "$r_l_other" | wc -l`
238                 r_lc_together=`{ echo "$r_l_me"; echo "$r_l_other"; } | sort -u | wc -l`
239                 r_lc_same=$(($r_lc_me + $r_lc_other - $r_lc_together))
240
241                 if [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_me )) ] || [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_other )) ]; then
242                         if yesno "Probable upstream rebase detected, automatically fix?" 'git log --oneline --graph --date-order --left-right "$r_other"..."$r_me"'; then
243                                 git reset --hard "$r_me"
244                                 git pull --rebase
245                                 return 1
246                         fi
247                 fi
248         fi
249
250         return 0
251 }
252
253 fix_upstream_rebase_mergeok()
254 {
255         r_me=`git rev-parse --revs-only HEAD^1 2>/dev/null || true`
256         r_other=`git rev-parse --revs-only HEAD^2 2>/dev/null || true`
257         fix_upstream_rebase
258 }
259
260 fix_upstream_rebase_mergefail()
261 {
262         r_me=`git rev-parse --revs-only HEAD 2>/dev/null || true`
263         r_other=`git rev-parse --revs-only MERGE_HEAD 2>/dev/null || true`
264         fix_upstream_rebase
265 }
266
267 fix_git_config()
268 {
269         verbose git config core.autocrlf input
270         if [ -z "`git config push.default`" ]; then
271                 verbose git config push.default current # or is tracking better?
272         fi
273 }
274
275 mkzip()
276 {
277         archive=$1
278         shift
279         ziplist=`mktemp`
280         find "$@" -xtype f \( -executable -or -type l \) -print > "$ziplist"
281         7za a -tzip -mx=9 -x@"$ziplist" "$archive" "$@" || true
282         zip         -9y   -@<"$ziplist" "$archive"      || true
283         rm -f "$ziplist"
284 }
285
286 mkzip0()
287 {
288         zip -0y "$@"
289 }
290
291 case "$cmd" in
292         fix_upstream_rebase)
293                 for d in $repos; do
294                         enter "$d0/$d" verbose
295                         verbose fix_upstream_rebase_mergefail && verbose fix_upstream_rebase_mergeok
296                 done
297                 ;;
298         update|pull)
299                 allow_pull=true
300                 if [ x"$1" = x"-N" ]; then
301                         allow_pull=false
302                 fi
303                 for d in $repos; do
304                         url=`repourl "$d"`
305                         branch=`repobranch "$d"`
306                         if [ -d "$d0/$d" ]; then
307                                 if $allow_pull; then
308                                         enter "$d0/$d" verbose
309                                         fix_git_config
310                                         verbose git config remote.origin.url "$url"
311                                         verbose git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
312                                         r=`git symbolic-ref HEAD`
313                                         r=${r#refs/heads/}
314                                         if git config branch.$r.remote >/dev/null 2>&1; then
315                                                 if ! verbose git pull; then
316                                                         fix_upstream_rebase_mergefail || true
317                                                         check_mergeconflict "$d"
318                                                         echo "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
319                                                         read -r DUMMY
320                                                 else
321                                                         fix_upstream_rebase_mergeok || true
322                                                 fi
323                                         fi
324
325                                         cd "$d00"
326                                         checkself "$cmd" "$@"
327                                         cd "$d0/$d"
328                                         verbose git remote prune origin
329                                         cd "$d0"
330                                 fi
331                         else
332                                 verbose git clone "$url" "$d0/$d"
333                                 enter "$d0/$d" verbose
334                                 fix_git_config
335                                 if [ "$branch" != "master" ]; then
336                                         verbose git checkout --track -b "$branch" origin/"$branch"
337                                 fi
338                                 cd "$d0"
339                         fi
340                 done
341                 ;;
342         update-maps)
343                 misc/tools/xonotic-map-compiler-autobuild download
344                 ;;
345         checkout|switch)
346                 checkoutflags=
347                 if [ x"$1" = x"-f" ]; then
348                         checkoutflags=-f
349                         shift
350                 fi
351                 remote=$1
352                 branch=$2
353                 if [ -z "$branch" ]; then
354                         case "$remote" in
355                                 origin/*)
356                                         branch=${remote#origin/}
357                                         remote=origin
358                                         ;;
359                                 *)
360                                         branch=$remote
361                                         remote=origin
362                                         ;;
363                         esac
364                 fi
365                 exists=false
366                 for d in $repos; do
367                         enter "$d0/$d" verbose
368                         b=$branch
369                         if [ -n "$b" ] && git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
370                                 exists=true
371                                 verbose git checkout $checkoutflags "$b"
372                         elif [ -n "$b" ] && git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
373                                 exists=true
374                                 verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
375                         else
376                                 b=`repobranch "$d"`
377                                 if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
378                                         exists=true
379                                         verbose git checkout $checkoutflags "$b"
380                                 elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
381                                         exists=true
382                                         verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
383                                 else
384                                         echo "WTF? Not even branch $b doesn't exist in $d"
385                                         exit 1
386                                 fi
387                         fi
388                         cd "$d00"
389                         checkself "$cmd" "$@"
390                         cd "$d0"
391                 done
392                 if ! $exists; then
393                         echo "The requested branch was not found in any repository."
394                 fi
395                 exec "$SELF" branch
396                 ;;
397         branch)
398                 remote=$1
399                 branch=$2
400                 srcbranch=$3
401                 if [ -z "$branch" ]; then
402                         branch=$remote
403                         remote=origin
404                 fi
405                 if [ -z "$branch" ]; then
406                         for d in $repos; do
407                                 enter "$d0/$d"
408                                 r=`git symbolic-ref HEAD`
409                                 r=${r#refs/heads/}
410                                 echo "$d is at $r"
411                                 cd "$d0"
412                         done
413                 else
414                         for d in $repos; do
415                                 dv=`visible_repo_name "$d"`
416                                 enter "$d0/$d" verbose
417                                 if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
418                                         echo "Already having this branch in $dv."
419                                 else
420                                         if yesno "Branch in $dv?"; then
421                                                 if [ -n "$srcbranch" ]; then
422                                                         b=$srcbranch
423                                                 else
424                                                         b=origin/"`repobranch "$d"`"
425                                                         verbose git fetch origin || true
426                                                 fi
427                                                 # TODO do this without pushing
428                                                 verbose git checkout -b "$branch" "$b"
429                                                 verbose git config "branch.$branch.remote" "$remote"
430                                                 verbose git config "branch.$branch.merge" "refs/heads/$branch"
431                                         fi
432                                 fi
433                                 cd "$d0"
434                         done
435                         "$SELF" branch
436                 fi
437                 ;;
438         branches)
439                 for d in $repos; do
440                         cd "$d0/$d" # am in a pipe, shouldn't use enter
441                         git branch -a -v -v | cut -c 3- | sed "s/^(no branch)/(no_branch)/" | sed "s,^,$d ,"
442                         cd "$d0"
443                 done | {
444                         branches_list=
445                         # branches_repos_*=
446                         while read -r d BRANCH REV UPSTREAM TEXT; do
447                                 if [ x"$BRANCH" = x"`repobranch "$d"`" ]; then
448                                         continue
449                                 fi
450                                 case "$UPSTREAM" in
451                                         \[*)
452                                                 UPSTREAM=${UPSTREAM#\[}
453                                                 UPSTREAM=${UPSTREAM%\]}
454                                                 UPSTREAM=${UPSTREAM%:*}
455                                                 ;;
456                                         *)
457                                                 TEXT="$UPSTREAM $TEXT"
458                                                 UPSTREAM=
459                                                 ;;
460                                 esac
461                                 if [ x"$REV" = x"->" ]; then
462                                         continue
463                                 fi
464                                 BRANCH=${BRANCH#remotes/}
465                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
466                                 branches_list="$branches_list $BRANCH" # TEH SORT MAKEZ IT UNIEQ
467                                 eval "r=\$branches_repos_$ID"
468                                 case "$UPSTREAM" in
469                                         '')
470                                                 r="$r $d"
471                                                 ;;
472                                         *)
473                                                 r="$r $d:$UPSTREAM"
474                                                 ;;
475                                 esac
476                                 eval "branches_repos_$ID=\$r"
477                         done
478                         echo -n "$branches_list" | xargs -n 1 echo | sort -u | while IFS= read -r BRANCH; do
479                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
480                                 eval "r=\$branches_repos_$ID"
481                                 printf "%-60s %s\n" "$BRANCH" "$r"
482                                 #echo "$BRANCH: $r"
483                         done
484                 }
485                 ;;
486         merge)
487                 for d in $repos; do
488                         dv=`visible_repo_name "$d"`
489                         enter "$d0/$d" verbose
490                         r=`git symbolic-ref HEAD`
491                         r=${r#refs/heads/}
492                         if git log HEAD..origin/"`repobranch "$d"`" | grep .; then
493                                 # we have uncommitted changes
494                                 if yesno "Could merge from \"`repobranch "$d"`\" into \"$r\" in $dv. Do it?"; then
495                                         if ! verbose git merge origin/"`repobranch "$d"`"; then
496                                                 check_mergeconflict "$d"
497                                                 exit 1 # this should ALWAYS be fatal
498                                         fi
499                                 fi
500                         fi
501                         cd "$d0"
502                 done
503                 ;;
504         push|commit)
505                 submit=$1
506                 for d in $repos; do
507                         dv=`visible_repo_name "$d"`
508                         enter "$d0/$d" verbose
509                         r=`git symbolic-ref HEAD`
510                         r=${r#refs/heads/}
511                         diffdata=`git diff --color HEAD`
512                         if [ -n "$diffdata" ]; then
513                                 # we have uncommitted changes
514                                 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?" 'echo "$diffdata" | less -r'; then
515                                         verbose git commit -a
516                                 fi
517                         fi
518                         rem=`git config "branch.$r.remote" || echo origin`
519                         bra=`git config "branch.$r.merge" || echo "$r"`
520                         upstream="$rem/${bra#refs/heads/}"
521                         if ! git rev-parse "$upstream" >/dev/null 2>&1; then
522                                 upstream="origin/`repobranch "$d"`"
523                         fi
524                         logdata=`git log --color "$upstream".."$r"`
525                         if [ -n "$logdata" ]; then
526                                 if yesno "Push \"$r\" in $dv?" 'echo "$logdata" | less -r'; then
527                                         verbose git push "$rem" HEAD
528                                 fi
529                         fi
530                         if [ x"$submit" = x"-s" ]; then
531                                 case "$r" in
532                                         */*)
533                                                 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
534                                                 ;;
535                                 esac
536                         fi
537                         cd "$d0"
538                 done
539                 ;;
540         compile)
541                 if [ -n "$WE_HATE_OUR_USERS" ]; then
542                         TARGETS="sv-debug cl-debug"
543                         if [ -z "$CC" ]; then
544                                 export CC=gcc
545                         fi
546                 elif [ x"`uname`" = x"Darwin" ]; then
547                         case "`uname -r`" in
548                                 ?.*)
549                                         TARGETS="sv-debug cl-debug sdl-debug"
550                                         ;;
551                                 *)
552                                         # AGL cannot be compiled on systems with a kernel > 10.x (Snow Leopard)
553                                         TARGETS="sv-debug sdl-debug"
554                                         ;;
555                         esac
556                         export CC="gcc -I$PWD/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks/SDL.framework/Headers -F$PWD/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks"
557                 else
558                         TARGETS="sv-debug cl-debug sdl-debug"
559                 fi
560                 case "$1" in
561                         -c)
562                                 cleandp=true
563                                 cleanqcc=true
564                                 cleanqc=true
565                                 shift
566                                 ;;
567                         *)
568                                 cleandp=false
569                                 cleanqcc=false
570                                 cleanqc=false
571                                 ;;
572                 esac
573                 if [ $# -gt 0 ] && [ x"$1" = x"" ]; then
574                         # if we give the command make the arg "", it will surely fail (invalid filename),
575                         # so better handle it as an empty client option
576                         BAD_TARGETS=" "
577                         shift
578                 elif [ -n "$1" ]; then
579                         BAD_TARGETS=
580                         TARGETS_SAVE=$TARGETS
581                         TARGETS=
582                         for X in $1; do
583                                 case "$X" in
584                                         sdl)
585                                                 TARGETS="$TARGETS sdl-debug"
586                                                 ;;
587                                         glx|agl|wgl)
588                                                 TARGETS="$TARGETS cl-debug"
589                                                 ;;
590                                         dedicated)
591                                                 TARGETS="$TARGETS sv-debug"
592                                                 ;;
593                                         *)
594                                                 BAD_TARGETS="$BAD_TARGETS $X"
595                                                 ;;
596                                 esac
597                         done
598                         if [ -n "$TARGETS" ]; then # at least a valid client
599                                 shift
600                         else # no valid client, let's assume this option is not meant to be a client then
601                                 TARGETS=$TARGETS_SAVE
602                                 BAD_TARGETS=
603                         fi
604                 fi
605                 if [ -z "$MAKEFLAGS" ]; then
606                         if [ -f /proc/cpuinfo ]; then
607                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
608                                 if [ $ncpus -gt 1 ]; then
609                                         MAKEFLAGS=-j$ncpus
610                                 fi
611                         fi
612                         if [ -n "$WE_HATE_OUR_USERS" ]; then
613                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw LIB_JPEG= CFLAGS_LIBJPEG="
614                         fi
615                 fi
616
617                 enter "$d0/fteqcc" verbose
618                 if $cleanqcc; then
619                         verbose make $MAKEFLAGS clean
620                 fi
621                 verbose make $MAKEFLAGS
622
623                 enter "$d0/data/xonotic-data.pk3dir" verbose
624                 if $cleanqc; then
625                         verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS clean
626                 fi
627                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS
628
629                 enter "$d0/darkplaces" verbose
630                 if [ x"$BAD_TARGETS" = x" " ]; then
631                         echo "Warning: invalid empty client, default clients will be used."
632                 fi
633                 if $cleandp; then
634                         verbose make $MAKEFLAGS clean
635                 fi
636                 for T in $TARGETS; do
637                         verbose make $MAKEFLAGS "$@" "$T"
638                 done
639                 for T in $BAD_TARGETS; do
640                         echo "Warning: discarded invalid client $T."
641                 done
642
643                 verbose "$SELF" update-maps
644                 ;;
645         run)
646                 if [ -n "$WE_HATE_OUR_USERS" ]; then
647                         client=
648                         export PATH="$d0/misc/buildfiles/win32:$PATH"
649                 elif [ x"`uname`" = x"Darwin" ]; then
650                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/MacOS"
651                         export DYLD_FRAMEWORK_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks"
652                         client=-sdl
653                 else
654                         client=-sdl
655                 fi
656                 case "$1" in
657                         sdl|glx|agl|dedicated)
658                                 client=-$1
659                                 shift
660                                 ;;
661                         wgl)
662                                 client=
663                                 shift
664                                 ;;
665                 esac
666                 if ! [ -x "darkplaces/darkplaces$client" ]; then
667                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
668                                 client=$client.exe
669                         else
670                                 echo "Client darkplaces/darkplaces$client not found, aborting"
671                                 exit 1
672                         fi
673                 fi
674                 set -- "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic -mygames "$@"
675                 # change this to:
676                 #set -- "darkplaces/darkplaces$client" -xonotic -mygames "$@"
677
678                 # if pulseaudio is running: USE IT
679                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
680                         if ps -C pulseaudio >/dev/null; then
681                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
682                                         export SDL_AUDIODRIVER=pulse
683                                 fi
684                         fi
685                 fi
686
687                 if [ -n "$USE_GDB" ]; then
688                         set -- gdb --args "$@"
689                 fi
690                 "$@"
691                 ;;
692         each|foreach)
693                 keep_going=false
694                 if [ x"$1" = x"-k" ]; then
695                         keep_going=true
696                         shift
697                 fi
698                 for d in $repos; do
699                         if verbose cd "$d0/$d"; then
700                                 if $keep_going; then
701                                         verbose "$@" || true
702                                 else
703                                         verbose "$@"
704                                 fi
705                                 cd "$d0"
706                         fi
707                 done
708                 ;;
709         save-patches)
710                 outfile=$1
711                 patchdir=`mktemp -d -t save-patches.XXXXXX`
712                 for d in $repos; do
713                         enter "$d0/$d" verbose
714                         git branch -v -v | cut -c 3- | {
715                                 i=0
716                                 while read -r BRANCH REV UPSTREAM TEXT; do
717                                         case "$UPSTREAM" in
718                                                 \[*)
719                                                         UPSTREAM=${UPSTREAM#\[}
720                                                         UPSTREAM=${UPSTREAM%\]}
721                                                         UPSTREAM=${UPSTREAM%:*}
722                                                         TRACK=true
723                                                         ;;
724                                                 *)
725                                                         UPSTREAM=origin/"`repobranch "$d"`"
726                                                         TRACK=false
727                                                         ;;
728                                         esac
729                                         if [ x"$REV" = x"->" ]; then
730                                                 continue
731                                         fi
732                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
733                                                 echo "$d" > "$patchdir/$i/info.txt"
734                                                 echo "$BRANCH" >> "$patchdir/$i/info.txt"
735                                                 echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
736                                                 echo "$TRACK" >> "$patchdir/$i/info.txt"
737                                                 i=$(($i+1))
738                                         else
739                                                 rm -rf "$patchdir/$i"
740                                         fi
741                                 done
742                         }
743                 done
744                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
745                 rm -rf "$patchdir"
746                 ;;
747         restore-patches)
748                 infile=$1
749                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
750                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
751                 # detach the head
752                 for P in "$patchdir"/*/info.txt; do
753                         D=${P%/info.txt}
754                         exec 3<"$P"
755                         read -r d <&3
756                         read -r BRANCH <&3
757                         read -r UPSTREAM <&3
758                         read -r TRACK <&3
759                         verbose git checkout HEAD^0
760                         verbose git branch -D "$BRANCH"
761                         if [ x"$TRACK" = x"true" ]; then
762                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
763                         else
764                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
765                         fi
766                         verbose git am "$D"
767                 done
768                 rm -rf "$patchdir"
769                 ;;
770         admin-merge)
771                 branch=$1
772                 t=`mktemp`
773                 report=""
774                 reportecho()
775                 {
776                         report=$report"$*$LF"
777                         echo "$*"
778                 }
779                 reportecho4()
780                 {
781                         report=$report"    $*$LF"
782                         echo "    $*"
783                 }
784                 reportdo4()
785                 {
786                         o=`"$@" | sed 's/^/    /' || true`
787                         reportecho "$o"
788                 }
789                 for d in $repos; do
790                         enter "$d0/$d" verbose
791                         base="`repobranch "$d"`"
792                         reportecho "In $d:"
793                         for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
794                                 case "${ref#refs/remotes/origin/}" in
795                                         "$base")
796                                                 continue
797                                                 ;;
798                                         HEAD|master)
799                                                 continue
800                                                 ;;
801                                         */*)
802                                                 ;;
803                                         *)
804                                                 continue
805                                                 ;;
806                                 esac
807                                 if [ -n "$branch" ]; then
808                                         if [ x"$branch" != x"${ref#refs/remotes/origin/}" ]; then
809                                                 continue
810                                         fi
811                                 fi
812                                 case "$base" in
813                                         master)
814                                                 realbase=$base
815                                                 ;;
816                                         *)
817                                                 l0=`git rev-list "$base".."$ref" | wc -l`
818                                                 l1=`git rev-list master.."$ref" | wc -l`
819                                                 if [ $l0 -gt $l1 ]; then
820                                                         realbase=master
821                                                 else
822                                                         realbase=$base
823                                                 fi
824                                                 ;;
825                                 esac
826                                 reportecho "  Branch $ref:"
827                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
828                                 logdata=`git log --color "$realbase".."$ref"`
829                                 if [ -z "$logdata" ]; then
830                                         reportecho4 "--> not merging, no changes vs master"
831                                         if yesno "Branch \"$ref\" probably should get deleted. Do it?" ''; then
832                                                 git push origin :"${ref#refs/remotes/origin/}"
833                                                 reportecho4 "--> branch deleted"
834                                         fi
835                                 else
836                                         diffdata=`git diff --color --find-copies-harder --ignore-space-change "$realbase"..."$ref"`
837                                         if [ -z "$diffdata" ]; then
838                                                 reportecho4 "--> not merging, no changes vs master, branch contains redundant history"
839                                                 if yesno "Branch \"$ref\" probably should get deleted. Do it?" '{ echo "$logdata"; } | less -r'; then
840                                                         git push origin :"${ref#refs/remotes/origin/}"
841                                                         reportecho4 "--> branch deleted"
842                                                 fi
843                                         elif [ -z "$branch" ] && [ -n "$note" ]; then
844                                                 reportdo4 echo "$note"
845                                                 reportecho4 "--> not merging, already had this one rejected before"
846                                         elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ echo "$logdata"; echo "$diffdata"; } | less -r'; then
847                                                 git checkout "$realbase"
848                                                 org=`git rev-parse HEAD`
849                                                 if ! git merge --no-ff "$ref" 2>&1 | tee "$t" && ! { git ls-files -u | grep ' 1 ' >/dev/null; }; then
850                                                         git reset --hard "$org"
851                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Merge failed:$LF`cat "$t"`" "$ref"
852                                                         reportdo4 cat "$t"
853                                                         reportecho4 "--> merge failed"
854                                                 elif ! "$SELF" compile -n 2>&1 | tee "$t"; then
855                                                         git reset --hard "$org"
856                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Compile failed:$LF`cat "$t"`" "$ref"
857                                                         reportdo4 cat "$t"
858                                                         reportecho4 "--> compile failed"
859                                                 elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
860                                                         git reset --hard "$org"
861                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
862                                                         note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
863                                                         if [ x"$note" = x"del" ]; then
864                                                                 git push origin :"${ref#refs/remotes/origin/}"
865                                                                 reportecho4 "--> test failed, branch deleted"
866                                                         elif [ -n "$note" ]; then
867                                                                 reportdo4 echo "$note"
868                                                                 reportecho4 "--> test failed"
869                                                         else
870                                                                 reportecho4 "--> test failed, postponed"
871                                                         fi
872                                                 else
873                                                         echo "MERGING"
874                                                         case ",`repoflags "$d"`," in
875                                                                 *,svn,*)
876                                                                         # we do quite a mess here... luckily we know $org
877                                                                         git fetch # svn needs to be current
878                                                                         git rebase -i --onto origin/master "$org"
879                                                                         git svn dcommit --add-author-from
880                                                                         git reset --hard "$org"
881                                                                         ;;
882                                                                 *)
883                                                                         git push origin HEAD
884                                                                         ;;
885                                                         esac
886                                                         reportecho4 "--> MERGED"
887                                                         if yesno "Delete original branch \"$ref\"?"; then
888                                                                 git push origin :"${ref#refs/remotes/origin/}"
889                                                                 reportecho4 "--> branch deleted"
890                                                         fi
891                                                 fi
892                                         else
893                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
894                                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
895                                                 if [ x"$note" = x"del" ]; then
896                                                         git push origin :"${ref#refs/remotes/origin/}"
897                                                         reportecho4 "--> branch deleted"
898                                                 elif [ -n "$note" ]; then
899                                                         reportdo4 echo "$note"
900                                                         reportecho4 "--> rejected"
901                                                 else
902                                                         reportecho4 "--> postponed"
903                                                 fi
904                                         fi
905                                 fi
906                                 reportecho ""
907                         done
908                         reportecho ""
909                 done
910                 rm -f "$t"
911                 echo "$report" | ssh nexuiz@rm.endoftheinternet.org cat '>>' public_html/xonotic-merge-notes.txt
912                 ;;
913         clean)
914                 force=false
915                 if [ x"$1" = x"-f" ]; then
916                         force=true
917                 fi
918                 for d in $repos; do
919                         verbose cd "$d0/$d"
920                         if $force; then
921                                 verbose git reset --hard
922                                 #redundant# verbose git checkout-index -fa
923                         fi
924                         case "$d" in
925                                 .)
926                                         verbose git clean -df
927                                         ;;
928                                 *)
929                                         verbose git clean -xdf
930                                         ;;
931                         esac
932                 done
933                 ;;
934
935         # release building goes here
936         release-prepare)
937                 #"$SELF" each git clean -fxd
938                 case "$RELEASETYPE" in
939                         beta)
940                                 msg "Building a BETA"
941                                 ;;
942                         release)
943                                 msg "Building a RELEASE"
944                                 ;;
945                         *)
946                                 msg "Must either set RELEASETYPE=beta or RELEASETYPE=release"
947                                 exit 1
948                                 ;;
949                 esac
950                 verbose rm -rf Xonotic Xonotic*.zip
951                 verbose mkdir -p Xonotic
952                 if [ -n "$RELEASEDATE" ]; then
953                         verbose echo "$RELEASEDATE" > Xonotic/stamp.txt
954                 else
955                         verbose date +%Y%m%d > Xonotic/stamp.txt
956                 fi
957                 verbose git archive --format=tar HEAD -- Docs misc server xonotic-linux-glx.sh xonotic-linux-sdl.sh misc/buildfiles | {
958                         verbose cd Xonotic
959                         verbose mkdir data fteqcc source source/darkplaces source/fteqcc
960                         verbose tar xvf -
961                         verbose rm -rf misc/builddeps
962                         verbose mv misc/buildfiles/win32/* . || true
963                         verbose mv misc/buildfiles/win64 bin64 || true
964                         verbose mv misc/buildfiles/osx/* . || true
965                         verbose rm -rf misc/buildfiles
966                 }
967                 {
968                         verbose cd darkplaces
969                         verbose git archive --format=tar HEAD
970                 } | {
971                         verbose cd Xonotic/source/darkplaces
972                         verbose tar xvf -
973                 }
974                 {
975                         verbose cd fteqcc
976                         verbose git archive --format=tar HEAD
977                 } | {
978                         verbose cd Xonotic/source/fteqcc
979                         verbose tar xvf -
980                 }
981                 {
982                         verbose cd data/xonotic-data.pk3dir
983                         verbose git archive --format=tar HEAD -- qcsrc Makefile
984                 } | {
985                         verbose cd Xonotic/source
986                         verbose tar xvf -
987                 }
988                 ;;
989         release-compile-run)
990                 host=$1
991                 buildpath=$2
992                 maketargets=$3
993                 makeflags=$4
994                 srcdir=$5
995                 depsdir=$6
996                 targetfiles=$7
997                 set -x
998                 if [ -n "$targetfiles" ]; then
999                         case " $HOSTS_THAT_ARE_DISABLED " in
1000                                 *\ $host\ *)
1001                                         exit
1002                                         ;;
1003                         esac
1004                         case " $HOSTS_THAT_ARE_MYSELF " in
1005                                 *\ $host\ *)
1006                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$buildpath/"
1007                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$buildpath.deps/"
1008                                         verbose ln -snf "$buildpath.deps" "$buildpath/.deps"
1009                                         verbose eval make -C "$buildpath" clean $maketargets $makeflags
1010                                         for f in $targetfiles; do
1011                                                 verbose mv "$buildpath/${f%:*}" "${f##*:}" || true
1012                                         done
1013                                         ;;
1014                                 *)
1015                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$host:$buildpath/"
1016                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$host:$buildpath.deps/"
1017                                         verbose ssh "$host" "ln -snf $buildpath.deps $buildpath/.deps && cd $buildpath && nice -`nice` make clean $maketargets $makeflags"
1018                                         for f in $targetfiles; do
1019                                                 verbose rsync -zvaSHP "$host:$buildpath/${f%:*}" "${f##*:}" || true
1020                                         done
1021                                         ;;
1022                         esac
1023                         # now rebrand the binaries...
1024                         for f in $targetfiles; do
1025                                 #verbose "$d0/misc/tools/rebrand-darkplaces-engine.sh" "${XONOTIC_BRAND:-$d0/misc/tools/xonotic.brand}" "${f##*:}" || true
1026                                 case "$f" in
1027                                         xonotic*.exe)
1028                                                 verbose "$d0/misc/tools/change-icon-of-exe.sh" "$d0/misc/logos/icons_ico/xonotic.ico" "$f"
1029                                                 (
1030                                                         d=`mktemp -d -t rebrand.XXXXXX`
1031                                                         cd "$d"
1032                                                         echo "-mygames" > darkplaces.opt
1033                                                         zip -9r darkplaces.zip darkplaces.opt
1034                                                         cat darkplaces.zip
1035                                                         cd "$d0"
1036                                                         rm -rf "$d"
1037                                                 ) >> "$f"
1038                                                 ;;
1039                                 esac
1040                         done
1041                 fi
1042                 ;;
1043         release-compile)
1044                 suffix=$1
1045                 makeflags=$2
1046                 fteqcc_maketargets=$3
1047                 fteqcc_files=$4
1048                 darkplaces_maketargets=$5
1049                 darkplaces_files=$6
1050                 host=xonotic-build-$suffix
1051                 verbose "$SELF" release-compile-run "$host" /tmp/fteqcc.build."$suffix" "$fteqcc_maketargets" "$makeflags" "Xonotic/source/fteqcc" "$d0/misc/builddeps/dp.$suffix" "$fteqcc_files"
1052                 verbose "$SELF" release-compile-run "$host" /tmp/Darkplaces.build."$suffix" "$darkplaces_maketargets" "$makeflags" "Xonotic/source/darkplaces" "$d0/misc/builddeps/dp.$suffix" "$darkplaces_files"
1053                 ;;
1054         release-engine-win32)
1055                 # TODO change to g++ and D3D=1 when D3D gets added
1056                 verbose "$SELF" release-compile win32 \
1057                         'STRIP=: DP_MAKE_TARGET=mingw CC="i586-mingw32msvc-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib" WINDRES="i586-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN32RELEASE=1 D3D=0' \
1058                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc.exe' \
1059                         release 'darkplaces.exe:Xonotic/xonotic.exe darkplaces-sdl.exe:Xonotic/xonotic-sdl.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated.exe'
1060                 ;;
1061         release-engine-win64)
1062                 # TODO change to g++ and D3D=1 when D3D gets added
1063                 verbose "$SELF" release-compile win64 \
1064                         'STRIP=: DP_MAKE_TARGET=mingw CC="amd64-mingw32msvc-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib" WINDRES="amd64-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN64RELEASE=1 D3D=0' \
1065                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc-x64.exe' \
1066                         'sv-release cl-release' 'darkplaces.exe:Xonotic/xonotic-x64.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated-x64.exe'
1067                         # release 'darkplaces.exe:Xonotic/xonotic-x64.exe darkplaces-sdl.exe:Xonotic/xonotic-sdl-x64.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated-x64.exe'
1068                 ;;
1069         release-engine-osx-sv-sdl)
1070                 # gcc on OSX is buggy, needs -fno-reorder-blocks for a release build to succeed
1071                 verbose "$SELF" release-compile osx \
1072                         'STRIP=: CC="gcc -g -arch i386 -arch ppc -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.4 -I.deps/include -L.deps/lib -fno-reorder-blocks"' \
1073                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.osx' \
1074                         'sv-release sdl-release' 'darkplaces-sdl:Xonotic/Xonotic-SDL.app/Contents/MacOS/xonotic-osx-sdl-bin darkplaces-dedicated:Xonotic/xonotic-osx-dedicated'
1075                 ;;
1076         release-engine-osx-agl)
1077                 # gcc on OSX is buggy, needs -fno-reorder-blocks for a release build to succeed
1078                 verbose "$SELF" release-compile osx \
1079                         'STRIP=: CC="gcc -g -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.4 -I.deps/include -L.deps/lib -fno-reorder-blocks"' \
1080                         '' '' \
1081                         'cl-release' 'darkplaces-agl:Xonotic/Xonotic.app/Contents/MacOS/xonotic-osx-agl-bin'
1082                 ;;
1083         release-engine-osx)
1084                 verbose "$SELF" release-engine-osx-sv-sdl
1085                 verbose "$SELF" release-engine-osx-agl
1086                 ;;
1087         release-engine-linux32)
1088                 verbose "$SELF" release-compile linux32 \
1089                         'STRIP=: CC="gcc -m32 -g -I.deps/include -L.deps/lib" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a' \
1090                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux32' \
1091                         release 'darkplaces-glx:Xonotic/xonotic-linux32-glx darkplaces-sdl:Xonotic/xonotic-linux32-sdl darkplaces-dedicated:Xonotic/xonotic-linux32-dedicated'
1092                 ;;
1093         release-engine-linux64)
1094                 verbose "$SELF" release-compile linux64 \
1095                         'STRIP=: CC="gcc -m64 -g -I.deps/include -L.deps/lib" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a' \
1096                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux64' \
1097                         release 'darkplaces-glx:Xonotic/xonotic-linux64-glx darkplaces-sdl:Xonotic/xonotic-linux64-sdl darkplaces-dedicated:Xonotic/xonotic-linux64-dedicated'
1098                 ;;
1099         release-engine)
1100                 verbose "$SELF" release-engine-linux32 &
1101                 verbose "$SELF" release-engine-linux64 &
1102                 verbose "$SELF" release-engine-win32 &
1103                 verbose "$SELF" release-engine-win64 &
1104                 verbose "$SELF" release-engine-osx &
1105                 wait %1
1106                 wait %2
1107                 wait %3
1108                 wait %4
1109                 wait %5
1110                 wait
1111                 ;;
1112         release-maps)
1113                 verbose "$SELF" update-maps
1114                 ;;
1115         release-qc)
1116                 case "$RELEASETYPE" in
1117                         beta)
1118                                 verbose make -C Xonotic/source FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 clean all
1119                                 ;;
1120                         release)
1121                                 verbose make -C Xonotic/source FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 FTEQCCFLAGS_WATERMARK= clean all
1122                                 ;;
1123                 esac
1124                 verbose rm -f Xonotic/source/*/fteqcc.log
1125                 ;;
1126         release-buildpk3-transform-raw)
1127                 dir=$1
1128                 ;;
1129         release-buildpk3-transform-normal)
1130                 dir=$1
1131                 verbose cd "$dir"
1132                 # texture: convert to jpeg and dds
1133                 verbose export do_jpeg=true
1134                 verbose export jpeg_qual_rgb=95
1135                 verbose export jpeg_qual_a=99
1136                 verbose export do_dds=true
1137                 verbose export dds_flags=
1138                 verbose export do_ogg=false
1139                 verbose export del_src=true
1140                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1141                 ;;
1142         release-buildpk3-transform-low)
1143                 dir=$1
1144                 verbose cd "$dir"
1145                 # texture: convert to jpeg and dds
1146                 # music: reduce bitrate
1147                 verbose export do_jpeg=true
1148                 verbose export jpeg_qual_rgb=80
1149                 verbose export jpeg_qual_a=95
1150                 verbose export do_dds=false
1151                 verbose export do_ogg=true
1152                 verbose export ogg_qual=1
1153                 verbose export del_src=true
1154                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1155                 ;;
1156         release-buildpk3-transform-lowdds)
1157                 dir=$1
1158                 verbose cd "$dir"
1159                 # texture: convert to jpeg and dds
1160                 # music: reduce bitrate
1161                 verbose export do_jpeg=false
1162                 verbose export do_jpeg_if_not_dds=true
1163                 verbose export jpeg_qual_rgb=80
1164                 verbose export jpeg_qual_a=95
1165                 verbose export do_dds=true
1166                 verbose export dds_flags=
1167                 verbose export do_ogg=true
1168                 verbose export ogg_qual=1
1169                 verbose export del_src=true
1170                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1171                 ;;
1172         release-buildpk3)
1173                 src=$1
1174                 dst=$2
1175                 transform=$3
1176                 case "$dst" in
1177                         /*)
1178                                 ;;
1179                         */)
1180                                 dst="$PWD/$dst"
1181                                 ;;
1182                 esac
1183                 verbose rm -rf Xonotic/temp
1184                 verbose mkdir -p Xonotic/temp
1185                 {
1186                         verbose cd "$src"
1187                         verbose git archive --format=tar HEAD
1188                 } | {
1189                         verbose cd Xonotic/temp
1190                         verbose tar xvf -
1191                 }
1192                 verbose cd Xonotic/temp
1193                 if [ x"$src" = x"data/xonotic-data.pk3dir" ]; then
1194                         verbose cp ../source/progs.dat .
1195                         verbose cp ../source/csprogs.dat .
1196                         verbose cp ../source/menu.dat .
1197                         verbose rm -rf qcsrc
1198                         gv=`grep "^gameversion " "defaultXonotic.cfg" | awk '{ print $2 }'`
1199                         major=$(($gv / 10000))
1200                         minor=$(($gv / 100 - $major * 100))
1201                         patch=$(($gv - $major * 10000 - $minor * 100))
1202                         versionstr="$major.$minor.$patch"
1203                         case "$RELEASETYPE" in
1204                                 beta)
1205                                         versionstr="$versionstr""beta"
1206                                         ;;
1207                         esac
1208                         verbose sed -i "
1209                                 s/^set g_xonoticversion [^ ]* /set g_xonoticversion $versionstr /;
1210                                 s/^gameversion_min [0-9]*/gameversion_min $(( ($gv / 100) * 100 - 100 ))/;
1211                                 s/^gameversion_max [0-9]*/gameversion_max $(( ($gv / 100) * 100 + 199 ))/;
1212                         " defaultXonotic.cfg
1213                         (
1214                                 verbose cd gfx/menu/luminos
1215                                 verbose cp "$d0"/mediasource/gfx/menu/luminos_versionbuilder/background_l2.svg .
1216                                 verbose "$d0"/mediasource/gfx/menu/luminos_versionbuilder/versionbuilder "$versionstr"
1217                                 verbose rm background_l2.svg
1218                         )
1219                 fi
1220                 if [ x"$src" = x"data/xonotic-maps.pk3dir" ]; then
1221                         for X in ../../data/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
1222                                 if [ -f "$X" ]; then
1223                                         verbose unzip "$X"
1224                                         verbose rm -f maps/*.log maps/*.irc maps/*.lin
1225                                 fi
1226                         done
1227                 fi
1228                 verbose export git_src_repo="$d0/$src" # skip hash-object
1229                 verbose "$SELF" release-buildpk3-transform-$transform "Xonotic/temp"
1230                 verbose mkzip "../../$dst" .
1231                 verbose cd ../..
1232                 verbose rm -rf Xonotic/temp
1233                 ;;
1234         release-buildpk3s)
1235                 stamp=`cat Xonotic/stamp.txt`
1236                 src=$1
1237                 shift
1238                 dst=${src%.pk3dir}
1239                 case "$dst" in
1240                         data/xonotic-*)
1241                                 dst="data/xonotic-$stamp-${dst#data/xonotic-}"
1242                                 ;;
1243                         *)
1244                                 dst="$dst-$stamp"
1245                                 ;;
1246                 esac
1247                 while [ "$#" -gt 1 ]; do
1248                         verbose "$SELF" release-buildpk3 "$src" "Xonotic/$dst$2.pk3" "$1"
1249                         shift
1250                         shift
1251                 done
1252                 ;;
1253         release-pack)
1254                 verbose "$SELF" release-buildpk3s data/font-nimbussansl.pk3dir             raw ''
1255                 verbose "$SELF" release-buildpk3s data/xonotic-data.pk3dir       normal '' raw '-raw' low '-low' lowdds '-lowdds'
1256                 verbose "$SELF" release-buildpk3s data/xonotic-maps.pk3dir       normal '' raw '-raw' low '-low' lowdds '-lowdds'
1257                 verbose "$SELF" release-buildpk3s data/xonotic-music.pk3dir                raw ''     low '-low'
1258                 verbose "$SELF" release-buildpk3s data/xonotic-nexcompat.pk3dir                       low ''
1259                 ;;
1260         release-pack-needsx11)
1261                 case "$DISPLAY" in
1262                         '')
1263                                 verbose startx "$SELF" release-pack -- /usr/bin/Xvfb :7
1264                                 ;;
1265                         *)
1266                                 verbose "$SELF" release-pack
1267                                 ;;
1268                 esac
1269                 ;;
1270         release-zip)
1271                 stamp=`cat Xonotic/stamp.txt`
1272                 # exe and dll files do not need +x, so this makes them eligible for 7zip compression too
1273                 chmod a-x *.exe *.dll
1274                 # need to use infozip for these (+x bits)
1275                 verbose mkzip Xonotic-$stamp-engine.zip \
1276                         Xonotic/*.dll \
1277                         Xonotic/bin64/*.dll \
1278                         Xonotic/*.app \
1279                         Xonotic/xonotic-* \
1280                         Xonotic/xonotic.exe
1281                 verbose cp Xonotic-$stamp-engine.zip Xonotic-$stamp-common.zip
1282                 verbose mkzip Xonotic-$stamp-common.zip \
1283                         Xonotic/source/*/ \
1284                         Xonotic/Docs \
1285                         Xonotic/misc \
1286                         Xonotic/fteqcc \
1287                         Xonotic/server \
1288                         Xonotic/data/font-nimbussansl-$stamp.pk3
1289                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp.zip
1290                 verbose mkzip0 Xonotic-$stamp.zip \
1291                         Xonotic/data/xonotic-$stamp-data.pk3 \
1292                         Xonotic/data/xonotic-$stamp-maps.pk3 \
1293                         Xonotic/data/xonotic-$stamp-music.pk3 \
1294                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1295                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-low.zip
1296                 verbose mkzip0 Xonotic-$stamp-low.zip \
1297                         Xonotic/data/xonotic-$stamp-data-low.pk3 \
1298                         Xonotic/data/xonotic-$stamp-maps-low.pk3 \
1299                         Xonotic/data/xonotic-$stamp-music-low.pk3
1300                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-lowdds.zip
1301                 verbose mkzip0 Xonotic-$stamp-lowdds.zip \
1302                         Xonotic/data/xonotic-$stamp-data-lowdds.pk3 \
1303                         Xonotic/data/xonotic-$stamp-maps-lowdds.pk3 \
1304                         Xonotic/data/xonotic-$stamp-music-low.pk3
1305                 verbose mv Xonotic-$stamp-common.zip Xonotic-$stamp-high.zip
1306                 verbose mkzip0 Xonotic-$stamp-high.zip \
1307                         Xonotic/data/xonotic-$stamp-data-raw.pk3 \
1308                         Xonotic/data/xonotic-$stamp-maps-raw.pk3 \
1309                         Xonotic/data/xonotic-$stamp-music.pk3 \
1310                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1311                 ;;
1312         release)
1313                 verbose "$SELF" release-prepare
1314                 verbose "$SELF" release-maps
1315                 verbose "$SELF" release-engine
1316                 verbose "$SELF" release-qc
1317                 verbose "$SELF" release-pack-needsx11
1318                 verbose "$SELF" release-zip
1319                 ;;
1320
1321         *)
1322                 echo "Usage:"
1323                 echo "  $SELF pull"
1324                 echo "  $SELF merge"
1325                 echo "  $SELF push [-s]"
1326                 echo "  $SELF branches"
1327                 echo "  $SELF branch [<remote>] <branchname>"
1328                 echo "  $SELF branch <remote> <branchname> <srcbranchname>"
1329                 echo "  $SELF checkout [<remote>] <branchname>"
1330                 echo "  $SELF compile [-c|-n] [<client>] <options>"
1331                 echo "  $SELF run [<client>] <options>"
1332                 echo "  $SELF each <command>"
1333                 ;;
1334 esac