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