Make it look nicer, but do the same ;)
[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 self=`cksum "$SELF"`
37 checkself()
38 {
39         self_new=`cksum "$SELF"`
40         if [ x"$self" != x"$self_new" ]; then
41                 msg "./all has changed."
42                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
43                         msg "Rerunning the requested operation to make sure."
44                         export XONOTIC_FORBID_RERUN_ALL=1
45                         exec "$SELF" "$@"
46                 else
47                         msg "Please try $SELF update, and then retry your requested operation."
48                         exit 1
49                 fi
50         fi
51         return 0
52 }
53
54 verbose()
55 {
56         msg "+ $*"
57         "$@"
58 }
59
60 repos_urls="
61         .
62         data/xonotic-data.pk3dir
63         data/xonotic-maps.pk3dir
64         data/xonotic-music.pk3dir
65         data/xonotic-nexcompat.pk3dir
66         darkplaces
67         fteqcc@git://github.com/Blub/qclib.git
68         div0-gittools@git://git.icculus.org/divverent/div0-gittools.git
69         netradiant
70 "
71
72 repos=`for X in $repos_urls; do echo "${X%%@*}"; done`
73
74 if [ "$#" = 0 ]; then
75         set -- help
76 fi
77 cmd=$1
78 shift
79
80 case "$cmd" in
81         update|pull)
82                 base=`git config remote.origin.url`
83                 base=${base%xonotic.git}
84                 for dcomplete in $repos_urls; do
85                         case "$dcomplete" in
86                                 *@*)
87                                         d=${dcomplete%%@*}
88                                         url=${dcomplete#*@}
89                                         switch=false
90                                         ;;
91                                 *)
92                                         d=${dcomplete%%@*}
93                                         url=$base${d##*/}.git
94                                         switch=true
95                                         ;;
96                         esac
97                         if [ -d "$d0/$d" ]; then
98                                 verbose cd "$d0/$d"
99                                 case "$d" in
100                                         .)
101                                                 ;;
102                                         *)
103                                                 if $switch; then
104                                                         verbose git config remote.origin.url "$url"
105                                                 fi
106                                                 ;;
107                                 esac
108                                 verbose git pull
109                                 cd "$d00"
110                                 checkself "$SELF" "$@"
111                                 cd "$d0/$d"
112                                 verbose git remote prune origin
113                                 cd "$d0"
114                         else
115                                 verbose git clone "$url" "$d0/$d"
116                         fi
117                 done
118                 ;;
119         checkout|switch)
120                 remote=$1
121                 branch=$2
122                 if [ -z "$branch" ]; then
123                         branch=$remote
124                         remote=origin
125                 fi
126                 exists=false
127                 for d in $repos; do
128                         verbose cd "$d0/$d"
129                         if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
130                                 exists=true
131                                 verbose git checkout "$branch"
132                         elif git rev-parse "refs/remotes/$remote/$branch" >/dev/null 2>&1; then
133                                 exists=true
134                                 verbose git checkout --track -b "$branch" "$remote/$branch"
135                         else
136                                 verbose git checkout master
137                         fi
138                         cd "$d00"
139                         checkself "$SELF" "$@"
140                         cd "$d0"
141                 done
142                 if ! $exists; then
143                         echo "The requested branch was not found in any repository."
144                 fi
145                 exec "$SELF" branch
146                 ;;
147         branch)
148                 remote=$1
149                 branch=$2
150                 if [ -z "$branch" ]; then
151                         branch=$remote
152                         remote=origin
153                 fi
154                 if [ -z "$branch" ]; then
155                         for d in $repos; do
156                                 cd "$d0/$d"
157                                 r=`git symbolic-ref HEAD`
158                                 r=${r#refs/heads/}
159                                 echo "$d is at $r"
160                                 cd "$d0"
161                         done
162                 else
163                         for d in $repos; do
164                                 cd "$d0/$d"
165                                 a=
166                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
167                                         echo "Branch in \"$d\"?"
168                                         read -r a
169                                 done
170                                 if [ x"$a" = x"y" ]; then
171                                         verbose git push "$remote" HEAD:"$branch"
172                                         verbose git checkout --track -b "$branch" "$remote/$branch"
173                                 fi
174                                 cd "$d0"
175                         done
176                         "$SELF" branch
177                 fi
178                 ;;
179         branches)
180                 for d in $repos; do
181                         cd "$d0/$d"
182                         echo "In $d:"
183                         git branch -a | sed 's/^/  /; /->/d'
184                         cd "$d0"
185                 done
186                 ;;
187         push)
188                 for d in $repos; do
189                         cd "$d0/$d"
190                         r=`git symbolic-ref HEAD`
191                         r=${r#refs/heads/}
192                         if git diff HEAD | grep .; then
193                                 # we have uncommitted changes
194                                 a=
195                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
196                                         echo "Uncommitted changes in \"$r\" in \"$d\". Commit?"
197                                         read -r a
198                                 done
199                                 if [ x"$a" = x"y" ]; then
200                                         verbose git commit -a
201                                 fi
202                         fi
203                         if git log "origin/$r".."$r" | grep .; then
204                                 a=
205                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
206                                         echo "Push \"$r\" in \"$d\"?"
207                                         read -r a
208                                 done
209                                 if [ x"$a" = x"y" ]; then
210                                         verbose git push `git config "branch.$r.remote" || echo origin` HEAD
211                                 fi
212                         fi
213                         cd "$d0"
214                 done
215                 ;;
216         compile)
217                 if [ -z "$MAKEFLAGS" ]; then
218                         if [ -f /proc/cpuinfo ]; then
219                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
220                                 if [ $ncpus -gt 1 ]; then
221                                         MAKEFLAGS=-j$ncpus
222                                 fi
223                         fi
224                 fi
225                 verbose cd "$d0/fteqcc"
226                 verbose make $MAKEFLAGS
227                 verbose cd "$d0/data/xonotic-data.pk3dir"
228                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" $MAKEFLAGS
229                 verbose cd "$d0/darkplaces"
230                 verbose make $MAKEFLAGS sv-debug
231                 verbose make $MAKEFLAGS cl-debug
232                 verbose make $MAKEFLAGS sdl-debug
233                 ;;
234         run)
235                 client=-sdl
236                 case "$1" in
237                         sdl|glx|agl|dedicated)
238                                 client=-$1
239                                 shift
240                                 ;;
241                         wgl)
242                                 client=
243                                 shift
244                                 ;;
245                 esac
246                 if ! [ -x "darkplaces/darkplaces$client" ]; then
247                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
248                                 client=$client.exe
249                         else
250                                 echo "Client darkplaces/darkplaces$client not found, aborting"
251                                 exit 1
252                         fi
253                 fi
254                 #verbose "darkplaces/darkplaces$client" -xonotic "$@"
255                 verbose "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
256                 ;;
257         each|foreach)
258                 for d in $repos; do
259                         verbose cd "$d0/$d"
260                         verbose "$@"
261                         cd "$d0"
262                 done
263                 ;;
264         *)
265                 echo "Usage:"
266                 echo "  $SELF pull"
267                 echo "  $SELF push"
268                 echo "  $SELF branches"
269                 echo "  $SELF branch <remote> <branchname>"
270                 echo "  $SELF checkout"
271                 echo "  $SELF compile"
272                 echo "  $SELF run <client> <options>"
273                 echo "  $SELF each <command>"
274                 ;;
275 esac