]> git.xonotic.org Git - xonotic/xonotic.git/blob - all
c94d71b36be26690535cbbf9a8626a25694da14b
[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*)
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         verbose 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"
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                                 if ! verbose git pull; then
157                                         check_mergeconflict "$d"
158                                         # do not exit, as this may also mean we are tracking something else
159                                 fi
160                                 cd "$d00"
161                                 checkself "$cmd" "$@"
162                                 cd "$d0/$d"
163                                 verbose git remote prune origin
164                                 cd "$d0"
165                         else
166                                 verbose git clone "$url" "$d0/$d"
167                         fi
168                 done
169                 ;;
170         checkout|switch)
171                 remote=$1
172                 branch=$2
173                 if [ -z "$branch" ]; then
174                         branch=$remote
175                         remote=origin
176                 fi
177                 exists=false
178                 for d in $repos; do
179                         enter "$d0/$d"
180                         if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
181                                 exists=true
182                                 verbose git checkout "$branch"
183                         elif git rev-parse "refs/remotes/$remote/$branch" >/dev/null 2>&1; then
184                                 exists=true
185                                 verbose git checkout --track -b "$branch" "$remote/$branch"
186                         else
187                                 verbose git checkout master
188                         fi
189                         cd "$d00"
190                         checkself "$cmd" "$@"
191                         cd "$d0"
192                 done
193                 if ! $exists; then
194                         echo "The requested branch was not found in any repository."
195                 fi
196                 exec "$SELF" branch
197                 ;;
198         branch)
199                 remote=$1
200                 branch=$2
201                 srcbranch=$3
202                 if [ -z "$branch" ]; then
203                         branch=$remote
204                         remote=origin
205                 fi
206                 if [ -z "$srcbranch" ]; then
207                         srcbranch=master
208                 fi
209                 if [ -z "$branch" ]; then
210                         for d in $repos; do
211                                 enter "$d0/$d"
212                                 r=`git symbolic-ref HEAD`
213                                 r=${r#refs/heads/}
214                                 echo "$d is at $r"
215                                 cd "$d0"
216                         done
217                 else
218                         for d in $repos; do
219                                 dv=`visible_repo_name "$d"`
220                                 enter "$d0/$d"
221                                 a=
222                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
223                                         echo "Branch in $dv?"
224                                         read -r a
225                                 done
226                                 if [ x"$a" = x"y" ]; then
227                                         verbose git push "$remote" "$srcbranch":"$branch"
228                                         verbose git checkout --track -b "$branch" "$remote/$branch"
229                                 fi
230                                 cd "$d0"
231                         done
232                         "$SELF" branch
233                 fi
234                 ;;
235         branches)
236                 for d in $repos; do
237                         enter "$d0/$d"
238                         echo "In $d:"
239                         git branch -a | sed 's/^/  /; /->/d'
240                         cd "$d0"
241                 done
242                 ;;
243         merge)
244                 for d in $repos; do
245                         dv=`visible_repo_name "$d"`
246                         enter "$d0/$d"
247                         r=`git symbolic-ref HEAD`
248                         r=${r#refs/heads/}
249                         if git log HEAD..origin/master | grep .; then
250                                 # we have uncommitted changes
251                                 a=
252                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
253                                         echo "Could merge from \"master\" into \"$r\" in $dv. Do it?"
254                                         read -r a
255                                 done
256                                 if [ x"$a" = x"y" ]; then
257                                         if ! verbose git merge origin/master; then
258                                                 check_mergeconflict "$d"
259                                                 exit 1 # this should ALWAYS be fatal
260                                         fi
261                                 fi
262                         fi
263                         cd "$d0"
264                 done
265                 ;;
266         push)
267                 for d in $repos; do
268                         dv=`visible_repo_name "$d"`
269                         enter "$d0/$d"
270                         r=`git symbolic-ref HEAD`
271                         r=${r#refs/heads/}
272                         if git diff HEAD | grep .; then
273                                 # we have uncommitted changes
274                                 a=
275                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
276                                         echo "Uncommitted changes in \"$r\" in $dv. Commit?"
277                                         read -r a
278                                 done
279                                 if [ x"$a" = x"y" ]; then
280                                         verbose git commit -a
281                                 fi
282                         fi
283                         if git log "origin/$r".."$r" | grep .; then
284                                 a=
285                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
286                                         echo "Push \"$r\" in $dv?"
287                                         read -r a
288                                 done
289                                 if [ x"$a" = x"y" ]; then
290                                         verbose git push `git config "branch.$r.remote" || echo origin` HEAD
291                                 fi
292                         fi
293                         cd "$d0"
294                 done
295                 ;;
296         compile)
297                 if [ -z "$MAKEFLAGS" ]; then
298                         if [ -f /proc/cpuinfo ]; then
299                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
300                                 if [ $ncpus -gt 1 ]; then
301                                         MAKEFLAGS=-j$ncpus
302                                 fi
303                         fi
304                 fi
305                 enter "$d0/fteqcc"
306                 verbose make $MAKEFLAGS
307                 enter "$d0/data/xonotic-data.pk3dir"
308                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" $MAKEFLAGS
309                 enter "$d0/darkplaces"
310                 verbose make $MAKEFLAGS sv-debug
311                 verbose make $MAKEFLAGS cl-debug
312                 verbose make $MAKEFLAGS sdl-debug
313                 ;;
314         run)
315                 client=-sdl
316                 case "$1" in
317                         sdl|glx|agl|dedicated)
318                                 client=-$1
319                                 shift
320                                 ;;
321                         wgl)
322                                 client=
323                                 shift
324                                 ;;
325                 esac
326                 if ! [ -x "darkplaces/darkplaces$client" ]; then
327                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
328                                 client=$client.exe
329                         else
330                                 echo "Client darkplaces/darkplaces$client not found, aborting"
331                                 exit 1
332                         fi
333                 fi
334                 #verbose "darkplaces/darkplaces$client" -xonotic "$@"
335                 verbose "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
336                 ;;
337         each|foreach)
338                 for d in $repos; do
339                         enter "$d0/$d"
340                         verbose "$@"
341                         cd "$d0"
342                 done
343                 ;;
344         *)
345                 echo "Usage:"
346                 echo "  $SELF pull"
347                 echo "  $SELF merge"
348                 echo "  $SELF push"
349                 echo "  $SELF branches"
350                 echo "  $SELF branch [<remote>] <branchname>"
351                 echo "  $SELF branch <remote> <branchname> <srcbranchname>"
352                 echo "  $SELF checkout [<remote>] <branchname>"
353                 echo "  $SELF compile"
354                 echo "  $SELF run <client> <options>"
355                 echo "  $SELF each <command>"
356                 ;;
357 esac