]> git.xonotic.org Git - xonotic/xonotic.git/blob - all
21c9eaa54f9ad18285933805c805a269307e7956
[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 check_mergeconflict()
74 {
75         if git ls-files -u | grep ' 1   '; then
76                 echo
77                 echo "MERGE CONFLICT."
78                 echo "change into the \"$1\" project directory, and then:"
79                 echo "- edit the files mentioned above with your favorite editor,"
80                 echo "  and fix the conflicts (marked with <<<<<<< blocks)"
81                 echo "- for binary files, you can select the files using"
82                 echo "  git checkout --ours or git checkout --theirs"
83                 echo "- when done with a file, 'git add' the file"
84                 echo "- when done, 'git commit'"
85                 echo
86                 exit 1
87         fi
88 }
89
90 enter()
91 {
92         verbose cd "$1"
93         check_mergeconflict "$1"
94 }
95
96 repos_urls="
97         .
98         data/xonotic-data.pk3dir
99         data/xonotic-maps.pk3dir
100         data/xonotic-music.pk3dir
101         data/xonotic-nexcompat.pk3dir
102         darkplaces
103         fteqcc@git://github.com/Blub/qclib.git
104         div0-gittools@git://git.icculus.org/divverent/div0-gittools.git
105         netradiant
106 "
107
108 repos=`for X in $repos_urls; do echo "${X%%@*}"; done`
109
110 if [ "$#" = 0 ]; then
111         set -- help
112 fi
113 cmd=$1
114 shift
115
116 case "$cmd" in
117         update|pull)
118                 base=`git config remote.origin.url`
119                 base=${base%xonotic.git}
120                 for dcomplete in $repos_urls; do
121                         case "$dcomplete" in
122                                 *@*)
123                                         d=${dcomplete%%@*}
124                                         url=${dcomplete#*@}
125                                         switch=false
126                                         ;;
127                                 *)
128                                         d=${dcomplete%%@*}
129                                         url=$base${d##*/}.git
130                                         switch=true
131                                         ;;
132                         esac
133                         if [ -d "$d0/$d" ]; then
134                                 enter "$d0/$d"
135                                 case "$d" in
136                                         .)
137                                                 ;;
138                                         *)
139                                                 if $switch; then
140                                                         verbose git config remote.origin.url "$url"
141                                                 fi
142                                                 ;;
143                                 esac
144                                 if ! verbose git pull; then
145                                         check_mergeconflict "$d"
146                                         # do not exit, as this may also mean we are tracking something else
147                                 fi
148                                 cd "$d00"
149                                 checkself "$SELF" "$@"
150                                 cd "$d0/$d"
151                                 verbose git remote prune origin
152                                 cd "$d0"
153                         else
154                                 verbose git clone "$url" "$d0/$d"
155                         fi
156                 done
157                 ;;
158         checkout|switch)
159                 remote=$1
160                 branch=$2
161                 if [ -z "$branch" ]; then
162                         branch=$remote
163                         remote=origin
164                 fi
165                 exists=false
166                 for d in $repos; do
167                         enter "$d0/$d"
168                         if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
169                                 exists=true
170                                 verbose git checkout "$branch"
171                         elif git rev-parse "refs/remotes/$remote/$branch" >/dev/null 2>&1; then
172                                 exists=true
173                                 verbose git checkout --track -b "$branch" "$remote/$branch"
174                         else
175                                 verbose git checkout master
176                         fi
177                         cd "$d00"
178                         checkself "$SELF" "$@"
179                         cd "$d0"
180                 done
181                 if ! $exists; then
182                         echo "The requested branch was not found in any repository."
183                 fi
184                 exec "$SELF" branch
185                 ;;
186         branch)
187                 remote=$1
188                 branch=$2
189                 if [ -z "$branch" ]; then
190                         branch=$remote
191                         remote=origin
192                 fi
193                 if [ -z "$branch" ]; then
194                         for d in $repos; do
195                                 enter "$d0/$d"
196                                 r=`git symbolic-ref HEAD`
197                                 r=${r#refs/heads/}
198                                 echo "$d is at $r"
199                                 cd "$d0"
200                         done
201                 else
202                         for d in $repos; do
203                                 enter "$d0/$d"
204                                 a=
205                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
206                                         echo "Branch in \"$d\"?"
207                                         read -r a
208                                 done
209                                 if [ x"$a" = x"y" ]; then
210                                         verbose git push "$remote" HEAD:"$branch"
211                                         verbose git checkout --track -b "$branch" "$remote/$branch"
212                                 fi
213                                 cd "$d0"
214                         done
215                         "$SELF" branch
216                 fi
217                 ;;
218         branches)
219                 for d in $repos; do
220                         enter "$d0/$d"
221                         echo "In $d:"
222                         git branch -a | sed 's/^/  /; /->/d'
223                         cd "$d0"
224                 done
225                 ;;
226         merge)
227                 for d in $repos; do
228                         enter "$d0/$d"
229                         r=`git symbolic-ref HEAD`
230                         r=${r#refs/heads/}
231                         if git log HEAD..origin/master | grep .; then
232                                 # we have uncommitted changes
233                                 a=
234                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
235                                         echo "Could merge from \"master\" into \"$r\" in \"$d\". Do it?"
236                                         read -r a
237                                 done
238                                 if [ x"$a" = x"y" ]; then
239                                         if ! verbose git merge origin/master; then
240                                                 check_mergeconflict "$d"
241                                                 exit 1 # this should ALWAYS be fatal
242                                         fi
243                                 fi
244                         fi
245                         cd "$d0"
246                 done
247                 ;;
248         push)
249                 for d in $repos; do
250                         enter "$d0/$d"
251                         r=`git symbolic-ref HEAD`
252                         r=${r#refs/heads/}
253                         if git diff HEAD | grep .; then
254                                 # we have uncommitted changes
255                                 a=
256                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
257                                         echo "Uncommitted changes in \"$r\" in \"$d\". Commit?"
258                                         read -r a
259                                 done
260                                 if [ x"$a" = x"y" ]; then
261                                         verbose git commit -a
262                                 fi
263                         fi
264                         if git log "origin/$r".."$r" | grep .; then
265                                 a=
266                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
267                                         echo "Push \"$r\" in \"$d\"?"
268                                         read -r a
269                                 done
270                                 if [ x"$a" = x"y" ]; then
271                                         verbose git push `git config "branch.$r.remote" || echo origin` HEAD
272                                 fi
273                         fi
274                         cd "$d0"
275                 done
276                 ;;
277         compile)
278                 if [ -z "$MAKEFLAGS" ]; then
279                         if [ -f /proc/cpuinfo ]; then
280                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
281                                 if [ $ncpus -gt 1 ]; then
282                                         MAKEFLAGS=-j$ncpus
283                                 fi
284                         fi
285                 fi
286                 enter "$d0/fteqcc"
287                 verbose make $MAKEFLAGS
288                 enter "$d0/data/xonotic-data.pk3dir"
289                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" $MAKEFLAGS
290                 enter "$d0/darkplaces"
291                 verbose make $MAKEFLAGS sv-debug
292                 verbose make $MAKEFLAGS cl-debug
293                 verbose make $MAKEFLAGS sdl-debug
294                 ;;
295         run)
296                 client=-sdl
297                 case "$1" in
298                         sdl|glx|agl|dedicated)
299                                 client=-$1
300                                 shift
301                                 ;;
302                         wgl)
303                                 client=
304                                 shift
305                                 ;;
306                 esac
307                 if ! [ -x "darkplaces/darkplaces$client" ]; then
308                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
309                                 client=$client.exe
310                         else
311                                 echo "Client darkplaces/darkplaces$client not found, aborting"
312                                 exit 1
313                         fi
314                 fi
315                 #verbose "darkplaces/darkplaces$client" -xonotic "$@"
316                 verbose "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
317                 ;;
318         each|foreach)
319                 for d in $repos; do
320                         enter "$d0/$d"
321                         verbose "$@"
322                         cd "$d0"
323                 done
324                 ;;
325         *)
326                 echo "Usage:"
327                 echo "  $SELF pull"
328                 echo "  $SELF merge"
329                 echo "  $SELF push"
330                 echo "  $SELF branches"
331                 echo "  $SELF branch [<remote>] <branchname>"
332                 echo "  $SELF checkout [<remote>] <branchname>"
333                 echo "  $SELF compile"
334                 echo "  $SELF run <client> <options>"
335                 echo "  $SELF each <command>"
336                 ;;
337 esac