]> git.xonotic.org Git - xonotic/xonotic.git/blob - all
fudge factors for mirrors: NL mirror gets a 50% malus in the mirror selection
[xonotic/xonotic.git] / all
1 #!/bin/sh
2 # vim: filetype=zsh
3
4 set -e
5 if [ -n "$ZSH_VERSION" ]; then
6         setopt SH_WORD_SPLIT
7 fi
8 if [ -z "$ECHO" ]; then
9         if echo "\\\\" | grep .. >/dev/null; then
10                 ECHO=echo
11         else
12                 ECHO=`which echo`
13         fi
14 fi
15
16 # I use this in EVERY shell script ;)
17 LF="
18 "
19 ESC="\e"
20
21 d00=`pwd`
22 while ! [ -f ./all ]; do
23         if [ x"`pwd`" = x"/" ]; then
24                 $ECHO "Cannot find myself."
25                 $ECHO "Please run this script with the working directory inside a Xonotic checkout."
26                 exit 1
27         fi
28         cd ..
29 done
30 export d0=`pwd`
31 SELF="$d0/all"
32
33 # If we are on WINDOWS:
34 case "$0" in
35         all|*/all)
36                 case "`uname`" in
37                         MINGW*|Win*)
38                                 # Windows hates users. So this script has to copy itself elsewhere first...
39                                 cp "$SELF" ../all.xonotic.sh
40                                 export WE_HATE_OUR_USERS=1
41                                 exec ../all.xonotic.sh "$@"
42                                 ;;
43                 esac
44                 ;;
45 esac
46
47 msg()
48 {
49         $ECHO >&2 "$ESC""[1m$*$ESC""[m"
50 }
51
52 self=`git hash-object "$SELF"`
53 checkself()
54 {
55         self_new=`git hash-object "$SELF"`
56         if [ x"$self" != x"$self_new" ]; then
57                 msg "./all has changed."
58                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
59                         msg "Rerunning the requested operation to make sure."
60                         export XONOTIC_FORBID_RERUN_ALL=1
61                         exec "$SELF" "$@"
62                 else
63                         msg "Please try $SELF update, and then retry your requested operation."
64                         exit 1
65                 fi
66         fi
67         return 0
68 }
69
70 verbose()
71 {
72         msg "+ $*"
73         "$@"
74 }
75
76 visible_repo_name()
77 {
78         case "$1" in
79                 .)
80                         $ECHO "the root directory"
81                         ;;
82                 *)
83                         $ECHO "\"$1\""
84                         ;;
85         esac
86 }
87
88 check_mergeconflict()
89 {
90         if git ls-files -u | grep ' 1   '; then
91                 $ECHO
92                 $ECHO "MERGE CONFLICT."
93                 $ECHO "change into the \"$1\" project directory, and then:"
94                 $ECHO "- edit the files mentioned above with your favorite editor,"
95                 $ECHO "  and fix the conflicts (marked with <<<<<<< blocks)"
96                 $ECHO "- for binary files, you can select the files using"
97                 $ECHO "  git checkout --ours or git checkout --theirs"
98                 $ECHO "- when done with a file, 'git add' the file"
99                 $ECHO "- when done, 'git commit'"
100                 $ECHO
101                 exit 1
102         fi
103 }
104
105 yesno()
106 {
107         yesno=
108         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
109                 eval "$2"
110                 $ECHO "$1"
111                 IFS= read -r yesno
112         done
113         [ x"$yesno" = x"y" ]
114 }
115
116 enter()
117 {
118         $2 cd "$1" || exit 1
119         check_mergeconflict "$1"
120 }
121
122 repos_urls="
123 .                             |                                                   | master         |
124 data/xonotic-data.pk3dir      |                                                   | master         |
125 data/xonotic-music.pk3dir     |                                                   | master         |
126 data/xonotic-nexcompat.pk3dir |                                                   | master         | no
127 darkplaces                    |                                                   | div0-stable    | svn
128 netradiant                    |                                                   | master         |
129 div0-gittools                 |                                                   | master         | no
130 d0_blind_id                   |                                                   | master         |
131 data/xonotic-maps.pk3dir      |                                                   | master         |
132 mediasource                   |                                                   | master         | no
133 fteqcc                        |                                                   | xonotic-stable | noautocrlf
134 "
135 # todo: in darkplaces, change repobranch to div0-stable
136
137 repos=`$ECHO "$repos_urls" | grep . | cut -d '|' -f 1 | tr -d ' '`
138
139 base=`git config remote.origin.url`
140 case "$base" in
141         */xonotic.git)
142                 base=${base%xonotic.git}
143                 ;;
144         *)
145                 $ECHO "The main repo is not xonotic.git, what have you done?"
146                 exit 1
147                 ;;
148 esac
149 pushbase=`git config remote.origin.pushurl || true`
150 case "$pushbase" in
151         */xonotic.git)
152                 pushbase=${pushbase%xonotic.git}
153                 ;;
154         '')
155                 ;;
156         *)
157                 $ECHO "The main repo is not xonotic.git, what have you done?"
158                 exit 1
159                 ;;
160 esac
161
162 repourl()
163 {
164         repo_t=`$ECHO "$repos_urls" | grep "^$1 " | cut -d '|' -f 2 | tr -d ' '`
165         if [ -n "$repo_t" ]; then
166                 case "$repo_t" in
167                         *://*)
168                                 $ECHO "$repo_t"
169                                 ;;
170                         *)
171                                 $ECHO "$base$repo_t"
172                                 ;;
173                 esac
174         else
175                 if [ x"$1" = x"." ]; then
176                         $ECHO "$base""xonotic.git"
177                 else
178                         $ECHO "$base${1##*/}.git"
179                 fi
180         fi
181 }
182
183 repopushurl()
184 {
185         [ -n "$pushbase" ] || return 0
186         repo_t=`$ECHO "$repos_urls" | grep "^$1 " | cut -d '|' -f 2 | tr -d ' '`
187         if [ -n "$repo_t" ]; then
188                 case "$repo_t" in
189                         *://*)
190                                 ;;
191                         *)
192                                 $ECHO "$pushbase$repo_t"
193                                 ;;
194                 esac
195         else
196                 if [ x"$1" = x"." ]; then
197                         $ECHO "$pushbase""xonotic.git"
198                 else
199                         $ECHO "$pushbase${1##*/}.git"
200                 fi
201         fi
202 }
203
204 repobranch()
205 {
206         repo_t=`$ECHO "$repos_urls" | grep "^$1 " | cut -d '|' -f 3 | tr -d ' '`
207         if [ -n "$repo_t" ]; then
208                 $ECHO "$repo_t"
209         else
210                 $ECHO "master"
211         fi
212 }
213
214 repoflags()
215 {
216         $ECHO "$repos_urls" | grep "^$1 " | cut -d '|' -f 4 | tr -d ' '
217 }
218
219 listrepos()
220 {
221         for d in $repos; do
222                 p="${d%dir}"
223                 f="`repoflags "$d"`"
224                 # if we have the dir, always keep it
225                 if [ -d "$d" ]; then
226                         msg "Repository $d enabled because it already exists"
227                         $ECHO "$d"
228                         continue
229                 fi
230                 # if .yes file exists, always keep it
231                 if [ -f "$d.yes" ]; then
232                         msg "Repository $d enabled by a .yes file"
233                         $ECHO "$d"
234                         continue
235                 fi
236                 # if we have .no file, skip
237                 if [ -f "$d.no" ]; then
238                         msg "Repository $d disabled by a .no file, delete $p.no to enable"
239                         continue
240                 fi
241                 # if we have matching pk3, skip
242                 if [ x"$p" != x"$d" ] && [ -f "$p" ]; then
243                         msg "Repository $d disabled by matching .pk3 file, delete $p or create $d.yes to enable"
244                         continue
245                 fi
246                 # if "no" flag is set, skip
247                 case ",$f," in
248                         *,no,*)
249                                 msg "Repository $d disabled by default, create $d.yes to enable"
250                                 continue
251                                 ;;
252                 esac
253                 # default: enable
254                 msg "Repository $d enabled by default"
255                 $ECHO "$d"
256         done
257 }
258
259 repos=`listrepos`
260
261 if [ "$#" = 0 ]; then
262         set -- help
263 fi
264 cmd=$1
265 shift
266
267 fix_upstream_rebase()
268 {
269         if [ -z "$r_me" ] || [ -z "$r_other" ]; then
270                 return
271         fi
272         r_base=`git merge-base "$r_me" "$r_other"`
273
274         # no merge-base? upstream did filter-branch
275         if [ -n "$r_base" ]; then
276                 # otherwise, check if the two histories are "similar"
277                 r_l_me=`git log --pretty="format:%s" "$r_other".."$r_me" | grep -v "^Merge" | sort -u`
278                 r_l_other=`git log --pretty="format:%s" "$r_me".."$r_other" | grep -v "^Merge" | sort -u`
279
280                 # heuristics: upstream rebase/filter-branch if more than 50% of the commits of one of the sides are in the other too
281                 r_lc_me=`$ECHO "$r_l_me" | wc -l`
282                 r_lc_other=`$ECHO "$r_l_other" | wc -l`
283                 r_lc_together=`{ $ECHO "$r_l_me"; $ECHO "$r_l_other"; } | sort -u | wc -l`
284                 r_lc_same=$(($r_lc_me + $r_lc_other - $r_lc_together))
285
286                 if [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_me )) ] || [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_other )) ]; then
287                         if yesno "Probable upstream rebase detected, automatically fix?" 'git log --oneline --graph --date-order --left-right "$r_other"..."$r_me"'; then
288                                 git reset --hard "$r_me"
289                                 git pull --rebase
290                                 return 1
291                         fi
292                 fi
293         fi
294
295         return 0
296 }
297
298 fix_upstream_rebase_mergeok()
299 {
300         r_me=`git rev-parse --revs-only HEAD^1 2>/dev/null || true`
301         r_other=`git rev-parse --revs-only HEAD^2 2>/dev/null || true`
302         fix_upstream_rebase
303 }
304
305 fix_upstream_rebase_mergefail()
306 {
307         r_me=`git rev-parse --revs-only HEAD 2>/dev/null || true`
308         r_other=`git rev-parse --revs-only MERGE_HEAD 2>/dev/null || true`
309         fix_upstream_rebase
310 }
311
312 fix_git_config()
313 {
314         verbose git config remote.origin.url "$1"
315         if [ -n "$2" ]; then
316                 verbose git config remote.origin.pushurl "$2"
317         else
318                 verbose git config --unset remote.origin.pushurl || true
319         fi
320         verbose git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
321         case ",`repoflags "$d"`," in
322                 *,noautocrlf,*)
323                         verbose git config --unset core.autocrlf || true
324                         ;;
325                 *)
326                         verbose git config core.autocrlf input
327                         ;;
328         esac
329         if [ -z "`git config push.default || true`" ]; then
330                 verbose git config push.default current # or is tracking better?
331         fi
332         verbose git config filter.mapclean.clean "tr -d '\r' | grep '^[^/]'"
333         verbose git config filter.mapclean.smudge "cat"
334 }
335
336 mkzip()
337 {
338         archive=$1
339         shift
340         ziplist=`mktemp`
341         find "$@" -xtype f \( -executable -or -type l \) -print > "$ziplist"
342         7za a -tzip -mx=9 -x@"$ziplist" "$archive" "$@" || true
343         zip         -9y   -@<"$ziplist" "$archive"      || true
344         rm -f "$ziplist"
345 }
346
347 mkzip0()
348 {
349         zip -0y "$@"
350 }
351
352 mirrorspeed()
353 {
354         # first result is to be ignored, but we use it to check status
355         git ls-remote "$1" refs/heads/master >/dev/null 2>&1 || return 1
356         { time -p git ls-remote "$1" refs/heads/master; } 2>&1 >/dev/null | head -n 1 | cut -d ' ' -f 2 | tr -d . | sed 's,^0*,,'
357                 # unit: clock ticks (depends on what "time" returns
358 }
359
360 bestmirror()
361 {
362         pre=$1; shift
363         suf=$1; shift
364
365         if ! { time -p true; } >/dev/null 2>&1; then
366                 return 1
367         fi
368
369         bestin=
370         bestt=
371         for mir in "$@"; do
372                 case "$mir" in
373                         *:*)
374                                 in=${mir%%:*}
375                                 op=${mir#*:}
376                                 ;;
377                         *)
378                                 in=$mir
379                                 op=
380                                 ;;
381                 esac
382                 m=$pre$in$suf
383                 if t=`mirrorspeed "$m"`; then
384                         if [ -n "$t" ]; then
385                                 t=$(($t$op)) # fudge factor
386                                 msg "$m -> $t ticks ($op)"
387                                 if [ -z "$bestt" ] || [ "$t" -lt "$bestt" ]; then
388                                         bestin=$in
389                                         bestt=$t
390                                 fi
391                         else
392                                 msg "$m -> error"
393                         fi
394                 else
395                         msg "$m -> FAIL"
396                 fi
397         done
398         if [ -n "$bestin" ]; then
399                 msg "Best mirror seems to be $pre$bestin$suf"
400                 $ECHO "$bestin"
401         else
402                 return 1
403         fi
404 }
405
406 case "$cmd" in
407         fix_upstream_rebase)
408                 for d in $repos; do
409                         enter "$d0/$d" verbose
410                         verbose fix_upstream_rebase_mergefail && verbose fix_upstream_rebase_mergeok
411                 done
412                 ;;
413         fix_config)
414                 for d in $repos; do
415                         url=`repourl "$d"`
416                         pushurl=`repopushurl "$d"`
417                         branch=`repobranch "$d"`
418                         if [ -d "$d0/$d" ]; then
419                                 verbose cd "$d0/$d"
420                                 fix_git_config "$url" "$pushurl"
421                                 cd "$d0"
422                         fi
423                 done
424                 ;;
425         keygen)
426                 # enable the ssh URL for pushing
427                 "$SELF" update -N -p
428
429                 if [ -f ~/.ssh/id_rsa.pub ]; then
430                         msg ""
431                         msg "A key already exists and no new one will be generated. If you"
432                         msg "already have done the procedure for getting your key approved, you"
433                         msg "can skip the following paragraph and already use the repository."
434                         msg ""
435                         msg "To get access, your key has to be approved first. For that, visit"
436                         msg "http://dev.xonotic.org/, then log in, create a \"New Issue\" on"
437                         msg "the \"Support\" tracker in the \"Repository\" category where you"
438                         msg "apply for access and paste the following output into the issue:"
439                         msg ""
440                         msg "`cat ~/.ssh/id_rsa.pub`"
441                         msg ""
442                         msg "Note that you will only have write access to branches that start"
443                         msg "with your user name."
444                 elif [ -f ~/.ssh/id_dsa.pub ]; then
445                         msg ""
446                         msg "A key already exists and no new one will be generated. If you"
447                         msg "already have done the procedure for getting your key approved, you"
448                         msg "can skip the following paragraph and already use the repository."
449                         msg ""
450                         msg "To get access, your key has to be approved first. For that, visit"
451                         msg "http://dev.xonotic.org/, then log in, create a \"New Issue\" on"
452                         msg "the \"Support\" tracker in the \"Repository\" category where you"
453                         msg "apply for access and paste the following output into the issue:"
454                         msg ""
455                         msg "`cat ~/.ssh/id_dsa.pub`"
456                         msg ""
457                         msg "Note that you will only have write access to branches that start"
458                         msg "with your user name."
459                 else
460                         msg ""
461                         msg "No key has been generated yet. One will be generated now."
462                         msg "If other people are using your computer, it is recommended"
463                         msg "to specify a passphrase. Otherwise you can simply hit ENTER"
464                         msg "when asked for a passphrase."
465                         msg ""
466                         ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
467                         msg ""
468                         msg "To get access, your key has to be approved first. For that, visit"
469                         msg "http://dev.xonotic.org/, then log in, create a \"New Issue\" on"
470                         msg "the \"Support\" tracker in the \"Repository\" category where you"
471                         msg "apply for access and paste the following output into the issue:"
472                         msg ""
473                         msg "`cat ~/.ssh/id_rsa.pub`"
474                         msg ""
475                         msg "Note that you will only have write access to branches that start"
476                         msg "with your user name."
477                 fi
478                 ;;
479         update|pull)
480                 allow_pull=true
481                 fix_config=false
482                 location=current
483                 while :; do
484                         if [ x"$1" = x"-N" ]; then
485                                 allow_pull=false
486                         elif [ x"$1" = x"-p" ]; then
487                                 fix_config=true
488                                 if [ x"$base" != x"ssh://xonotic@git.xonotic.org/" ]; then
489                                         pushbase=ssh://xonotic@git.xonotic.org/
490                                 fi
491                         elif [ x"$1" = x"-s" ]; then
492                                 fix_config=true
493                                 base=ssh://xonotic@git.xonotic.org/
494                                 pushbase=
495                         elif [ x"$1" = x"-g" ]; then
496                                 fix_config=true
497                                 base=git://git.xonotic.org/xonotic/
498                         elif [ x"$1" = x"-h" ]; then
499                                 fix_config=true
500                                 base=http://git.xonotic.org/xonotic/
501                         elif [ x"$1" = x"-l" ]; then
502                                 case "$2" in
503                                         nl) ;;
504                                         de) ;;
505                                         us) ;;
506                                         best) ;;
507                                         default) ;;
508                                         *)
509                                                 msg "Invalid location!"
510                                                 msg "Possible locations for the -l option:"
511                                                 msg "  nl (Netherlands, run by merlijn)"
512                                                 msg "  de (Germany, run by divVerent)"
513                                                 msg "  us (United States of America, run by detrate)"
514                                                 msg "  best (find automatically)"
515                                                 msg "  default (currently nl)"
516                                                 exit 1
517                                                 ;;
518                                 esac
519                                 fix_config=true
520                                 location=$2
521                                 shift
522                         else
523                                 break
524                         fi
525                         shift
526                 done
527                 case "$location" in
528                         best)
529                                 newbase=`$ECHO "$base" | sed "s,://\(.*\.\)\?git.xonotic.org/,:// .git.xonotic.org/,"`
530                                 case "$newbase" in
531                                         *\ *)
532                                                 if location=`bestmirror $newbase"xonotic.git" de us nl:'*3/2'`; then
533                                                         :
534                                                 else
535                                                         location=current
536                                                 fi
537                                                 ;;
538                                         *)
539                                                 location=current
540                                                 ;;
541                                 esac
542                                 ;;
543                 esac
544                 case "$location" in
545                         default)
546                                 location=
547                                 ;;
548                         current)
549                                 case "$base" in
550                                         *://*.git.xonotic.org/*)
551                                                 location=${base%%.git.xonotic.org/*}
552                                                 location=${location##*://}
553                                                 ;;
554                                         *)
555                                                 location=
556                                                 ;;
557                                 esac
558                                 ;;
559                 esac
560                 if [ -n "$location" ]; then
561                         base=`$ECHO "$base" | sed "s,://\(.*\.\)\?git.xonotic.org/,://$location.git.xonotic.org/,"`
562                         pushbase=`$ECHO "$pushbase" | sed "s,://\(.*\.\)\?git.xonotic.org/,://$location.git.xonotic.org/,"`
563                 else
564                         base=`$ECHO "$base" | sed "s,://\(.*\.\)\?git.xonotic.org/,://git.xonotic.org/,"`
565                         pushbase=`$ECHO "$pushbase" | sed "s,://\(.*\.\)\?git.xonotic.org/,://git.xonotic.org/,"`
566                 fi
567                 if $fix_config; then
568                         url=`repourl .`
569                         pushurl=`repopushurl .`
570                         fix_git_config "$url" "$pushurl"
571                 fi
572                 if $allow_pull || $fix_config; then
573                         "$SELF" fix_config
574                 fi
575                 for d in $repos; do
576                         url=`repourl "$d"`
577                         pushurl=`repopushurl "$d"`
578                         branch=`repobranch "$d"`
579                         if [ -d "$d0/$d" ]; then
580                                 if $allow_pull; then
581                                         enter "$d0/$d" verbose
582                                         r=`git symbolic-ref HEAD`
583                                         r=${r#refs/heads/}
584                                         if git config branch.$r.remote >/dev/null 2>&1; then
585                                                 if ! verbose git pull; then
586                                                         fix_upstream_rebase_mergefail || true
587                                                         check_mergeconflict "$d"
588                                                         $ECHO "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
589                                                         read -r DUMMY
590                                                 else
591                                                         fix_upstream_rebase_mergeok || true
592                                                 fi
593                                         fi
594
595                                         cd "$d00"
596                                         checkself "$cmd" "$@"
597                                         cd "$d0/$d"
598                                         verbose git remote prune origin
599                                         cd "$d0"
600                                 fi
601                         else
602                                 verbose git clone "$url" "$d0/$d"
603                                 enter "$d0/$d" verbose
604                                 fix_git_config "$url" "$pushurl"
605                                 if [ "$branch" != "master" ]; then
606                                         verbose git checkout --track -b "$branch" origin/"$branch"
607                                 fi
608                                 cd "$d0"
609                         fi
610                 done
611                 ;;
612         update-maps)
613                 misc/tools/xonotic-map-compiler-autobuild download
614                 ;;
615         checkout|switch)
616                 checkoutflags=
617                 if [ x"$1" = x"-f" ]; then
618                         checkoutflags=-f
619                         shift
620                 fi
621                 remote=$1
622                 branch=$2
623                 if [ -z "$branch" ]; then
624                         case "$remote" in
625                                 origin/*)
626                                         branch=${remote#origin/}
627                                         remote=origin
628                                         ;;
629                                 *)
630                                         branch=$remote
631                                         remote=origin
632                                         ;;
633                         esac
634                 fi
635                 exists=false
636                 for d in $repos; do
637                         enter "$d0/$d" verbose
638                         b=$branch
639                         if [ -n "$b" ] && git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
640                                 exists=true
641                                 verbose git checkout $checkoutflags "$b"
642                         elif [ -n "$b" ] && git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
643                                 exists=true
644                                 verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
645                         else
646                                 b=`repobranch "$d"`
647                                 if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
648                                         exists=true
649                                         verbose git checkout $checkoutflags "$b"
650                                 elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
651                                         exists=true
652                                         verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
653                                 else
654                                         $ECHO "WTF? Not even branch $b doesn't exist in $d"
655                                         exit 1
656                                 fi
657                         fi
658                         cd "$d00"
659                         checkself "$cmd" "$@"
660                         cd "$d0"
661                 done
662                 if ! $exists; then
663                         $ECHO "The requested branch was not found in any repository."
664                 fi
665                 exec "$SELF" branch
666                 ;;
667         branch)
668                 remote=$1
669                 branch=$2
670                 srcbranch=$3
671                 if [ -z "$branch" ]; then
672                         branch=$remote
673                         remote=origin
674                 fi
675                 if [ -z "$branch" ]; then
676                         for d in $repos; do
677                                 enter "$d0/$d"
678                                 r=`git symbolic-ref HEAD`
679                                 r=${r#refs/heads/}
680                                 $ECHO "$d is at $r"
681                                 cd "$d0"
682                         done
683                 else
684                         for d in $repos; do
685                                 dv=`visible_repo_name "$d"`
686                                 enter "$d0/$d" verbose
687                                 if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
688                                         $ECHO "Already having this branch in $dv."
689                                 else
690                                         if yesno "Branch in $dv?"; then
691                                                 if [ -n "$srcbranch" ]; then
692                                                         b=$srcbranch
693                                                 else
694                                                         b=origin/"`repobranch "$d"`"
695                                                         verbose git fetch origin || true
696                                                 fi
697                                                 # TODO do this without pushing
698                                                 verbose git checkout -b "$branch" "$b"
699                                                 verbose git config "branch.$branch.remote" "$remote"
700                                                 verbose git config "branch.$branch.merge" "refs/heads/$branch"
701                                         fi
702                                 fi
703                                 cd "$d0"
704                         done
705                         "$SELF" branch
706                 fi
707                 ;;
708         branches)
709                 for d in $repos; do
710                         cd "$d0/$d" # am in a pipe, shouldn't use enter
711                         git branch -r -v -v | cut -c 3- | sed "s/^(no branch)/(no_branch)/" | sed "s,^,$d ,"
712                         cd "$d0"
713                 done | {
714                         branches_list=
715                         # branches_repos_*=
716                         while read -r d BRANCH REV TEXT; do
717                                 if [ x"$BRANCH" = x"`repobranch "$d"`" ]; then
718                                         continue
719                                 fi
720                                 if [ x"$REV" = x"->" ]; then
721                                         continue
722                                 fi
723                                 BRANCH=${BRANCH#remotes/}
724                                 ID=`$ECHO "$BRANCH" | tr -c "A-Za-z0-9." "_"`
725                                 branches_list="$branches_list $BRANCH" # TEH SORT MAKEZ IT UNIEQ
726                                 eval "r=\$branches_repos_$ID"
727                                 r="$r $d"
728                                 eval "branches_repos_$ID=\$r"
729                         done
730                         $ECHO -n "$branches_list" | xargs -n 1 $ECHO | sort -u | while IFS= read -r BRANCH; do
731                                 ID=`$ECHO "$BRANCH" | tr -c "A-Za-z0-9." "_"`
732                                 eval "r=\$branches_repos_$ID"
733                                 printf "%-60s %s\n" "$BRANCH" "$r"
734                                 #$ECHO "$BRANCH: $r"
735                         done
736                 }
737                 ;;
738         merge)
739                 for d in $repos; do
740                         dv=`visible_repo_name "$d"`
741                         enter "$d0/$d" verbose
742                         r=`git symbolic-ref HEAD`
743                         r=${r#refs/heads/}
744                         if git log HEAD..origin/"`repobranch "$d"`" | grep .; then
745                                 # we have uncommitted changes
746                                 if yesno "Could merge from \"`repobranch "$d"`\" into \"$r\" in $dv. Do it?"; then
747                                         if ! verbose git merge origin/"`repobranch "$d"`"; then
748                                                 check_mergeconflict "$d"
749                                                 exit 1 # this should ALWAYS be fatal
750                                         fi
751                                 fi
752                         fi
753                         cd "$d0"
754                 done
755                 ;;
756         push|commit)
757                 submit=$1
758                 for d in $repos; do
759                         dv=`visible_repo_name "$d"`
760                         enter "$d0/$d" verbose
761                         r=`git symbolic-ref HEAD`
762                         r=${r#refs/heads/}
763                         diffdata=`git diff --color HEAD`
764                         if [ -n "$diffdata" ]; then
765                                 # we have uncommitted changes
766                                 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?" '$ECHO "$diffdata" | less -r'; then
767                                         verbose git commit -a
768                                 fi
769                         fi
770                         rem=`git config "branch.$r.remote" || $ECHO origin`
771                         bra=`git config "branch.$r.merge" || $ECHO "$r"`
772                         upstream="$rem/${bra#refs/heads/}"
773                         if ! git rev-parse "$upstream" >/dev/null 2>&1; then
774                                 upstream="origin/`repobranch "$d"`"
775                         fi
776                         logdata=`git log --color "$upstream".."$r"`
777                         if [ -n "$logdata" ]; then
778                                 if yesno "Push \"$r\" in $dv?" '$ECHO "$logdata" | less -r'; then
779                                         verbose git push "$rem" HEAD
780                                 fi
781                         fi
782                         if [ x"$submit" = x"-s" ]; then
783                                 case "$r" in
784                                         */*)
785                                                 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
786                                                 ;;
787                                 esac
788                         fi
789                         cd "$d0"
790                 done
791                 ;;
792         compile)
793                 cleand0=false
794                 cleandp=false
795                 cleanqcc=false
796                 cleanqc=false
797                 compiled0=false
798                 debug=debug
799                 snowleopardhack=false
800                 if [ -z "$CC" ]; then
801                         export CC="gcc -DSUPPORTIPV6"
802                 fi
803                 while :; do
804                         case "$1" in
805                                 -0)
806                                         compiled0=true
807                                         shift
808                                         ;;
809                                 -c)
810                                         cleand0=true
811                                         cleandp=true
812                                         cleanqcc=true
813                                         cleanqc=true
814                                         shift
815                                         ;;
816                                 -r)
817                                         debug=release
818                                         export CC="$CC -g"
819                                         case "`$CC -dumpversion`" in
820                                                 [5-9]*|[1-9][0-9]*|4.[3-9]*|4.[1-9][0-9]*)
821                                                         # gcc 4.3 or higher
822                                                         # -march=native is broken < 4.3
823                                                         export CC="$CC -mtune=native -march=native"
824                                                         ;;
825                                         esac
826                                         if [ -n "$WE_HATE_OUR_USERS" ]; then
827                                                 export CC="$CC -fno-common"
828                                         fi
829                                         shift
830                                         ;;
831                                 *)
832                                         break
833                                         ;;
834                         esac
835                 done
836                 if [ -n "$WE_HATE_OUR_USERS" ]; then
837                         TARGETS="sv-$debug cl-$debug"
838                 elif [ x"`uname`" = x"Darwin" ]; then
839                         case "`uname -r`" in
840                                 ?.*)
841                                         TARGETS="sv-$debug cl-$debug sdl-$debug"
842                                         ;;
843                                 *)
844                                         # AGL cannot be compiled on systems with a kernel > 10.x (Snow Leopard)
845                                         snowleopardhack=true
846                                         TARGETS="sv-$debug sdl-$debug"
847                                         ;;
848                         esac
849                         export CC="$CC -fno-reorder-blocks -I$PWD/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks/SDL.framework/Headers -F$PWD/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks"
850                 else
851                         TARGETS="sv-$debug cl-$debug sdl-$debug"
852                 fi
853                 if [ $# -gt 0 ] && [ x"$1" = x"" ]; then
854                         # if we give the command make the arg "", it will surely fail (invalid filename),
855                         # so better handle it as an empty client option
856                         BAD_TARGETS=" "
857                         shift
858                 elif [ -n "$1" ]; then
859                         BAD_TARGETS=
860                         TARGETS_SAVE=$TARGETS
861                         TARGETS=
862                         for X in $1; do
863                                 case "$X" in
864                                         sdl)
865                                                 TARGETS="$TARGETS sdl-debug"
866                                                 ;;
867                                         agl)
868                                                 TARGETS="$TARGETS cl-debug"
869                                                 if $snowleopardhack; then
870                                                         export CC="$CC -arch i386"
871                                                 fi
872                                                 ;;
873                                         glx|wgl)
874                                                 TARGETS="$TARGETS cl-debug"
875                                                 ;;
876                                         dedicated)
877                                                 TARGETS="$TARGETS sv-debug"
878                                                 ;;
879                                         *)
880                                                 BAD_TARGETS="$BAD_TARGETS $X"
881                                                 ;;
882                                 esac
883                         done
884                         if [ -n "$TARGETS" ]; then # at least a valid client
885                                 shift
886                         else # no valid client, let's assume this option is not meant to be a client then
887                                 TARGETS=$TARGETS_SAVE
888                                 BAD_TARGETS=
889                         fi
890                 fi
891                 if [ -z "$MAKEFLAGS" ]; then
892                         if [ -f /proc/cpuinfo ]; then
893                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
894                                 if [ $ncpus -gt 1 ]; then
895                                         MAKEFLAGS=-j$ncpus
896                                 fi
897                         fi
898                         if [ -n "$WE_HATE_OUR_USERS" ]; then
899                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw LIB_JPEG= CFLAGS_LIBJPEG="
900                         fi
901                 fi
902
903                 enter "$d0/d0_blind_id" verbose
904                 if ! $compiled0; then
905                         # compilation of crypto library failed
906                         # use binaries then, if we can...
907                         mkdir -p .libs
908                         if [ -n "$WE_HATE_OUR_USERS" ]; then
909                                 verbose cp "$d0/misc/buildfiles/win32/libd0_blind_id"-* .libs/
910                                 verbose cp "$d0/misc/buildfiles/win32/libd0_rijndael"-* .libs/
911                                 verbose cp "$d0/misc/buildfiles/win32/libgmp"-* .libs/
912                         else
913                                 case "`uname`" in
914                                         Linux)
915                                                 case `uname -m` in
916                                                         x86_64)
917                                                                 #verbose cp "$d0/misc/builddeps/dp.linux64/lib/libd0_blind_id".* .libs/
918                                                                 #verbose cp "$d0/misc/builddeps/dp.linux64/lib/libd0_rijndael".* .libs/
919                                                                 #verbose cp "$d0/misc/builddeps/dp.linux64/lib/libgmp".* .libs/
920                                                                 MAKEFLAGS="$MAKEFLAGS DP_CRYPTO_STATIC_LIBDIR=../misc/builddeps/dp.linux64/lib/ DP_CRYPTO_RIJNDAEL_STATIC_LIBDIR=../misc/builddeps/dp.linux64/lib/"
921                                                                 ;;
922                                                         *86)
923                                                                 #verbose cp "$d0/misc/builddeps/dp.linux32/lib/libd0_blind_id".* .libs/
924                                                                 #verbose cp "$d0/misc/builddeps/dp.linux32/lib/libd0_rijndael".* .libs/
925                                                                 #verbose cp "$d0/misc/builddeps/dp.linux32/lib/libgmp".* .libs/
926                                                                 MAKEFLAGS="$MAKEFLAGS DP_CRYPTO_STATIC_LIBDIR=../misc/builddeps/dp.linux32/lib/ DP_CRYPTO_RIJNDAEL_STATIC_LIBDIR=../misc/builddeps/dp.linux32/lib/"
927                                                                 ;;
928                                                         *)
929                                                                 compiled0=true
930                                                                 ;;
931                                                 esac
932                                                 ;;
933                                         Darwin)
934                                                 verbose cp "$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS/libd0_blind_id".* .libs/
935                                                 verbose cp "$d0/misc/buildfiles/osx/Xonotic.app/Contents/MacOS/libd0_rijndael".* .libs/
936                                                 ;;
937                                         *)
938                                                 compiled0=true
939                                                 ;;
940                                 esac
941                         fi
942                 fi
943                 if $compiled0; then
944                         if $cleand0; then
945                                 if [ -f Makefile ]; then
946                                         verbose make $MAKEFLAGS distclean
947                                 fi
948                         fi
949                         if ! [ -f Makefile ]; then
950                                 verbose sh autogen.sh
951                                 verbose ./configure
952                         fi
953                         verbose make $MAKEFLAGS
954                 fi
955
956                 enter "$d0/fteqcc" verbose
957                 if $cleanqcc; then
958                         verbose make $MAKEFLAGS clean
959                 fi
960                 verbose make $MAKEFLAGS
961
962                 enter "$d0/data/xonotic-data.pk3dir" verbose
963                 if $cleanqc; then
964                         verbose make FTEQCC="../../../../fteqcc/fteqcc.bin" "$@" $MAKEFLAGS clean
965                 fi
966                 verbose make FTEQCC="../../../../fteqcc/fteqcc.bin" "$@" $MAKEFLAGS
967                 # 4 levels up: data, xonotic-data, qcsrc, server
968
969                 enter "$d0/darkplaces" verbose
970                 if [ x"$BAD_TARGETS" = x" " ]; then
971                         $ECHO "Warning: invalid empty client, default clients will be used."
972                 fi
973                 if $cleandp; then
974                         verbose make $MAKEFLAGS clean
975                 fi
976                 for T in $TARGETS; do
977                         verbose make $MAKEFLAGS STRIP=: "$@" "$T"
978                 done
979                 for T in $BAD_TARGETS; do
980                         $ECHO "Warning: discarded invalid client $T."
981                 done
982
983                 verbose "$SELF" update-maps
984                 ;;
985         run)
986                 if [ -n "$WE_HATE_OUR_USERS" ]; then
987                         client=
988                         export PATH="$d0/misc/buildfiles/win32:$d0/d0_blind_id/.libs:$PATH"
989                 elif [ x"`uname`" = x"Darwin" ]; then
990                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/MacOS:$d0/d0_blind_id/.libs"
991                         export DYLD_FRAMEWORK_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/Frameworks"
992                         client=-sdl
993                 else
994                         export LD_LIBRARY_PATH="$d0/d0_blind_id/.libs"
995                         client=-sdl
996                 fi
997                 case "$1" in
998                         sdl|glx|agl|dedicated)
999                                 client=-$1
1000                                 shift
1001                                 ;;
1002                         wgl)
1003                                 client=
1004                                 shift
1005                                 ;;
1006                 esac
1007                 if ! [ -x "darkplaces/darkplaces$client" ]; then
1008                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
1009                                 client=$client.exe
1010                         else
1011                                 $ECHO "Client darkplaces/darkplaces$client not found, aborting"
1012                                 exit 1
1013                         fi
1014                 fi
1015                 set -- "darkplaces/darkplaces$client" -xonotic -mygames "$@"
1016
1017                 # if pulseaudio is running: USE IT
1018                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
1019                         if ps -C pulseaudio >/dev/null; then
1020                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
1021                                         export SDL_AUDIODRIVER=pulse
1022                                 fi
1023                         fi
1024                 fi
1025
1026                 binary=$1
1027
1028                 if [ x"$USE_GDB" = x"yes" ]; then
1029                         set -- gdb --args "$@"
1030                 elif [ x"$USE_GDB" != x"no" ] && which gdb >/dev/null 2>&1; then
1031                         set -- gdb --batch -x savecore.gdb --args "$@"
1032                 elif which catchsegv >/dev/null 2>&1; then
1033                         set -- catchsegv "$@"
1034                 fi
1035                 rm -f xonotic.core
1036                 "$@" || true
1037                 if [ -f xonotic.core ]; then
1038                         if yesno "The program has CRASHED. Do you want to examine the core dump?"; then
1039                                 gdb "$binary" xonotic.core
1040                         #elif yesno "You did not want to examine the core dump. Do you want to provide it - including your DarkPlaces checkout - to the Xonotic developers?"; then
1041                         #       tar cvzf xonotic.core.tar.gz xonotic.core darkplaces/*.c darkplaces/*.h
1042                         #       # somehow send it
1043                         #       rm -f xonotic.core.tar.gz
1044                         else
1045                                 $ECHO "The core dump can be examined later by"
1046                                 $ECHO "  gdb $binary xonotic.core"
1047                         fi
1048                         exit 1
1049                 fi
1050                 ;;
1051         each|foreach)
1052                 keep_going=false
1053                 if [ x"$1" = x"-k" ]; then
1054                         keep_going=true
1055                         shift
1056                 fi
1057                 for d in $repos; do
1058                         if verbose cd "$d0/$d"; then
1059                                 if $keep_going; then
1060                                         verbose "$@" || true
1061                                 else
1062                                         verbose "$@"
1063                                 fi
1064                                 cd "$d0"
1065                         fi
1066                 done
1067                 ;;
1068         save-patches)
1069                 outfile=$1
1070                 patchdir=`mktemp -d -t save-patches.XXXXXX`
1071                 for d in $repos; do
1072                         enter "$d0/$d" verbose
1073                         git branch -v -v | cut -c 3- | {
1074                                 i=0
1075                                 while read -r BRANCH REV UPSTREAM TEXT; do
1076                                         case "$UPSTREAM" in
1077                                                 \[*)
1078                                                         UPSTREAM=${UPSTREAM#\[}
1079                                                         UPSTREAM=${UPSTREAM%\]}
1080                                                         UPSTREAM=${UPSTREAM%:*}
1081                                                         TRACK=true
1082                                                         ;;
1083                                                 *)
1084                                                         UPSTREAM=origin/"`repobranch "$d"`"
1085                                                         TRACK=false
1086                                                         ;;
1087                                         esac
1088                                         if [ x"$REV" = x"->" ]; then
1089                                                 continue
1090                                         fi
1091                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
1092                                                 $ECHO "$d" > "$patchdir/$i/info.txt"
1093                                                 $ECHO "$BRANCH" >> "$patchdir/$i/info.txt"
1094                                                 $ECHO "$UPSTREAM" >> "$patchdir/$i/info.txt"
1095                                                 $ECHO "$TRACK" >> "$patchdir/$i/info.txt"
1096                                                 i=$(($i+1))
1097                                         else
1098                                                 rm -rf "$patchdir/$i"
1099                                         fi
1100                                 done
1101                         }
1102                 done
1103                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
1104                 rm -rf "$patchdir"
1105                 ;;
1106         restore-patches)
1107                 infile=$1
1108                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
1109                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
1110                 # detach the head
1111                 for P in "$patchdir"/*/info.txt; do
1112                         D=${P%/info.txt}
1113                         exec 3<"$P"
1114                         read -r d <&3
1115                         read -r BRANCH <&3
1116                         read -r UPSTREAM <&3
1117                         read -r TRACK <&3
1118                         verbose git checkout HEAD^0
1119                         verbose git branch -D "$BRANCH"
1120                         if [ x"$TRACK" = x"true" ]; then
1121                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
1122                         else
1123                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
1124                         fi
1125                         verbose git am "$D"
1126                 done
1127                 rm -rf "$patchdir"
1128                 ;;
1129         admin-merge)
1130                 branch=$1
1131                 t=`mktemp`
1132                 report=""
1133                 reportecho()
1134                 {
1135                         report=$report"$*$LF"
1136                         $ECHO "$*"
1137                 }
1138                 reportecho4()
1139                 {
1140                         report=$report"    $*$LF"
1141                         $ECHO "    $*"
1142                 }
1143                 reportdo4()
1144                 {
1145                         o=`"$@" | sed 's/^/    /' || true`
1146                         reportecho "$o"
1147                 }
1148                 for d in $repos; do
1149                         case "$d" in
1150                                 fteqcc)
1151                                         # sorry, fteqcc repo is managed manually
1152                                         continue
1153                                         ;;
1154                         esac
1155                         enter "$d0/$d" verbose
1156                         base="`repobranch "$d"`"
1157                         reportecho "In $d:"
1158                         for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
1159                                 case "${ref#refs/remotes/origin/}" in
1160                                         "$base")
1161                                                 continue
1162                                                 ;;
1163                                         HEAD|master)
1164                                                 continue
1165                                                 ;;
1166                                         */*)
1167                                                 ;;
1168                                         *)
1169                                                 continue
1170                                                 ;;
1171                                 esac
1172                                 if [ -n "$branch" ]; then
1173                                         if [ x"$branch" != x"${ref#refs/remotes/origin/}" ]; then
1174                                                 continue
1175                                         fi
1176                                 fi
1177                                 case "$base" in
1178                                         master)
1179                                                 realbase=$base
1180                                                 ;;
1181                                         *)
1182                                                 l0=`git rev-list "$base".."$ref" | wc -l`
1183                                                 l1=`git rev-list master.."$ref" | wc -l`
1184                                                 if [ $l0 -gt $l1 ]; then
1185                                                         realbase=master
1186                                                 else
1187                                                         realbase=$base
1188                                                 fi
1189                                                 ;;
1190                                 esac
1191                                 reportecho "  Branch $ref:"
1192                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
1193                                 logdata=`git log --color "$realbase".."$ref"`
1194                                 if [ -z "$logdata" ]; then
1195                                         reportecho4 "--> not merging, no changes vs master"
1196                                         if yesno "Branch \"$ref\" probably should get deleted. Do it?" ''; then
1197                                                 git push origin :"${ref#refs/remotes/origin/}"
1198                                                 reportecho4 "--> branch deleted"
1199                                         fi
1200                                 else
1201                                         diffdata=`git diff --color --find-copies-harder --ignore-space-change "$realbase"..."$ref"`
1202                                         if [ -z "$diffdata" ]; then
1203                                                 reportecho4 "--> not merging, no changes vs master, branch contains redundant history"
1204                                                 if yesno "Branch \"$ref\" probably should get deleted. Do it?" '{ $ECHO "$logdata"; } | less -r'; then
1205                                                         git push origin :"${ref#refs/remotes/origin/}"
1206                                                         reportecho4 "--> branch deleted"
1207                                                 fi
1208                                         elif [ -z "$branch" ] && [ -n "$note" ]; then
1209                                                 reportdo4 $ECHO "$note"
1210                                                 reportecho4 "--> not merging, already had this one rejected before"
1211                                         elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ $ECHO "$logdata"; $ECHO "$diffdata"; } | less -r'; then
1212                                                 git checkout "$realbase"
1213                                                 org=`git rev-parse HEAD`
1214                                                 if ! git merge --no-ff "$ref" 2>&1 | tee "$t" && ! { git ls-files -u | grep ' 1 ' >/dev/null; }; then
1215                                                         git reset --hard "$org"
1216                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Merge failed:$LF`cat "$t"`" "$ref"
1217                                                         reportdo4 cat "$t"
1218                                                         reportecho4 "--> merge failed"
1219                                                 elif ! "$SELF" compile 2>&1 | tee "$t"; then
1220                                                         git reset --hard "$org"
1221                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Compile failed:$LF`cat "$t"`" "$ref"
1222                                                         reportdo4 cat "$t"
1223                                                         reportecho4 "--> compile failed"
1224                                                 elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
1225                                                         git reset --hard "$org"
1226                                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
1227                                                         note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
1228                                                         if [ x"$note" = x"del" ]; then
1229                                                                 git push origin :"${ref#refs/remotes/origin/}"
1230                                                                 reportecho4 "--> test failed, branch deleted"
1231                                                         elif [ -n "$note" ]; then
1232                                                                 reportdo4 $ECHO "$note"
1233                                                                 reportecho4 "--> test failed"
1234                                                         else
1235                                                                 reportecho4 "--> test failed, postponed"
1236                                                         fi
1237                                                 else
1238                                                         # apply crlf, or other cleanup filters (non-behavioural changes)
1239                                                         git reset --hard
1240                                                         find . -type f -exec touch {} \;
1241                                                         git commit -a --amend -C HEAD || true # don't fail if nothing to commit
1242
1243                                                         $ECHO "MERGING"
1244                                                         case ",`repoflags "$d"`," in
1245                                                                 *,svn,*)
1246                                                                         # we do quite a mess here... luckily we know $org
1247                                                                         git fetch # svn needs to be current
1248                                                                         git rebase -i --onto origin/master "$org"
1249                                                                         git svn dcommit --add-author-from
1250                                                                         git reset --hard "$org"
1251                                                                         ;;
1252                                                                 *)
1253                                                                         git push origin HEAD
1254                                                                         ;;
1255                                                         esac
1256                                                         reportecho4 "--> MERGED"
1257                                                         if yesno "Delete original branch \"$ref\"?"; then
1258                                                                 git push origin :"${ref#refs/remotes/origin/}"
1259                                                                 reportecho4 "--> branch deleted"
1260                                                         fi
1261                                                 fi
1262                                         else
1263                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
1264                                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
1265                                                 if [ x"$note" = x"del" ]; then
1266                                                         git push origin :"${ref#refs/remotes/origin/}"
1267                                                         reportecho4 "--> branch deleted"
1268                                                 elif [ -n "$note" ]; then
1269                                                         reportdo4 $ECHO "$note"
1270                                                         reportecho4 "--> rejected"
1271                                                 else
1272                                                         reportecho4 "--> postponed"
1273                                                 fi
1274                                         fi
1275                                 fi
1276                                 reportecho ""
1277                         done
1278                         reportecho ""
1279                 done
1280                 rm -f "$t"
1281                 $ECHO "$report" | ssh nexuiz@rm.endoftheinternet.org cat '>>' public_html/xonotic-merge-notes.txt
1282                 ;;
1283         clean)
1284                 "$SELF" fix_config
1285                 "$SELF" update -N
1286                 force=false
1287                 gotoupstream=false
1288                 fetchupstream=false
1289                 gotomaster=false
1290                 rmuntracked=false
1291                 killbranches=false
1292                 # usage:
1293                 #   ./all clean [-m] [-f | -fu | -fU] [-r] [-D]
1294                 #   ./all clean --reclone
1295                 found=false
1296                 for X in "$@"; do
1297                         if [ x"$X" = x"--reclone" ]; then
1298                                 force=true
1299                                 fetchupstream=true
1300                                 gotoupstream=true
1301                                 gotomaster=true
1302                                 rmuntracked=true
1303                                 killbranches=true
1304                         elif [ x"$X" = x"-f" ]; then
1305                                 force=true
1306                         elif [ x"$X" = x"-u" ]; then
1307                                 gotoupstream=true
1308                         elif [ x"$X" = x"-U" ]; then
1309                                 gotoupstream=true
1310                                 fetchupstream=true
1311                         elif [ x"$X" = x"-fu" ]; then
1312                                 force=true
1313                                 gotoupstream=true
1314                         elif [ x"$X" = x"-fU" ]; then
1315                                 force=true
1316                                 gotoupstream=true
1317                                 fetchupstream=true
1318                         elif [ x"$X" = x"-m" ]; then
1319                                 gotomaster=true
1320                         elif [ x"$X" = x"-r" ]; then
1321                                 rmuntracked=true
1322                         elif [ x"$X" = x"-D" ]; then
1323                                 killbranches=true
1324                         elif $ECHO "$X" | grep '^-FFFF*UUUU*$' >/dev/null; then
1325                                 msg ''
1326                                 msg "        _____"
1327                                 msg "    ,--'-\\P/\`\\  FFFFFFF"
1328                                 msg " __/_    B/,-.\\  FFFFFFF"
1329                                 msg " /  _\\  (//  O\\\\  FFFFFF"
1330                                 msg "| (O  \`) _\\._ _)\\  FFFUU"
1331                                 msg "| |___/.^d0~~\"\\  \\ UUUU"
1332                                 msg "|     |\`~'     \\ |  UUUU"
1333                                 msg "|     |    __,C>|| UUUU"
1334                                 msg "\\    /_ ,-/,-'   |  UUUU"
1335                                 msg " \\\\_ \\_>~'      /  UUUU-"
1336                                 msg ''
1337                         else
1338                                 msg "Unknown arg: $X"
1339                         fi
1340                         found=true
1341                         shift
1342                 done
1343                 if ! $found; then
1344                         rmuntracked=true
1345                 fi
1346                 for d in $repos; do
1347                         verbose cd "$d0/$d"
1348                         if $gotoupstream; then
1349                                 if ! $force; then
1350                                         msg "Must also use -f (delete local changes) when using -u"
1351                                         exit 1
1352                                 fi
1353                                 if $gotomaster; then
1354                                         if $fetchupstream; then
1355                                                 verbose git fetch origin
1356                                                 verbose git remote prune origin
1357                                         fi
1358                                         verbose git checkout -f "`repobranch "$d"`"
1359                                         verbose git reset --hard origin/"`repobranch "$d"`"
1360                                 else
1361                                         r=`git symbolic-ref HEAD`
1362                                         r=${r#refs/heads/}
1363                                         rem=`git config "branch.$r.remote" || $ECHO origin`
1364                                         bra=`git config "branch.$r.merge" || $ECHO "$r"`
1365                                         upstream="$rem/${bra#refs/heads/}"
1366                                         if $fetchupstream; then
1367                                                 verbose git fetch "$rem"
1368                                                 verbose git remote prune "$rem"
1369                                         fi
1370                                         if ! git rev-parse "$upstream" >/dev/null 2>&1; then
1371                                                 upstream="origin/`repobranch "$d"`"
1372                                         fi
1373                                         verbose git reset --hard "$upstream"
1374                                 fi
1375                         elif $gotomaster; then
1376                                 if $force; then
1377                                         verbose git checkout -f "`repobranch "$d"`"
1378                                         verbose git reset --hard
1379                                 else
1380                                         verbose git checkout "`repobranch "$d"`"
1381                                 fi
1382                         elif $force; then
1383                                 verbose git reset --hard
1384                         fi
1385                         if $rmuntracked; then
1386                                 case "$d" in
1387                                         .)
1388                                                 verbose git clean -df || true
1389                                                 ;;
1390                                         *)
1391                                                 verbose git clean -xdf || true
1392                                                 ;;
1393                                 esac
1394                         fi
1395                         if $killbranches; then
1396                                 git for-each-ref --format='%(refname)' refs/heads/ | while IFS= read -r B; do
1397                                         if [ x"$B" != x"`git symbolic-ref HEAD`" ]; then
1398                                                 verbose git branch -D "${B#refs/heads/}"
1399                                         fi
1400                                 done
1401                                 git rev-parse refs/heads/master >/dev/null 2>&1 || verbose git branch --track master origin/master || true
1402                                 git rev-parse "refs/heads/`repobranch "$d"`" >/dev/null 2>&1 || verbose git branch --track "`repobranch "$d"`" origin/"`repobranch "$d"`" || true
1403                         fi
1404                         checkself "$cmd" "$@"
1405                 done
1406                 ;;
1407
1408         # release building goes here
1409         release-prepare)
1410                 #"$SELF" each git clean -fxd
1411                 case "$RELEASETYPE" in
1412                         beta)
1413                                 msg "Building a BETA"
1414                                 ;;
1415                         release)
1416                                 msg "Building a RELEASE"
1417                                 ;;
1418                         *)
1419                                 $ECHO >&2 -n "$ESC[2J$ESC[H"
1420                                 msg ""
1421                                 msg ""
1422                                 msg ""
1423                                 msg ""
1424                                 msg ""
1425                                 msg ""
1426                                 msg "        +---------------------------------------------------------.---+"
1427                                 msg "        | NOTE                                                    | X |"
1428                                 msg "        +---------------------------------------------------------^---+"
1429                                 msg "        |   ____                                                      |"
1430                                 msg "        |  /    \  This is the official release build system.         |"
1431                                 msg "        | |      | If you are not a member of the Xonotic Core Team,  |"
1432                                 msg "        | | STOP | you are not supposed to use this script and should |"
1433                                 msg "        | |      | instead use ./all compile to compile the engine    |"
1434                                 msg "        |  \____/  and game code.                                     |"
1435                                 msg "        |                                                             |"
1436                                 msg "        |                      [ I understand ]                       |"
1437                                 msg "        +-------------------------------------------------------------+"
1438                                 sleep 10
1439                                 # A LOT of build infrastructure is required:
1440                                 # - vorbis-tools
1441                                 # - ImageMagick
1442                                 # - .ssh/config must be configured so the following
1443                                 #   host names are reachable and have a compile
1444                                 #   infrastructure set up:
1445                                 #   - xonotic-build-linux32 (with gcc on x86)
1446                                 #   - xonotic-build-linux64 (with gcc on x86_64)
1447                                 #   - xonotic-build-win32 (with i586-mingw32msvc-g++)
1448                                 #   - xonotic-build-win64 (with amd64-mingw32msvc-g++
1449                                 #     and x86_64-w64-mingw32-g++)
1450                                 #   - xonotic-build-osx (with Xcode and SDL.framework)
1451                                 # - AMD Compressonator installed in WINE
1452                                 # - ResEdit installed in WINE
1453                                 # - a lot of other requirements you will figure out
1454                                 #   while reading the error messages
1455                                 # - environment variable RELEASETYPE set
1456                                 # - optionally, environment variable RELEASEDATE set
1457                                 #   (YYYYMMDD)
1458                                 exit 1
1459                                 ;;
1460                 esac
1461                 verbose rm -rf Xonotic Xonotic*.zip
1462                 verbose mkdir -p Xonotic
1463                 if [ -n "$RELEASEDATE" ]; then
1464                         verbose $ECHO "$RELEASEDATE" > Xonotic/stamp.txt
1465                 else
1466                         verbose date +%Y%m%d > Xonotic/stamp.txt
1467                 fi
1468                 verbose git archive --format=tar HEAD -- Docs misc server xonotic-linux-glx.sh xonotic-linux-sdl.sh misc/buildfiles key_0.d0pk | {
1469                         verbose cd Xonotic
1470                         verbose mkdir data fteqcc source source/darkplaces source/fteqcc
1471                         verbose tar xvf -
1472                         verbose rm -rf misc/builddeps
1473                         verbose mv misc/buildfiles/win32/* . || true
1474                         verbose mv misc/buildfiles/win64 bin64 || true
1475                         verbose mv misc/buildfiles/osx/* . || true
1476                         verbose rm -rf misc/buildfiles
1477                         verbose rm -rf misc/pki
1478                 }
1479                 {
1480                         verbose cd darkplaces
1481                         verbose git archive --format=tar HEAD
1482                 } | {
1483                         verbose cd Xonotic/source/darkplaces
1484                         verbose tar xvf -
1485                 }
1486                 {
1487                         verbose cd fteqcc
1488                         verbose git archive --format=tar HEAD
1489                 } | {
1490                         verbose cd Xonotic/source/fteqcc
1491                         verbose tar xvf -
1492                 }
1493                 {
1494                         verbose cd data/xonotic-data.pk3dir
1495                         verbose git archive --format=tar HEAD -- qcsrc Makefile
1496                 } | {
1497                         verbose cd Xonotic/source
1498                         verbose tar xvf -
1499                 }
1500                 rm -f Xonotic/key_15.d0pk
1501                 ;;
1502         release-compile-run)
1503                 host=$1
1504                 buildpath=$2
1505                 maketargets=$3
1506                 makeflags=$4
1507                 srcdir=$5
1508                 depsdir=$6
1509                 targetfiles=$7
1510                 set -x
1511                 if [ -n "$targetfiles" ]; then
1512                         case " $HOSTS_THAT_ARE_DISABLED " in
1513                                 *\ $host\ *)
1514                                         exit
1515                                         ;;
1516                         esac
1517                         case " $HOSTS_THAT_ARE_MYSELF " in
1518                                 *\ $host\ *)
1519                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$buildpath/"
1520                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$buildpath.deps/"
1521                                         verbose ln -snf "$buildpath.deps" "$buildpath/.deps"
1522                                         verbose eval make -C "$buildpath" clean $maketargets $makeflags
1523                                         for f in $targetfiles; do
1524                                                 verbose mv "$buildpath/${f%:*}" "${f##*:}" || true
1525                                         done
1526                                         ;;
1527                                 *)
1528                                         verbose rsync --delete -zLvaSHP "$srcdir"/ "$host:$buildpath/"
1529                                         verbose rsync --delete -zLvaSHP "$depsdir"/ "$host:$buildpath.deps/"
1530                                         verbose ssh "$host" "ln -snf $buildpath.deps $buildpath/.deps && cd $buildpath && nice -`nice` make clean $maketargets $makeflags"
1531                                         for f in $targetfiles; do
1532                                                 verbose rsync -zvaSHP "$host:$buildpath/${f%:*}" "${f##*:}" || true
1533                                         done
1534                                         ;;
1535                         esac
1536                         # now rebrand the binaries...
1537                         for f in $targetfiles; do
1538                                 #verbose "$d0/misc/tools/rebrand-darkplaces-engine.sh" "${XONOTIC_BRAND:-$d0/misc/tools/xonotic.brand}" "${f##*:}" || true
1539                                 case "${f##*:}" in
1540                                         xonotic*.exe)
1541                                                 verbose "$d0/misc/tools/change-icon-of-exe.sh" "$d0/misc/logos/icons_ico/xonotic.ico" "${f##*:}"
1542                                                 (
1543                                                         d=`mktemp -d -t rebrand.XXXXXX`
1544                                                         cd "$d"
1545                                                         $ECHO "-mygames" > darkplaces.opt
1546                                                         zip -9r darkplaces.zip darkplaces.opt
1547                                                         cat darkplaces.zip
1548                                                         cd "$d0"
1549                                                         rm -rf "$d"
1550                                                 ) >> "${f##*:}"
1551                                                 ;;
1552                                 esac
1553                         done
1554                 fi
1555                 ;;
1556         release-compile)
1557                 suffix=$1
1558                 makeflags=$2
1559                 fteqcc_maketargets=$3
1560                 fteqcc_files=$4
1561                 darkplaces_maketargets=$5
1562                 darkplaces_files=$6
1563                 host=xonotic-build-$suffix
1564                 verbose "$SELF" release-compile-run "$host" /tmp/fteqcc.build."$suffix" "$fteqcc_maketargets" "$makeflags" "Xonotic/source/fteqcc" "$d0/misc/builddeps/dp.$suffix" "$fteqcc_files"
1565                 verbose "$SELF" release-compile-run "$host" /tmp/Darkplaces.build."$suffix" "$darkplaces_maketargets" "$makeflags" "Xonotic/source/darkplaces" "$d0/misc/builddeps/dp.$suffix" "$darkplaces_files"
1566                 ;;
1567         release-engine-win32)
1568                 verbose "$SELF" release-compile win32 \
1569                         'STRIP=: DP_MAKE_TARGET=mingw CC="i586-mingw32msvc-gcc -march=i686 -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib -DUSE_WSPIAPI_H -DSUPPORTIPV6" WINDRES="i586-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN32RELEASE=1 D3D=0' \
1570                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc.exe' \
1571                         '' ''
1572                 verbose "$SELF" release-compile win32 \
1573                         'STRIP=: DP_MAKE_TARGET=mingw CC="i586-mingw32msvc-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib -DUSE_WSPIAPI_H -DSUPPORTIPV6" WINDRES="i586-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN32RELEASE=1 D3D=0' \
1574                         '' '' \
1575                         release 'darkplaces.exe:Xonotic/xonotic.exe darkplaces-sdl.exe:Xonotic/xonotic-sdl.exe darkplaces-dedicated.exe:Xonotic/xonotic-dedicated.exe'
1576                 ;;
1577         release-engine-win64)
1578                 verbose "$SELF" release-compile win64 \
1579                         'STRIP=: DP_MAKE_TARGET=mingw CC="amd64-mingw32msvc-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib -DSUPPORTIPV6" WINDRES="amd64-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN64RELEASE=1 D3D=0' \
1580                         win 'fteqcc.exe:Xonotic/fteqcc/fteqcc-x64.exe' \
1581                         'sv-release sdl-release' 'darkplaces-sdl.exe:Xonotic/xonotic-x64-sdl.exe darkplaces-dedicated.exe:Xonotic/xonotic-x64-dedicated.exe'
1582                 verbose "$SELF" release-compile win64 \
1583                         'STRIP=: DP_MAKE_TARGET=mingw CC="x86_64-w64-mingw32-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib -DSUPPORTIPV6" WINDRES="x86_64-w64-mingw32-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN64RELEASE=1 D3D=0' \
1584                         '' '' \
1585                         cl-release 'darkplaces.exe:Xonotic/xonotic-x64.exe'
1586                 ;;
1587         release-engine-osx)
1588                 # gcc on OSX is buggy, needs -fno-reorder-blocks for a release build to succeed
1589                 verbose "$SELF" release-compile osx \
1590                         '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 -DSUPPORTIPV6"' \
1591                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.osx' \
1592                         'sv-release sdl-release' 'darkplaces-sdl:Xonotic/Xonotic-SDL.app/Contents/MacOS/xonotic-osx-sdl-bin darkplaces-dedicated:Xonotic/xonotic-osx-dedicated'
1593                 verbose "$SELF" release-compile osx \
1594                         '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 -DSUPPORTIPV6"' \
1595                         '' '' \
1596                         'cl-release' 'darkplaces-agl:Xonotic/Xonotic.app/Contents/MacOS/xonotic-osx-agl-bin'
1597                 ;;
1598         release-engine-linux32)
1599                 verbose "$SELF" release-compile linux32 \
1600                         'STRIP=: CC="gcc -m32 -march=i686 -g -I.deps/include -L.deps/lib -DSUPPORTIPV6" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a DP_CRYPTO_STATIC_LIBDIR=.deps/lib' \
1601                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux32' \
1602                         release 'darkplaces-glx:Xonotic/xonotic-linux32-glx darkplaces-sdl:Xonotic/xonotic-linux32-sdl darkplaces-dedicated:Xonotic/xonotic-linux32-dedicated'
1603                 ;;
1604         release-engine-linux64)
1605                 verbose "$SELF" release-compile linux64 \
1606                         'STRIP=: CC="gcc -m64 -g -I.deps/include -L.deps/lib -DSUPPORTIPV6" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a DP_CRYPTO_STATIC_LIBDIR=.deps/lib' \
1607                         all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux64' \
1608                         release 'darkplaces-glx:Xonotic/xonotic-linux64-glx darkplaces-sdl:Xonotic/xonotic-linux64-sdl darkplaces-dedicated:Xonotic/xonotic-linux64-dedicated'
1609                 ;;
1610         release-engine)
1611                 verbose "$SELF" release-engine-linux32 &
1612                 verbose "$SELF" release-engine-linux64 &
1613                 verbose "$SELF" release-engine-win32 &
1614                 verbose "$SELF" release-engine-win64 &
1615                 verbose "$SELF" release-engine-osx &
1616                 wait %1
1617                 wait %2
1618                 wait %3
1619                 wait %4
1620                 wait %5
1621                 wait
1622                 ;;
1623         release-maps)
1624                 verbose "$SELF" update-maps
1625                 ;;
1626         release-qc)
1627                 case "$RELEASETYPE" in
1628                         beta)
1629                                 verbose make -C Xonotic/source FTEQCC="../../../fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 clean all
1630                                 # back out of: source/qcsrc/server
1631                                 ;;
1632                         release)
1633                                 verbose make -C Xonotic/source FTEQCC="../../../fteqcc/fteqcc.linux32" XON_BUILDSYSTEM=1 FTEQCCFLAGS_WATERMARK= clean all
1634                                 ;;
1635                 esac
1636                 verbose rm -f Xonotic/source/*/fteqcc.log
1637                 ;;
1638         release-buildpk3-transform-raw)
1639                 dir=$1
1640                 ;;
1641         release-buildpk3-transform-normal)
1642                 dir=$1
1643                 verbose cd "$dir"
1644                 # texture: convert to jpeg and dds
1645                 verbose export do_jpeg=true
1646                 verbose export jpeg_qual_rgb=95
1647                 verbose export jpeg_qual_a=99
1648                 verbose export do_dds=true
1649                 verbose export dds_flags=
1650                 verbose export do_ogg=false
1651                 verbose export del_src=true
1652                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1653                 ;;
1654         release-buildpk3-transform-low)
1655                 dir=$1
1656                 verbose cd "$dir"
1657                 # texture: convert to jpeg and dds
1658                 # music: reduce bitrate
1659                 verbose export do_jpeg=true
1660                 verbose export jpeg_qual_rgb=80
1661                 verbose export jpeg_qual_a=97
1662                 verbose export do_dds=false
1663                 verbose export do_ogg=true
1664                 verbose export ogg_qual=1
1665                 verbose export del_src=true
1666                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1667                 ;;
1668         release-buildpk3-transform-lowdds)
1669                 dir=$1
1670                 verbose cd "$dir"
1671                 # texture: convert to jpeg and dds
1672                 # music: reduce bitrate
1673                 verbose export do_jpeg=false
1674                 verbose export do_jpeg_if_not_dds=true
1675                 verbose export jpeg_qual_rgb=80
1676                 verbose export jpeg_qual_a=99
1677                 verbose export do_dds=true
1678                 verbose export dds_flags=
1679                 verbose export do_ogg=true
1680                 verbose export ogg_qual=1
1681                 verbose export del_src=true
1682                 find . -type f -print0 | verbose xargs -0 "$d0"/misc/tools/cached-converter.sh
1683                 ;;
1684         release-buildpk3)
1685                 src=$1
1686                 dst=$2
1687                 transform=$3
1688                 case "$dst" in
1689                         /*)
1690                                 ;;
1691                         */)
1692                                 dst="$PWD/$dst"
1693                                 ;;
1694                 esac
1695                 verbose rm -rf Xonotic/temp
1696                 verbose mkdir -p Xonotic/temp
1697                 {
1698                         verbose cd "$src"
1699                         verbose git archive --format=tar HEAD
1700                 } | {
1701                         verbose cd Xonotic/temp
1702                         verbose tar xvf -
1703                 }
1704                 verbose cd Xonotic/temp
1705                 if [ x"$src" = x"data/xonotic-data.pk3dir" ]; then
1706                         verbose cp ../source/progs.dat .
1707                         verbose cp ../source/csprogs.dat .
1708                         verbose cp ../source/menu.dat .
1709                         verbose rm -rf qcsrc
1710                         gv=`grep "^gameversion " "defaultXonotic.cfg" | awk '{ print $2 }'`
1711                         major=$(($gv / 10000))
1712                         minor=$(($gv / 100 - $major * 100))
1713                         patch=$(($gv - $major * 10000 - $minor * 100))
1714                         versionstr="$major.$minor.$patch"
1715                         case "$RELEASETYPE" in
1716                                 beta)
1717                                         versionstr="$versionstr""beta"
1718                                         ;;
1719                         esac
1720                         verbose sed -i "
1721                                 s/^set g_xonoticversion [^ ]* /set g_xonoticversion $versionstr /;
1722                                 s/^gameversion_min [0-9]*/gameversion_min $(( ($gv / 100) * 100 - 100 ))/;
1723                                 s/^gameversion_max [0-9]*/gameversion_max $(( ($gv / 100) * 100 + 199 ))/;
1724                         " defaultXonotic.cfg
1725                         (
1726                                 verbose cd gfx/menu/luminos
1727                                 verbose cp "$d0"/mediasource/gfx/menu/luminos_versionbuilder/background_l2.svg .
1728                                 verbose "$d0"/mediasource/gfx/menu/luminos_versionbuilder/versionbuilder "$versionstr"
1729                                 verbose rm background_l2.svg
1730                         )
1731                 fi
1732                 if [ x"$src" = x"data/xonotic-maps.pk3dir" ]; then
1733                         for X in ../../data/*-????????????????????????????????????????-????????????????????????????????????????.pk3; do
1734                                 if [ -f "$X" ]; then
1735                                         verbose unzip "$X"
1736                                         verbose rm -f maps/*.log maps/*.irc maps/*.lin
1737                                 fi
1738                         done
1739                 fi
1740                 verbose export git_src_repo="$d0/$src" # skip hash-object
1741                 verbose "$SELF" release-buildpk3-transform-$transform "Xonotic/temp"
1742                 verbose mkzip "../../$dst" *
1743                 verbose cd ../..
1744                 verbose rm -rf Xonotic/temp
1745                 ;;
1746         release-buildpk3s)
1747                 stamp=`cat Xonotic/stamp.txt`
1748                 src=$1
1749                 shift
1750                 dst=${src%.pk3dir}
1751                 case "$dst" in
1752                         data/xonotic-*)
1753                                 dst="data/xonotic-$stamp-${dst#data/xonotic-}"
1754                                 ;;
1755                         *)
1756                                 dst="$dst-$stamp"
1757                                 ;;
1758                 esac
1759                 while [ "$#" -gt 1 ]; do
1760                         verbose "$SELF" release-buildpk3 "$src" "Xonotic/$dst$2.pk3" "$1"
1761                         shift
1762                         shift
1763                 done
1764                 ;;
1765         release-pack)
1766                 verbose "$SELF" release-buildpk3s data/font-nimbussansl.pk3dir             raw ''
1767                 verbose "$SELF" release-buildpk3s data/xonotic-data.pk3dir       normal ''            low '-low' lowdds '-lowdds'
1768                 verbose "$SELF" release-buildpk3s data/xonotic-maps.pk3dir       normal ''            low '-low' lowdds '-lowdds'
1769                 verbose "$SELF" release-buildpk3s data/xonotic-music.pk3dir                raw ''     low '-low'
1770                 verbose "$SELF" release-buildpk3s data/xonotic-nexcompat.pk3dir                       low ''
1771                 ;;
1772         release-pack-needsx11)
1773                 case "$DISPLAY" in
1774                         '')
1775                                 verbose startx "$SELF" release-pack -- /usr/bin/Xvfb :7
1776                                 ;;
1777                         *)
1778                                 verbose "$SELF" release-pack
1779                                 ;;
1780                 esac
1781                 ;;
1782         release-zip)
1783                 stamp=`cat Xonotic/stamp.txt`
1784                 # exe and dll files do not need +x, so this makes them eligible for 7zip compression too
1785                 chmod a-x Xonotic/*.exe Xonotic/*.dll || true
1786                 # let's pass crypto import laws of some nasty countries
1787                 crypto_libs=`find Xonotic -name \*d0_rijndael\*`
1788                 if [ -n "$crypto_libs" ]; then
1789                         verbose mkzip Xonotic-$stamp-crypto.zip \
1790                                 $crypto_libs
1791                         rm -f $crypto_libs
1792                 fi
1793                 # build the archives
1794                 verbose mkzip Xonotic-$stamp-engine.zip \
1795                         Xonotic/*.dll \
1796                         Xonotic/bin64/*.dll \
1797                         Xonotic/*.app \
1798                         Xonotic/xonotic-* \
1799                         Xonotic/xonotic.exe \
1800                         Xonotic/source/darkplaces/
1801                 verbose cp Xonotic-$stamp-engine.zip Xonotic-$stamp-common.zip
1802                 verbose mkzip Xonotic-$stamp-common.zip \
1803                         Xonotic/source/fteqcc/ \
1804                         Xonotic/source/qcsrc/ \
1805                         Xonotic/Docs \
1806                         Xonotic/misc \
1807                         Xonotic/fteqcc \
1808                         Xonotic/server \
1809                         Xonotic/key_0.d0pk \
1810                         Xonotic/data/font-nimbussansl-$stamp.pk3
1811                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp.zip
1812                 verbose mkzip0 Xonotic-$stamp.zip \
1813                         Xonotic/data/xonotic-$stamp-data.pk3 \
1814                         Xonotic/data/xonotic-$stamp-maps.pk3 \
1815                         Xonotic/data/xonotic-$stamp-music.pk3 \
1816                         Xonotic/data/xonotic-$stamp-nexcompat.pk3
1817                 verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-low.zip
1818                 verbose mkzip0 Xonotic-$stamp-low.zip \
1819                         Xonotic/data/xonotic-$stamp-data-low.pk3 \
1820                         Xonotic/data/xonotic-$stamp-maps-low.pk3 \
1821                         Xonotic/data/xonotic-$stamp-music-low.pk3
1822 #               verbose cp Xonotic-$stamp-common.zip Xonotic-$stamp-high.zip
1823 #               verbose mkzip0 Xonotic-$stamp-high.zip \
1824 #                       Xonotic/data/xonotic-$stamp-data-raw.pk3 \
1825 #                       Xonotic/data/xonotic-$stamp-maps-raw.pk3 \
1826 #                       Xonotic/data/xonotic-$stamp-music.pk3 \
1827 #                       Xonotic/data/xonotic-$stamp-nexcompat.pk3
1828                 verbose mv Xonotic-$stamp-common.zip Xonotic-$stamp-lowdds.zip
1829                 verbose mkzip0 Xonotic-$stamp-lowdds.zip \
1830                         Xonotic/data/xonotic-$stamp-data-lowdds.pk3 \
1831                         Xonotic/data/xonotic-$stamp-maps-lowdds.pk3 \
1832                         Xonotic/data/xonotic-$stamp-music-low.pk3
1833                 ;;
1834         release)
1835                 verbose "$SELF" release-prepare
1836                 verbose "$SELF" release-maps
1837                 verbose "$SELF" release-engine
1838                 verbose "$SELF" release-qc
1839                 verbose "$SELF" release-pack-needsx11
1840                 verbose "$SELF" release-zip
1841                 ;;
1842
1843         *)
1844                 $ECHO "Usage:"
1845                 $ECHO "  $SELF admin-merge [<branch>]"
1846                 $ECHO "  $SELF branch <branch>"
1847                 $ECHO "  $SELF branch <remote> <branch> [<srcbranch>]"
1848                 $ECHO "  $SELF branches"
1849                 $ECHO "  $SELF checkout|switch <branch>"
1850                 $ECHO "  $SELF checkout|switch <remote>/<branch>"
1851                 $ECHO "  $SELF clean [-m] [-f | -fu | -fU] [-r] [-D]"
1852                 $ECHO "  $SELF clean --reclone"
1853                 $ECHO "  $SELF compile [-c] [-r] [-0]"
1854                 $ECHO "  $SELF each|foreach [-k] command..."
1855                 $ECHO "  $SELF fix_upstream_rebase"
1856                 $ECHO "  $SELF keygen"
1857                 $ECHO "  $SELF merge"
1858                 $ECHO "  $SELF push|commit [-s]"
1859                 $ECHO "  $SELF release"
1860                 $ECHO "  $SELF restore-patches"
1861                 $ECHO "  $SELF run [sdl|glx|wgl|agl|dedicated] options..."
1862                 $ECHO "  $SELF save-patches"
1863                 $ECHO "  $SELF update-maps"
1864                 $ECHO "  $SELF update|pull [-N] [-s | -h [-p] | -g [-p]] [-l de|nl|default]"
1865                 ;;
1866 esac