properly distinguish between 7za and zip
[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         \( -type f -not -executable \)    -print > "$ziplist"; 7za a -tzip -mx=9 -i@"$ziplist" "$archive" || true
281         rm -f "$ziplist"
282         find "$@" -xtype f \( -not \( -type f -not -executable \) \) -print             | zip         -9y   -@            "$archive" || true
283 }
284
285 mkzip0()
286 {
287         zip -0y "$@"
288 }
289
290 case "$cmd" in
291         fix_upstream_rebase)
292                 for d in $repos; do
293                         enter "$d0/$d" verbose
294                         verbose fix_upstream_rebase_mergefail && verbose fix_upstream_rebase_mergeok
295                 done
296                 ;;
297         update|pull)
298                 allow_pull=true
299                 if [ x"$1" = x"-N" ]; then
300                         allow_pull=false
301                 fi
302                 for d in $repos; do
303                         url=`repourl "$d"`
304                         branch=`repobranch "$d"`
305                         if [ -d "$d0/$d" ]; then
306                                 if $allow_pull; then
307                                         enter "$d0/$d" verbose
308                                         fix_git_config
309                                         verbose git config remote.origin.url "$url"
310                                         verbose git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
311                                         r=`git symbolic-ref HEAD`
312                                         r=${r#refs/heads/}
313                                         if git config branch.$r.remote >/dev/null 2>&1; then
314                                                 if ! verbose git pull; then
315                                                         fix_upstream_rebase_mergefail || true
316                                                         check_mergeconflict "$d"
317                                                         echo "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
318                                                         read -r DUMMY
319                                                 else
320                                                         fix_upstream_rebase_mergeok || true
321                                                 fi
322                                         fi
323
324                                         cd "$d00"
325                                         checkself "$cmd" "$@"
326                                         cd "$d0/$d"
327                                         verbose git remote prune origin
328                                         cd "$d0"
329                                 fi
330                         else
331                                 verbose git clone "$url" "$d0/$d"
332                                 enter "$d0/$d" verbose
333                                 fix_git_config
334                                 if [ "$branch" != "master" ]; then
335                                         verbose git checkout --track -b "$branch" origin/"$branch"
336                                 fi
337                                 cd "$d0"
338                         fi
339                 done
340                 ;;
341         update-maps)
342                 misc/tools/xonotic-map-compiler-autobuild download
343                 ;;
344         checkout|switch)
345                 checkoutflags=
346                 if [ x"$1" = x"-f" ]; then
347                         checkoutflags=-f
348                         shift
349                 fi
350                 remote=$1
351                 branch=$2
352                 if [ -z "$branch" ]; then
353                         case "$remote" in
354                                 origin/*)
355                                         branch=${remote#origin/}
356                                         remote=origin
357                                         ;;
358                                 *)
359                                         branch=$remote
360                                         remote=origin
361                                         ;;
362                         esac
363                 fi
364                 exists=false
365                 for d in $repos; do
366                         enter "$d0/$d" verbose
367                         b=$branch
368                         if [ -n "$b" ] && git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
369                                 exists=true
370                                 verbose git checkout $checkoutflags "$b"
371                         elif [ -n "$b" ] && git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
372                                 exists=true
373                                 verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
374                         else
375                                 b=`repobranch "$d"`
376                                 if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
377                                         exists=true
378                                         verbose git checkout $checkoutflags "$b"
379                                 elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
380                                         exists=true
381                                         verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
382                                 else
383                                         echo "WTF? Not even branch $b doesn't exist in $d"
384                                         exit 1
385                                 fi
386                         fi
387                         cd "$d00"
388                         checkself "$cmd" "$@"
389                         cd "$d0"
390                 done
391                 if ! $exists; then
392                         echo "The requested branch was not found in any repository."
393                 fi
394                 exec "$SELF" branch
395                 ;;
396         branch)
397                 remote=$1
398                 branch=$2
399                 srcbranch=$3
400                 if [ -z "$branch" ]; then
401                         branch=$remote
402                         remote=origin
403                 fi
404                 if [ -z "$branch" ]; then
405                         for d in $repos; do
406                                 enter "$d0/$d"
407                                 r=`git symbolic-ref HEAD`
408                                 r=${r#refs/heads/}
409                                 echo "$d is at $r"
410                                 cd "$d0"
411                         done
412                 else
413                         for d in $repos; do
414                                 dv=`visible_repo_name "$d"`
415                                 enter "$d0/$d" verbose
416                                 if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
417                                         echo "Already having this branch in $dv."
418                                 else
419                                         if yesno "Branch in $dv?"; then
420                                                 if [ -n "$srcbranch" ]; then
421                                                         b=$srcbranch
422                                                 else
423                                                         b=origin/"`repobranch "$d"`"
424                                                         verbose git fetch origin || true
425                                                 fi
426                                                 # TODO do this without pushing
427                                                 verbose git checkout -b "$branch" "$b"
428                                                 verbose git config "branch.$branch.remote" "$remote"
429                                                 verbose git config "branch.$branch.merge" "refs/heads/$branch"
430                                         fi
431                                 fi
432                                 cd "$d0"
433                         done
434                         "$SELF" branch
435                 fi
436                 ;;
437         branches)
438                 for d in $repos; do
439                         cd "$d0/$d" # am in a pipe, shouldn't use enter
440                         git branch -a -v -v | cut -c 3- | sed "s/^(no branch)/(no_branch)/" | sed "s,^,$d ,"
441                         cd "$d0"
442                 done | {
443                         branches_list=
444                         # branches_repos_*=
445                         while read -r d BRANCH REV UPSTREAM TEXT; do
446                                 if [ x"$BRANCH" = x"`repobranch "$d"`" ]; then
447                                         continue
448                                 fi
449                                 case "$UPSTREAM" in
450                                         \[*)
451                                                 UPSTREAM=${UPSTREAM#\[}
452                                                 UPSTREAM=${UPSTREAM%\]}
453                                                 UPSTREAM=${UPSTREAM%:*}
454                                                 ;;
455                                         *)
456                                                 TEXT="$UPSTREAM $TEXT"
457                                                 UPSTREAM=
458                                                 ;;
459                                 esac
460                                 if [ x"$REV" = x"->" ]; then
461                                         continue
462                                 fi
463                                 BRANCH=${BRANCH#remotes/}
464                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
465                                 branches_list="$branches_list $BRANCH" # TEH SORT MAKEZ IT UNIEQ
466                                 eval "r=\$branches_repos_$ID"
467                                 case "$UPSTREAM" in
468                                         '')
469                                                 r="$r $d"
470                                                 ;;
471                                         *)
472                                                 r="$r $d:$UPSTREAM"
473                                                 ;;
474                                 esac
475                                 eval "branches_repos_$ID=\$r"
476                         done
477                         echo -n "$branches_list" | xargs -n 1 echo | sort -u | while IFS= read -r BRANCH; do
478                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
479                                 eval "r=\$branches_repos_$ID"
480                                 printf "%-60s %s\n" "$BRANCH" "$r"
481                                 #echo "$BRANCH: $r"
482                         done
483                 }
484                 ;;
485         merge)
486                 for d in $repos; do
487                         dv=`visible_repo_name "$d"`
488                         enter "$d0/$d" verbose
489                         r=`git symbolic-ref HEAD`
490                         r=${r#refs/heads/}
491                         if git log HEAD..origin/"`repobranch "$d"`" | grep .; then
492                                 # we have uncommitted changes
493                                 if yesno "Could merge from \"`repobranch "$d"`\" into \"$r\" in $dv. Do it?"; then
494                                         if ! verbose git merge origin/"`repobranch "$d"`"; then
495                                                 check_mergeconflict "$d"
496                                                 exit 1 # this should ALWAYS be fatal
497                                         fi
498                                 fi
499                         fi
500                         cd "$d0"
501                 done
502                 ;;
503         push|commit)
504                 submit=$1
505                 for d in $repos; do
506                         dv=`visible_repo_name "$d"`
507                         enter "$d0/$d" verbose
508                         r=`git symbolic-ref HEAD`
509                         r=${r#refs/heads/}
510                         diffdata=`git diff --color HEAD`
511                         if [ -n "$diffdata" ]; then
512                                 # we have uncommitted changes
513                                 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?" 'echo "$diffdata" | less -r'; then
514                                         verbose git commit -a
515                                 fi
516                         fi
517                         rem=`git config "branch.$r.remote" || echo origin`
518                         bra=`git config "branch.$r.merge" || echo "$r"`
519                         upstream="$rem/${bra#refs/heads/}"
520                         if ! git rev-parse "$upstream" >/dev/null 2>&1; then
521                                 upstream="origin/`repobranch "$d"`"
522                         fi
523                         logdata=`git log --color "$upstream".."$r"`
524                         if [ -n "$logdata" ]; then
525                                 if yesno "Push \"$r\" in $dv?" 'echo "$logdata" | less -r'; then
526                                         verbose git push "$rem" HEAD
527                                 fi
528                         fi
529                         if [ x"$submit" = x"-s" ]; then
530                                 case "$r" in
531                                         */*)
532                                                 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
533                                                 ;;
534                                 esac
535                         fi
536                         cd "$d0"
537                 done
538                 ;;
539         compile)
540                 if [ -n "$WE_HATE_OUR_USERS" ]; then
541                         TARGETS="sv-debug cl-debug"
542                         if [ -z "$CC" ]; then
543                                 export CC=gcc
544                         fi
545                 elif [ x"`uname`" = x"Darwin" ]; then
546                         case "`uname -r`" in
547                                 ?.*)
548                                         TARGETS="sv-debug cl-debug sdl-debug"
549                                         ;;
550                                 *)
551                                         # AGL cannot be compiled on systems with a kernel > 10.x (Snow Leopard)
552                                         TARGETS="sv-debug sdl-debug"
553                                         ;;
554                         esac
555                         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"
556                 else
557                         TARGETS="sv-debug cl-debug sdl-debug"
558                 fi
559                 case "$1" in
560                         -c)
561                                 cleandp=true
562                                 cleanqcc=true
563                                 cleanqc=true
564                                 shift
565                                 ;;
566                         *)
567                                 cleandp=false
568                                 cleanqcc=false
569                                 cleanqc=false
570                                 ;;
571                 esac
572                 if [ $# -gt 0 ] && [ x"$1" = x"" ]; then
573                         # if we give the command make the arg "", it will surely fail (invalid filename),
574                         # so better handle it as an empty client option
575                         BAD_TARGETS=" "
576                         shift
577                 elif [ -n "$1" ]; then
578                         BAD_TARGETS=
579                         TARGETS_SAVE=$TARGETS
580                         TARGETS=
581                         for X in $1; do
582                                 case "$X" in
583                                         sdl)
584                                                 TARGETS="$TARGETS sdl-debug"
585                                                 ;;
586                                         glx|agl|wgl)
587                                                 TARGETS="$TARGETS cl-debug"
588                                                 ;;
589                                         dedicated)
590                                                 TARGETS="$TARGETS sv-debug"
591                                                 ;;
592                                         *)
593                                                 BAD_TARGETS="$BAD_TARGETS $X"
594                                                 ;;
595                                 esac
596                         done
597                         if [ -n "$TARGETS" ]; then # at least a valid client
598                                 shift
599                         else # no valid client, let's assume this option is not meant to be a client then
600                                 TARGETS=$TARGETS_SAVE
601                                 BAD_TARGETS=
602                         fi
603                 fi
604                 if [ -z "$MAKEFLAGS" ]; then
605                         if [ -f /proc/cpuinfo ]; then
606                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
607                                 if [ $ncpus -gt 1 ]; then
608                                         MAKEFLAGS=-j$ncpus
609                                 fi
610                         fi
611                         if [ -n "$WE_HATE_OUR_USERS" ]; then
612                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw LIB_JPEG= CFLAGS_LIBJPEG="
613                         fi
614                 fi
615
616                 enter "$d0/fteqcc" verbose
617                 if $cleanqcc; then
618                         verbose make $MAKEFLAGS clean
619                 fi
620                 verbose make $MAKEFLAGS
621
622                 enter "$d0/data/xonotic-data.pk3dir" verbose
623                 if $cleanqc; then
624                         verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS clean
625                 fi
626                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS
627
628                 enter "$d0/darkplaces" verbose
629                 if [ x"$BAD_TARGETS" = x" " ]; then
630                         echo "Warning: invalid empty client, default clients will be used."
631                 fi
632                 if $cleandp; then
633                         verbose make $MAKEFLAGS clean
634                 fi
635                 for T in $TARGETS; do
636                         verbose make $MAKEFLAGS "$@" "$T"
637                 done
638                 for T in $BAD_TARGETS; do
639                         echo "Warning: discarded invalid client $T."
640                 done
641
642                 verbose "$SELF" update-maps
643                 ;;
644         run)
645                 if [ -n "$WE_HATE_OUR_USERS" ]; then
646                         client=
647                         export PATH="$d0/misc/buildfiles/win32:$PATH"
648                 elif [ x"`uname`" = x"Darwin" ]; then
649                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/MacOS"
650                         export DYLD_FRAMEWORK_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks"
651                         client=-sdl
652                 else
653                         client=-sdl
654                 fi
655                 case "$1" in
656                         sdl|glx|agl|dedicated)
657                                 client=-$1
658                                 shift
659                                 ;;
660                         wgl)
661                                 client=
662                                 shift
663                                 ;;
664                 esac
665                 if ! [ -x "darkplaces/darkplaces$client" ]; then
666                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
667                                 client=$client.exe
668                         else
669                                 echo "Client darkplaces/darkplaces$client not found, aborting"
670                                 exit 1
671                         fi
672                 fi
673                 set -- "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic -mygames "$@"
674                 # change this to:
675                 #set -- "darkplaces/darkplaces$client" -xonotic -mygames "$@"
676
677                 # if pulseaudio is running: USE IT
678                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
679                         if ps -C pulseaudio >/dev/null; then
680                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
681                                         export SDL_AUDIODRIVER=pulse
682                                 fi
683                         fi
684                 fi
685
686                 if [ -n "$USE_GDB" ]; then
687                         set -- gdb --args "$@"
688                 fi
689                 "$@"
690                 ;;
691         each|foreach)
692                 keep_going=false
693                 if [ x"$1" = x"-k" ]; then
694                         keep_going=true
695                         shift
696                 fi
697                 for d in $repos; do
698                         if verbose cd "$d0/$d"; then
699                                 if $keep_going; then
700                                         verbose "$@" || true
701                                 else
702                                         verbose "$@"
703                                 fi
704                                 cd "$d0"
705                         fi
706                 done
707                 ;;
708         save-patches)
709                 outfile=$1
710                 patchdir=`mktemp -d -t save-patches.XXXXXX`
711                 for d in $repos; do
712                         enter "$d0/$d" verbose
713                         git branch -v -v | cut -c 3- | {
714                                 i=0
715                                 while read -r BRANCH REV UPSTREAM TEXT; do
716                                         case "$UPSTREAM" in
717                                                 \[*)
718                                                         UPSTREAM=${UPSTREAM#\[}
719                                                         UPSTREAM=${UPSTREAM%\]}
720                                                         UPSTREAM=${UPSTREAM%:*}
721                                                         TRACK=true
722                                                         ;;
723                                                 *)
724                                                         UPSTREAM=origin/"`repobranch "$d"`"
725                                                         TRACK=false
726                                                         ;;
727                                         esac
728                                         if [ x"$REV" = x"->" ]; then
729                                                 continue
730                                         fi
731                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
732                                                 echo "$d" > "$patchdir/$i/info.txt"
733                                                 echo "$BRANCH" >> "$patchdir/$i/info.txt"
734                                                 echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
735                                                 echo "$TRACK" >> "$patchdir/$i/info.txt"
736                                                 i=$(($i+1))
737                                         else
738                                                 rm -rf "$patchdir/$i"
739                                         fi
740                                 done
741                         }
742                 done
743                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
744                 rm -rf "$patchdir"
745                 ;;
746         restore-patches)
747                 infile=$1
748                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
749                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
750                 # detach the head
751                 for P in "$patchdir"/*/info.txt; do
752                         D=${P%/info.txt}
753                         exec 3<"$P"
754                         read -r d <&3
755                         read -r BRANCH <&3
756                         read -r UPSTREAM <&3
757                         read -r TRACK <&3
758                         verbose git checkout HEAD^0
759                         verbose git branch -D "$BRANCH"
760                         if [ x"$TRACK" = x"true" ]; then
761                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
762                         else
763                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
764                         fi
765                         verbose git am "$D"
766                 done
767                 rm -rf "$patchdir"
768                 ;;
769         admin-merge)
770                 branch=$1
771                 t=`mktemp`
772                 report=""
773                 reportecho()
774                 {
775                         report=$report"$*$LF"
776                         echo "$*"
777                 }
778                 reportecho4()
779                 {
780                         report=$report"    $*$LF"
781                         echo "    $*"
782                 }
783                 reportdo4()
784                 {
785                         o=`"$@" | sed 's/^/    /' || true`
786                         reportecho "$o"
787                 }
788                 for d in $repos; do
789                         enter "$d0/$d" verbose
790                         base="`repobranch "$d"`"
791                         reportecho "In $d:"
792                         for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
793                                 case "${ref#refs/remotes/origin/}" in
794                                         "$base")
795                                                 continue
796                                                 ;;
797                                         HEAD|master)
798                                                 continue
799                                                 ;;
800                                         */*)
801                                                 ;;
802                                         *)
803                                                 continue
804                                                 ;;
805                                 esac
806                                 if [ -n "$branch" ]; then
807                                         if [ x"$branch" != x"${ref#refs/remotes/origin/}" ]; then
808                                                 continue
809                                         fi
810                                 fi
811                                 case "$base" in
812                                         master)
813                                                 realbase=$base
814                                                 ;;
815                                         *)
816                                                 l0=`git rev-list "$base".."$ref" | wc -l`
817                                                 l1=`git rev-list master.."$ref" | wc -l`
818                                                 if [ $l0 -gt $l1 ]; then
819                                                         realbase=master
820                                                 else
821                                                         realbase=$base
822                                                 fi
823                                                 ;;
824                                 esac
825                                 reportecho "  Branch $ref:"
826                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
827                                 logdata=`git log --color "$realbase".."$ref"`
828                                 if [ -z "$logdata" ]; then
829                                         reportecho4 "--> not merging, no changes vs master"
830                                         if yesno "Branch \"$ref\" probably should get deleted. Do it?" ''; then
831                                                 git push origin :"${ref#refs/remotes/origin/}"
832                                                 reportecho4 "--> branch deleted"
833                                         fi
834                                 else
835                                         diffdata=`git diff --color --find-copies-harder --ignore-space-change "$realbase"..."$ref"`
836                                         if [ -z "$diffdata" ]; then
837                                                 reportecho4 "--> not merging, no changes vs master, branch contains redundant history"
838                                                 if yesno "Branch \"$ref\" probably should get deleted. Do it?" '{ echo "$logdata"; } | less -r'; then
839                                                         git push origin :"${ref#refs/remotes/origin/}"
840                                                         reportecho4 "--> branch deleted"
841                                                 fi
842                                         elif [ -z "$branch" ] && [ -n "$note" ]; then
843                                                 reportdo4 echo "$note"
844                                                 reportecho4 "--> not merging, already had this one rejected before"
845                                         elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ echo "$logdata"; echo "$diffdata"; } | less -r'; then
846                                                 git checkout "$realbase"
847                                                 org=`git rev-parse HEAD`
848                                                 if ! git merge --no-ff "$ref" 2>&1 | tee "$t" && ! { git ls-files -u | grep ' 1 ' >/dev/null; }; then
849                                                         git reset --hard "$org"
850                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Merge failed:$LF`cat "$t"`" "$ref"
851                                                         reportdo4 cat "$t"
852                                                         reportecho4 "--> merge failed"
853                                                 elif ! "$SELF" compile -n 2>&1 | tee "$t"; then
854                                                         git reset --hard "$org"
855                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Compile failed:$LF`cat "$t"`" "$ref"
856                                                         reportdo4 cat "$t"
857                                                         reportecho4 "--> compile failed"
858                                                 elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
859                                                         git reset --hard "$org"
860                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
861                                                         note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
862                                                         if [ x"$note" = x"del" ]; then
863                                                                 git push origin :"${ref#refs/remotes/origin/}"
864                                                                 reportecho4 "--> test failed, branch deleted"
865                                                         elif [ -n "$note" ]; then
866                                                                 reportdo4 echo "$note"
867                                                                 reportecho4 "--> test failed"
868                                                         else
869                                                                 reportecho4 "--> test failed, postponed"
870                                                         fi
871                                                 else
872                                                         echo "MERGING"
873                                                         case ",`repoflags "$d"`," in
874                                                                 *,svn,*)
875                                                                         # we do quite a mess here... luckily we know $org
876                                                                         git fetch # svn needs to be current
877                                                                         git rebase -i --onto origin/master "$org"
878                                                                         git svn dcommit --add-author-from
879                                                                         git reset --hard "$org"
880                                                                         ;;
881                                                                 *)
882                                                                         git push origin HEAD
883                                                                         ;;
884                                                         esac
885                                                         reportecho4 "--> MERGED"
886                                                         if yesno "Delete original branch \"$ref\"?"; then
887                                                                 git push origin :"${ref#refs/remotes/origin/}"
888                                                                 reportecho4 "--> branch deleted"
889                                                         fi
890                                                 fi
891                                         else
892                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
893                                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
894                                                 if [ x"$note" = x"del" ]; then
895                                                         git push origin :"${ref#refs/remotes/origin/}"
896                                                         reportecho4 "--> branch deleted"
897                                                 elif [ -n "$note" ]; then
898                                                         reportdo4 echo "$note"
899                                                         reportecho4 "--> rejected"
900                                                 else
901                                                         reportecho4 "--> postponed"
902                                                 fi
903                                         fi
904                                 fi
905                                 reportecho ""
906                         done
907                         reportecho ""
908                 done
909                 rm -f "$t"
910                 echo "$report" | ssh nexuiz@rm.endoftheinternet.org cat '>>' public_html/xonotic-merge-notes.txt
911                 ;;
912         clean)
913                 force=false
914                 if [ x"$1" = x"-f" ]; then
915                         force=true
916                 fi
917                 for d in $repos; do
918                         verbose cd "$d0/$d"
919                         if $force; then
920                                 verbose git reset --hard
921                                 #redundant# verbose git checkout-index -fa
922                         fi
923                         case "$d" in
924                                 .)
925                                         verbose git clean -df
926                                         ;;
927                                 *)
928                                         verbose git clean -xdf
929                                         ;;
930                         esac
931                 done
932                 ;;
933
934         # release building goes here
935         release-prepare)
936                 #"$SELF" each git clean -fxd
937                 case "$RELEASETYPE" in
938                         beta)
939                                 msg "Building a BETA"
940                                 ;;
941                         release)
942                                 msg "Building a RELEASE"
943                                 ;;
944                         *)
945                                 msg "Must either set RELEASETYPE=beta or RELEASETYPE=release"
946                                 exit 1
947                                 ;;
948                 esac
949                 verbose rm -rf Xonotic Xonotic*.zip
950                 verbose mkdir -p Xonotic
951                 if [ -n "$RELEASEDATE" ]; then
952                         verbose echo "$RELEASEDATE" > Xonotic/stamp.txt
953                 else
954                         verbose date +%Y%m%d > Xonotic/stamp.txt
955                 fi
956                 verbose git archive --format=tar HEAD -- Docs misc server xonotic-linux-glx.sh xonotic-linux-sdl.sh misc/buildfiles | {
957                         verbose cd Xonotic
958                         verbose mkdir data fteqcc source source/darkplaces source/fteqcc
959                         verbose tar xvf -
960                         verbose rm -rf misc/builddeps
961                         verbose mv misc/buildfiles/win32/* . || true
962                         verbose mv misc/buildfiles/win64 bin64 || true
963                         verbose mv misc/buildfiles/osx/* . || true
964                         verbose rm -rf misc/buildfiles
965                 }
966                 {
967                         verbose cd darkplaces
968                         verbose git archive --format=tar HEAD
969                 } | {
970                         verbose cd Xonotic/source/darkplaces
971                         verbose tar xvf -
972                 }
973                 {
974                         verbose cd fteqcc
975                         verbose git archive --format=tar HEAD
976                 } | {
977                         verbose cd Xonotic/source/fteqcc
978                         verbose tar xvf -
979                 }
980                 {
981                         verbose cd data/xonotic-data.pk3dir
982                         verbose git archive --format=tar HEAD -- qcsrc Makefile
983                 } | {
984                         verbose cd Xonotic/source
985                         verbose tar xvf -
986                 }
987                 ;;
988         release-compile-run)
989                 host=$1
990                 buildpath=$2
991                 maketargets=$3
992                 makeflags=$4
993                 srcdir=$5
994                 depsdir=$6
995                 targetfiles=$7
996                 set -x
997                 if [ -n "$targetfiles" ]; then
998                         case " $HOSTS_THAT_ARE_DISABLED " in
999                                 *\ $host\ *)
1000                                         exit
1001                                         ;;
1002                         esac
1003                         case " $HOSTS_THAT_ARE_MYSELF " in
1004                                 *\ $host\ *)
1005                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$buildpath/"
1006                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$buildpath.deps/"
1007                                         verbose ln -snf "$buildpath.deps" "$buildpath/.deps"
1008                                         verbose eval make -C "$buildpath" clean $maketargets $makeflags
1009                                         for f in $targetfiles; do
1010                                                 verbose mv "$buildpath/${f%:*}" "${f##*:}" || true
1011                                         done
1012                                         ;;
1013                                 *)
1014                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$host:$buildpath/"
1015                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$host:$buildpath.deps/"
1016                                         verbose ssh "$host" "ln -snf $buildpath.deps $buildpath/.deps && cd $buildpath && nice -`nice` make clean $maketargets $makeflags"
1017                                         for f in $targetfiles; do
1018                                                 verbose rsync -zvaSHP "$host:$buildpath/${f%:*}" "${f##*:}" || true
1019                                         done
1020                                         ;;
1021                         esac
1022                         # now rebrand the binaries...
1023                         for f in $targetfiles; do
1024                                 #verbose "$d0/misc/tools/rebrand-darkplaces-engine.sh" "${XONOTIC_BRAND:-$d0/misc/tools/xonotic.brand}" "${f##*:}" || true
1025                                 case "$f" in
1026                                         xonotic*.exe)
1027                                                 verbose "$d0/misc/tools/change-icon-of-exe.sh" "$d0/misc/logos/icons_ico/xonotic.ico" "$f"
1028                                                 (
1029                                                         d=`mktemp -d -t rebrand.XXXXXX`
1030                                                         cd "$d"
1031                                                         echo "-mygames" > darkplaces.opt
1032                                                         zip -9r darkplaces.zip darkplaces.opt
1033                                                         cat darkplaces.zip
1034                                                         cd "$d0"
1035                                                         rm -rf "$d"
1036                                                 ) >> "$f"
1037                                                 ;;
1038                                 esac
1039                         done
1040                 fi
1041                 ;;
1042         release-compile)
1043                 suffix=$1
1044                 makeflags=$2
1045                 fteqcc_maketargets=$3
1046                 fteqcc_files=$4
1047                 darkplaces_maketargets=$5
1048                 darkplaces_files=$6
1049                 host=xonotic-build-$suffix
1050                 verbose "$SELF" release-compile-run "$host" /tmp/fteqcc.build."$suffix" "$fteqcc_maketargets" "$makeflags" "Xonotic/source/fteqcc" "$d0/misc/builddeps/dp.$suffix" "$fteqcc_files"
1051                 verbose "$SELF" release-compile-run "$host" /tmp/Darkplaces.build."$suffix" "$darkplaces_maketargets" "$makeflags" "Xonotic/source/darkplaces" "$d0/misc/builddeps/dp.$suffix" "$darkplaces_files"
1052                 ;;
1053         release-engine-win32)
1054                 # TODO change to g++ and D3D=1 when D3D gets added
1055                 verbose "$SELF" release-compile win32 \
1056                         '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' \
1057                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc.exe' \
1058                         release 'darkplaces.exe:Xonotic/xonotic.exe darkplaces-sdl.exe:Xonotic/xonotic-sdl.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated.exe'
1059                 ;;
1060         release-engine-win64)
1061                 # TODO change to g++ and D3D=1 when D3D gets added
1062                 verbose "$SELF" release-compile win64 \
1063                         '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' \
1064                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc-x64.exe' \
1065                         'sv-release cl-release' 'darkplaces.exe:Xonotic/xonotic-x64.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated-x64.exe'
1066                         # release 'darkplaces.exe:Xonotic/xonotic-x64.exe darkplaces-sdl.exe:Xonotic/xonotic-sdl-x64.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated-x64.exe'
1067                 ;;
1068         release-engine-osx-sv-sdl)
1069                 # gcc on OSX is buggy, needs -fno-reorder-blocks for a release build to succeed
1070                 verbose "$SELF" release-compile osx \
1071                         '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"' \
1072                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.osx' \
1073                         'sv-release sdl-release' 'darkplaces-sdl:Xonotic/Xonotic-SDL.app/Contents/MacOS/xonotic-osx-sdl-bin darkplaces-dedicated:Xonotic/xonotic-osx-dedicated'
1074                 ;;
1075         release-engine-osx-agl)
1076                 # gcc on OSX is buggy, needs -fno-reorder-blocks for a release build to succeed
1077                 verbose "$SELF" release-compile osx \
1078                         '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"' \
1079                         '' '' \
1080                         'cl-release' 'darkplaces-agl:Xonotic/Xonotic.app/Contents/MacOS/xonotic-osx-agl-bin'
1081                 ;;
1082         release-engine-osx)
1083                 verbose "$SELF" release-engine-osx-sv-sdl
1084                 verbose "$SELF" release-engine-osx-agl
1085                 ;;
1086         release-engine-linux32)
1087                 verbose "$SELF" release-compile linux32 \
1088                         'STRIP=: CC="gcc -m32 -g -I.deps/include -L.deps/lib" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a' \
1089                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux32' \
1090                         release 'darkplaces-glx:Xonotic/xonotic-linux32-glx darkplaces-sdl:Xonotic/xonotic-linux32-sdl darkplaces-dedicated:Xonotic/xonotic-linux32-dedicated'
1091                 ;;
1092         release-engine-linux64)
1093                 verbose "$SELF" release-compile linux64 \
1094                         'STRIP=: CC="gcc -m64 -g -I.deps/include -L.deps/lib" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a' \
1095                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux64' \
1096                         release 'darkplaces-glx:Xonotic/xonotic-linux64-glx darkplaces-sdl:Xonotic/xonotic-linux64-sdl darkplaces-dedicated:Xonotic/xonotic-linux64-dedicated'
1097                 ;;
1098         release-engine)
1099                 verbose "$SELF" release-engine-linux32 &
1100                 verbose "$SELF" release-engine-linux64 &
1101                 verbose "$SELF" release-engine-win32 &
1102                 verbose "$SELF" release-engine-win64 &
1103                 verbose "$SELF" release-engine-osx &
1104                 wait %1
1105                 wait %2
1106                 wait %3
1107                 wait %4
1108                 wait %5
1109                 wait
1110                 ;;
1111         release-maps)
1112                 verbose "$SELF" update-maps
1113                 ;;
1114         release-qc)
1115                 case "$RELEASETYPE" in
1116                         beta)
1117                                 verbose make -C Xonotic/source FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 clean all
1118                                 ;;
1119                         release)
1120                                 verbose make -C Xonotic/source FTEQCC="$d0/Xonotic/fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 FTEQCCFLAGS_WATERMARK= clean all
1121                                 ;;
1122                 esac
1123                 verbose rm -f Xonotic/source/*/fteqcc.log
1124                 ;;
1125         release-buildpk3-transform-raw)
1126                 dir=$1
1127                 ;;
1128         release-buildpk3-transform-normal)
1129                 dir=$1
1130                 verbose cd "$dir"
1131                 # texture: convert to jpeg and dds
1132                 verbose export do_jpeg=true
1133                 verbose export jpeg_qual_rgb=95
1134                 verbose export jpeg_qual_a=99
1135                 verbose export do_dds=true
1136                 verbose export dds_flags=
1137                 verbose export do_ogg=false
1138                 verbose export del_src=true
1139                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1140                 ;;
1141         release-buildpk3-transform-low)
1142                 dir=$1
1143                 verbose cd "$dir"
1144                 # texture: convert to jpeg and dds
1145                 # music: reduce bitrate
1146                 verbose export do_jpeg=true
1147                 verbose export jpeg_qual_rgb=80
1148                 verbose export jpeg_qual_a=95
1149                 verbose export do_dds=false
1150                 verbose export do_ogg=true
1151                 verbose export ogg_qual=1
1152                 verbose export del_src=true
1153                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1154                 ;;
1155         release-buildpk3-transform-lowdds)
1156                 dir=$1
1157                 verbose cd "$dir"
1158                 # texture: convert to jpeg and dds
1159                 # music: reduce bitrate
1160                 verbose export do_jpeg=false
1161                 verbose export do_jpeg_if_not_dds=true
1162                 verbose export jpeg_qual_rgb=80
1163                 verbose export jpeg_qual_a=95
1164                 verbose export do_dds=true
1165                 verbose export dds_flags=
1166                 verbose export do_ogg=true
1167                 verbose export ogg_qual=1
1168                 verbose export del_src=true
1169                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1170                 ;;
1171         release-buildpk3)
1172                 src=$1
1173                 dst=$2
1174                 transform=$3
1175                 case "$dst" in
1176                         /*)
1177                                 ;;
1178                         */)
1179                                 dst="$PWD/$dst"
1180                                 ;;
1181                 esac
1182                 verbose rm -rf Xonotic/temp
1183                 verbose mkdir -p Xonotic/temp
1184                 {
1185                         verbose cd "$src"
1186                         verbose git archive --format=tar HEAD
1187                 } | {
1188                         verbose cd Xonotic/temp
1189                         verbose tar xvf -
1190                 }
1191                 verbose cd Xonotic/temp
1192                 if [ x"$src" = x"data/xonotic-data.pk3dir" ]; then
1193                         verbose cp ../source/progs.dat .
1194                         verbose cp ../source/csprogs.dat .
1195                         verbose cp ../source/menu.dat .
1196                         verbose rm -rf qcsrc
1197                         gv=`grep "^gameversion " "defaultXonotic.cfg" | awk '{ print $2 }'`
1198                         major=$(($gv / 10000))
1199                         minor=$(($gv / 100 - $major * 100))
1200                         patch=$(($gv - $major * 10000 - $minor * 100))
1201                         versionstr="$major.$minor.$patch"
1202                         case "$RELEASETYPE" in
1203                                 beta)
1204                                         versionstr="$versionstr""beta"
1205                                         ;;
1206                         esac
1207                         verbose sed -i "
1208                                 s/^set g_xonoticversion [^ ]* /set g_xonoticversion $versionstr /;
1209                                 s/^gameversion_min [0-9]*/gameversion_min $(( ($gv / 100) * 100 - 100 ))/;
1210                                 s/^gameversion_max [0-9]*/gameversion_max $(( ($gv / 100) * 100 + 199 ))/;
1211                         " defaultXonotic.cfg
1212                         (
1213                                 verbose cd gfx/menu/luminos
1214                                 verbose cp "$d0"/mediasource/gfx/menu/luminos_versionbuilder/background_l2.svg .
1215                                 verbose "$d0"/mediasource/gfx/menu/luminos_versionbuilder/versionbuilder "$versionstr"
1216                                 verbose rm background_l2.svg
1217                         )
1218                 fi
1219                 if [ x"$src" = x"data/xonotic-maps.pk3dir" ]; then
1220                         for X in ../../data/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
1221                                 if [ -f "$X" ]; then
1222                                         verbose unzip "$X"
1223                                         verbose rm -f maps/*.log maps/*.irc maps/*.lin
1224                                 fi
1225                         done
1226                 fi
1227                 verbose export git_src_repo="$d0/$src" # skip hash-object
1228                 verbose "$SELF" release-buildpk3-transform-$transform "Xonotic/temp"
1229                 verbose mkzip "../../$dst" .
1230                 verbose cd ../..
1231                 verbose rm -rf Xonotic/temp
1232                 ;;
1233         release-buildpk3s)
1234                 stamp=`cat Xonotic/stamp.txt`
1235                 src=$1
1236                 shift
1237                 dst=${src%.pk3dir}
1238                 case "$dst" in
1239                         data/xonotic-*)
1240                                 dst="data/xonotic-$stamp-${dst#data/xonotic-}"
1241                                 ;;
1242                         *)
1243                                 dst="$dst-$stamp"
1244                                 ;;
1245                 esac
1246                 while [ "$#" -gt 1 ]; do
1247                         verbose "$SELF" release-buildpk3 "$src" "Xonotic/$dst$2.pk3" "$1"
1248                         shift
1249                         shift
1250                 done
1251                 ;;
1252         release-pack)
1253                 verbose "$SELF" release-buildpk3s data/font-nimbussansl.pk3dir             raw ''
1254                 verbose "$SELF" release-buildpk3s data/xonotic-data.pk3dir       normal '' raw '-raw' low '-low' lowdds '-lowdds'
1255                 verbose "$SELF" release-buildpk3s data/xonotic-maps.pk3dir       normal '' raw '-raw' low '-low' lowdds '-lowdds'
1256                 verbose "$SELF" release-buildpk3s data/xonotic-music.pk3dir                raw ''     low '-low'
1257                 verbose "$SELF" release-buildpk3s data/xonotic-nexcompat.pk3dir                       low ''
1258                 ;;
1259         release-pack-needsx11)
1260                 case "$DISPLAY" in
1261                         '')
1262                                 verbose startx "$SELF" release-pack -- /usr/bin/Xvfb :7
1263                                 ;;
1264                         *)
1265                                 verbose "$SELF" release-pack
1266                                 ;;
1267                 esac
1268                 ;;
1269         release-zip)
1270                 stamp=`cat Xonotic/stamp.txt`
1271                 # need to use infozip for these (+x bits)
1272                 verbose mkzip Xonotic-$stamp-engine.zip \
1273                         Xonotic/*.dll \
1274                         Xonotic/bin64/*.dll \
1275                         Xonotic/*.app \
1276                         Xonotic/xonotic-* \
1277                         Xonotic/xonotic.exe
1278                 verbose cp Xonotic-$stamp-engine.zip Xonotic-$stamp-common.zip
1279                 verbose mkzip Xonotic-$stamp-common.zip \
1280                         Xonotic/source/*/ \
1281                         Xonotic/Docs \
1282                         Xonotic/misc \
1283                         Xonotic/fteqcc \
1284                         Xonotic/server \
1285                         Xonotic/data/font-nimbussansl-$stamp.pk3
1286                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp.zip
1287                 verbose mkzip0 Xonotic-$stamp.zip \
1288                         Xonotic/data/xonotic-$stamp-data.pk3 \
1289                         Xonotic/data/xonotic-$stamp-maps.pk3 \
1290                         Xonotic/data/xonotic-$stamp-music.pk3 \
1291                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1292                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-low.zip
1293                 verbose mkzip0 Xonotic-$stamp-low.zip \
1294                         Xonotic/data/xonotic-$stamp-data-low.pk3 \
1295                         Xonotic/data/xonotic-$stamp-maps-low.pk3 \
1296                         Xonotic/data/xonotic-$stamp-music-low.pk3
1297                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-lowdds.zip
1298                 verbose mkzip0 Xonotic-$stamp-lowdds.zip \
1299                         Xonotic/data/xonotic-$stamp-data-lowdds.pk3 \
1300                         Xonotic/data/xonotic-$stamp-maps-lowdds.pk3 \
1301                         Xonotic/data/xonotic-$stamp-music-low.pk3
1302                 verbose mv Xonotic-$stamp-common.zip Xonotic-$stamp-high.zip
1303                 verbose mkzip0 Xonotic-$stamp-high.zip \
1304                         Xonotic/data/xonotic-$stamp-data-raw.pk3 \
1305                         Xonotic/data/xonotic-$stamp-maps-raw.pk3 \
1306                         Xonotic/data/xonotic-$stamp-music.pk3 \
1307                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1308                 ;;
1309         release)
1310                 verbose "$SELF" release-prepare
1311                 verbose "$SELF" release-maps
1312                 verbose "$SELF" release-engine
1313                 verbose "$SELF" release-qc
1314                 verbose "$SELF" release-pack-needsx11
1315                 verbose "$SELF" release-zip
1316                 ;;
1317
1318         *)
1319                 echo "Usage:"
1320                 echo "  $SELF pull"
1321                 echo "  $SELF merge"
1322                 echo "  $SELF push [-s]"
1323                 echo "  $SELF branches"
1324                 echo "  $SELF branch [<remote>] <branchname>"
1325                 echo "  $SELF branch <remote> <branchname> <srcbranchname>"
1326                 echo "  $SELF checkout [<remote>] <branchname>"
1327                 echo "  $SELF compile [-c|-n] [<client>] <options>"
1328                 echo "  $SELF run [<client>] <options>"
1329                 echo "  $SELF each <command>"
1330                 ;;
1331 esac