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