]> git.xonotic.org Git - xonotic/xonotic.git/blob - all
57d92453a1d1e89e0536081087b16d696a34bdef
[xonotic/xonotic.git] / all
1 #!/bin/sh
2
3 set -e
4
5 d00=`pwd`
6 while ! [ -f ./all ]; do
7         if [ x"`pwd`" = x"/" ]; then
8                 echo "Cannot find myself."
9                 echo "Please run this script with the working directory inside a Xonotic checkout."
10                 exit 1
11         fi
12         cd ..
13 done
14 d0=`pwd`
15 SELF="$d0/all"
16
17 # If we are on WINDOWS:
18 case "$0" in
19         all|*/all)
20                 case "`uname`" in
21                         MINGW*|Win*)
22                                 # Windows hates users. So this script has to copy itself elsewhere first...
23                                 tname=
24                                 cp "$SELF" ../all.xonotic.sh
25                                 exec ../all.xonotic.sh "$@"
26                                 ;;
27                 esac
28                 ;;
29 esac
30
31 msg()
32 {
33         echo "\e[1m$*\e[m"
34 }
35
36 checksum()
37 {
38         if [ -x /usr/bin/md5sum ]; then
39                 /usr/bin/md5sum "$@"
40         elif [ -x /bin/md5sum ]; then
41                 /bin/md5sum "$@"
42         elif [ -x /usr/bin/cksum ]; then
43                 /usr/bin/cksum "$@"
44         else
45                 echo "NOCHECKSUM"
46         fi
47 }
48
49 self=`checksum "$SELF"`
50 checkself()
51 {
52         self_new=`checksum "$SELF"`
53         if [ x"$self" != x"$self_new" ]; then
54                 msg "./all has changed."
55                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
56                         msg "Rerunning the requested operation to make sure."
57                         export XONOTIC_FORBID_RERUN_ALL=1
58                         exec "$SELF" "$@"
59                 else
60                         msg "Please try $SELF update, and then retry your requested operation."
61                         exit 1
62                 fi
63         fi
64         return 0
65 }
66
67 verbose()
68 {
69         msg "+ $*"
70         "$@"
71 }
72
73 visible_repo_name()
74 {
75         case "$1" in
76                 .)
77                         echo "the root directory"
78                         ;;
79                 *)
80                         echo "\"$1\""
81                         ;;
82         esac
83 }
84
85 check_mergeconflict()
86 {
87         if git ls-files -u | grep ' 1   '; then
88                 echo
89                 echo "MERGE CONFLICT."
90                 echo "change into the \"$1\" project directory, and then:"
91                 echo "- edit the files mentioned above with your favorite editor,"
92                 echo "  and fix the conflicts (marked with <<<<<<< blocks)"
93                 echo "- for binary files, you can select the files using"
94                 echo "  git checkout --ours or git checkout --theirs"
95                 echo "- when done with a file, 'git add' the file"
96                 echo "- when done, 'git commit'"
97                 echo
98                 exit 1
99         fi
100 }
101
102 enter()
103 {
104         $2 cd "$1"
105         check_mergeconflict "$1"
106 }
107
108 repos_urls="
109         .
110         data/xonotic-data.pk3dir
111         data/xonotic-maps.pk3dir
112         data/xonotic-music.pk3dir
113         data/xonotic-nexcompat.pk3dir
114         darkplaces
115         fteqcc@git://github.com/Blub/qclib.git
116         div0-gittools@git://git.icculus.org/divverent/div0-gittools.git
117         netradiant
118 "
119
120 repos=`for X in $repos_urls; do echo "${X%%@*}"; done`
121
122 if [ "$#" = 0 ]; then
123         set -- help
124 fi
125 cmd=$1
126 shift
127
128 case "$cmd" in
129         update|pull)
130                 base=`git config remote.origin.url`
131                 base=${base%xonotic.git}
132                 for dcomplete in $repos_urls; do
133                         case "$dcomplete" in
134                                 *@*)
135                                         d=${dcomplete%%@*}
136                                         url=${dcomplete#*@}
137                                         switch=false
138                                         ;;
139                                 *)
140                                         d=${dcomplete%%@*}
141                                         url=$base${d##*/}.git
142                                         switch=true
143                                         ;;
144                         esac
145                         if [ -d "$d0/$d" ]; then
146                                 enter "$d0/$d" verbose
147                                 case "$d" in
148                                         .)
149                                                 ;;
150                                         *)
151                                                 if $switch; then
152                                                         verbose git config remote.origin.url "$url"
153                                                 fi
154                                                 ;;
155                                 esac
156                                 verbose git config remote.origin.fetch "refs/heads/*:refs/remotes/origin/*"
157
158                                 r=`git symbolic-ref HEAD`
159                                 r=${r#refs/heads/}
160                                 if git config branch.$r.remote >/dev/null 2>&1; then
161                                         if ! verbose git pull; then
162                                                 check_mergeconflict "$d"
163                                                 exit 1 # FATAL
164                                         fi
165                                 fi
166
167                                 cd "$d00"
168                                 checkself "$cmd" "$@"
169                                 cd "$d0/$d"
170                                 verbose git remote prune origin
171                                 cd "$d0"
172                         else
173                                 verbose git clone "$url" "$d0/$d"
174                         fi
175                 done
176                 ;;
177         checkout|switch)
178                 remote=$1
179                 branch=$2
180                 if [ -z "$branch" ]; then
181                         branch=$remote
182                         remote=origin
183                 fi
184                 exists=false
185                 for d in $repos; do
186                         enter "$d0/$d" verbose
187                         if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
188                                 exists=true
189                                 verbose git checkout "$branch"
190                         elif git rev-parse "refs/remotes/$remote/$branch" >/dev/null 2>&1; then
191                                 exists=true
192                                 verbose git checkout --track -b "$branch" "$remote/$branch"
193                         else
194                                 verbose git checkout master
195                         fi
196                         cd "$d00"
197                         checkself "$cmd" "$@"
198                         cd "$d0"
199                 done
200                 if ! $exists; then
201                         echo "The requested branch was not found in any repository."
202                 fi
203                 exec "$SELF" branch
204                 ;;
205         branch)
206                 remote=$1
207                 branch=$2
208                 srcbranch=$3
209                 if [ -z "$branch" ]; then
210                         branch=$remote
211                         remote=origin
212                 fi
213                 if [ -z "$srcbranch" ]; then
214                         srcbranch=master
215                 fi
216                 if [ -z "$branch" ]; then
217                         for d in $repos; do
218                                 enter "$d0/$d"
219                                 r=`git symbolic-ref HEAD`
220                                 r=${r#refs/heads/}
221                                 echo "$d is at $r"
222                                 cd "$d0"
223                         done
224                 else
225                         for d in $repos; do
226                                 dv=`visible_repo_name "$d"`
227                                 enter "$d0/$d" verbose
228                                 a=
229                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
230                                         echo "Branch in $dv?"
231                                         read -r a
232                                 done
233                                 if [ x"$a" = x"y" ]; then
234                                         verbose git push "$remote" "$srcbranch":"$branch"
235                                         verbose git checkout --track -b "$branch" "$remote/$branch"
236                                 fi
237                                 cd "$d0"
238                         done
239                         "$SELF" branch
240                 fi
241                 ;;
242         branches)
243                 for d in $repos; do
244                         enter "$d0/$d"
245                         echo "In $d:"
246                         git branch -a -v -v | cut -c 3- | while read -r BRANCH REV UPSTREAM TEXT; do
247                                 case "$UPSTREAM" in
248                                         \[*)
249                                                 UPSTREAM=${UPSTREAM#\[}
250                                                 UPSTREAM=${UPSTREAM%\]}
251                                                 UPSTREAM=${UPSTREAM%:*}
252                                                 ;;
253                                         *)
254                                                 TEXT="$UPSTREAM $TEXT"
255                                                 UPSTREAM=
256                                                 ;;
257                                 esac
258                                 if [ x"$REV" = x"->" ]; then
259                                         continue
260                                 fi
261                                 BRANCH=${BRANCH#remotes/}
262                                 echo -n "  $BRANCH"
263                                 if [ -n "$UPSTREAM" ]; then
264                                         echo -n " (tracking $UPSTREAM)"
265                                 fi
266                                 #echo " $TEXT"
267                                 echo
268                         done
269                 done
270                 ;;
271         merge)
272                 for d in $repos; do
273                         dv=`visible_repo_name "$d"`
274                         enter "$d0/$d" verbose
275                         r=`git symbolic-ref HEAD`
276                         r=${r#refs/heads/}
277                         if git log HEAD..origin/master | grep .; then
278                                 # we have uncommitted changes
279                                 a=
280                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
281                                         echo "Could merge from \"master\" into \"$r\" in $dv. Do it?"
282                                         read -r a
283                                 done
284                                 if [ x"$a" = x"y" ]; then
285                                         if ! verbose git merge origin/master; then
286                                                 check_mergeconflict "$d"
287                                                 exit 1 # this should ALWAYS be fatal
288                                         fi
289                                 fi
290                         fi
291                         cd "$d0"
292                 done
293                 ;;
294         push|commit)
295                 for d in $repos; do
296                         dv=`visible_repo_name "$d"`
297                         enter "$d0/$d" verbose
298                         r=`git symbolic-ref HEAD`
299                         r=${r#refs/heads/}
300                         if git diff HEAD | grep .; then
301                                 # we have uncommitted changes
302                                 a=
303                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
304                                         echo "Uncommitted changes in \"$r\" in $dv. Commit?"
305                                         read -r a
306                                 done
307                                 if [ x"$a" = x"y" ]; then
308                                         verbose git commit -a
309                                 fi
310                         fi
311                         if git log "origin/$r".."$r" | grep .; then
312                                 a=
313                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
314                                         echo "Push \"$r\" in $dv?"
315                                         read -r a
316                                 done
317                                 if [ x"$a" = x"y" ]; then
318                                         verbose git push `git config "branch.$r.remote" || echo origin` HEAD
319                                 fi
320                         fi
321                         cd "$d0"
322                 done
323                 ;;
324         compile)
325                 if [ -z "$MAKEFLAGS" ]; then
326                         if [ -f /proc/cpuinfo ]; then
327                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
328                                 if [ $ncpus -gt 1 ]; then
329                                         MAKEFLAGS=-j$ncpus
330                                 fi
331                         fi
332                 fi
333                 enter "$d0/fteqcc" verbose
334                 verbose make $MAKEFLAGS
335                 enter "$d0/data/xonotic-data.pk3dir" verbose
336                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" $MAKEFLAGS
337                 enter "$d0/darkplaces" verbose
338                 verbose make $MAKEFLAGS sv-debug
339                 verbose make $MAKEFLAGS cl-debug
340                 verbose make $MAKEFLAGS sdl-debug
341                 ;;
342         run)
343                 client=-sdl
344                 case "$1" in
345                         sdl|glx|agl|dedicated)
346                                 client=-$1
347                                 shift
348                                 ;;
349                         wgl)
350                                 client=
351                                 shift
352                                 ;;
353                 esac
354                 if ! [ -x "darkplaces/darkplaces$client" ]; then
355                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
356                                 client=$client.exe
357                         else
358                                 echo "Client darkplaces/darkplaces$client not found, aborting"
359                                 exit 1
360                         fi
361                 fi
362                 #verbose "darkplaces/darkplaces$client" -xonotic "$@"
363                 verbose "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
364                 ;;
365         each|foreach)
366                 for d in $repos; do
367                         enter "$d0/$d" verbose
368                         verbose "$@"
369                         cd "$d0"
370                 done
371                 ;;
372         save-patches)
373                 outfile=$1
374                 patchdir=`mktemp -d -t save-patches.XXXXXX`
375                 for d in $repos; do
376                         enter "$d0/$d" verbose
377                         git branch -v -v | cut -c 3- | {
378                                 i=0
379                                 while read -r BRANCH REV UPSTREAM TEXT; do
380                                         case "$UPSTREAM" in
381                                                 \[*)
382                                                         UPSTREAM=${UPSTREAM#\[}
383                                                         UPSTREAM=${UPSTREAM%\]}
384                                                         UPSTREAM=${UPSTREAM%:*}
385                                                         TRACK=true
386                                                         ;;
387                                                 *)
388                                                         UPSTREAM=origin/master
389                                                         TRACK=false
390                                                         ;;
391                                         esac
392                                         if [ x"$REV" = x"->" ]; then
393                                                 continue
394                                         fi
395                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
396                                                 echo "$d" > "$patchdir/$i/info.txt"
397                                                 echo "$BRANCH" >> "$patchdir/$i/info.txt"
398                                                 echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
399                                                 echo "$TRACK" >> "$patchdir/$i/info.txt"
400                                                 i=$(($i+1))
401                                         else
402                                                 rm -rf "$patchdir/$i"
403                                         fi
404                                 done
405                         }
406                 done
407                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
408                 rm -rf "$patchdir"
409                 ;;
410         restore-patches)
411                 infile=$1
412                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
413                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
414                 # detach the head
415                 for P in "$patchdir"/*/info.txt; do
416                         D=${P%/info.txt}
417                         exec 3<"$P"
418                         read -r d <&3
419                         read -r BRANCH <&3
420                         read -r UPSTREAM <&3
421                         read -r TRACK <&3
422                         verbose git checkout HEAD^0
423                         verbose git branch -D "$BRANCH"
424                         if [ x"$TRACK" = x"true" ]; then
425                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
426                         else
427                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
428                         fi
429                         verbose git am "$D"
430                 done
431                 rm -rf "$patchdir"
432                 ;;
433         *)
434                 echo "Usage:"
435                 echo "  $SELF pull"
436                 echo "  $SELF merge"
437                 echo "  $SELF push"
438                 echo "  $SELF branches"
439                 echo "  $SELF branch [<remote>] <branchname>"
440                 echo "  $SELF branch <remote> <branchname> <srcbranchname>"
441                 echo "  $SELF checkout [<remote>] <branchname>"
442                 echo "  $SELF compile"
443                 echo "  $SELF run <client> <options>"
444                 echo "  $SELF each <command>"
445                 ;;
446 esac