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