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