rerunning did not work for me, this should fix it
[xonotic/xonotic.git] / all
1 #!/bin/sh
2
3 set -e
4
5 msg()
6 {
7         echo "\e[1m$*\e[m"
8 }
9
10 self=`cksum "$0"`
11 checkself()
12 {
13         self_new=`cksum "$0"`
14         if [ x"$self" != x"$self_new" ]; then
15                 msg "./all has changed."
16                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
17                         msg "Rerunning the requested operation to make sure."
18                         export XONOTIC_FORBID_RERUN_ALL=1
19                         exec "$0" "$@"
20                 else
21                         msg "Please try $0 update, and then retry your requested operation."
22                         exit 1
23                 fi
24         fi
25         return 0
26 }
27
28 verbose()
29 {
30         msg "+ $*"
31         "$@"
32 }
33
34 repos_urls="
35         .
36         data/xonotic-data.pk3dir
37         data/xonotic-maps.pk3dir
38         data/xonotic-music.pk3dir
39         data/xonotic-nexcompat.pk3dir
40         darkplaces
41         fteqcc@git://github.com/Blub/qclib.git
42         div0-gittools@git://git.icculus.org/divverent/div0-gittools.git
43 "
44
45 repos=`for X in $repos_urls; do echo "${X%%@*}"; done`
46
47 if [ "$#" = 0 ]; then
48         set -- help
49 fi
50 cmd=$1
51 shift
52
53 d0=`pwd`
54 case "$cmd" in
55         update|pull)
56                 base=`git config remote.origin.url`
57                 base=${base%xonotic.git}
58                 for dcomplete in $repos_urls; do
59                         case "$dcomplete" in
60                                 *@*)
61                                         d=${dcomplete%%@*}
62                                         url=${dcomplete#*@}
63                                         switch=false
64                                         ;;
65                                 *)
66                                         d=${dcomplete%%@*}
67                                         url=$base${d##*/}.git
68                                         switch=true
69                                         ;;
70                         esac
71                         if [ -d "$d0/$d" ]; then
72                                 verbose cd "$d0/$d"
73                                 case "$d" in
74                                         .)
75                                                 ;;
76                                         *)
77                                                 if $switch; then
78                                                         verbose git config remote.origin.url "$url"
79                                                 fi
80                                                 ;;
81                                 esac
82                                 verbose git pull
83                                 cd "$d0"
84                                 checkself "$0" "$@"
85                                 cd "$d0/$d"
86                                 verbose git remote prune origin
87                                 cd "$d0"
88                         else
89                                 verbose git clone "$url" "$d0/$d"
90                         fi
91                 done
92                 ;;
93         checkout|switch)
94                 remote=$1
95                 branch=$2
96                 if [ -z "$branch" ]; then
97                         branch=$remote
98                         remote=origin
99                 fi
100                 exists=false
101                 for d in $repos; do
102                         verbose cd "$d0/$d"
103                         if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
104                                 exists=true
105                                 verbose git checkout "$branch"
106                         elif git rev-parse "refs/remotes/$remote/$branch" >/dev/null 2>&1; then
107                                 exists=true
108                                 verbose git checkout --track -b "$branch" "$remote/$branch"
109                         else
110                                 verbose git checkout master
111                         fi
112                         cd "$d0"
113                         checkself "$0" "$@"
114                 done
115                 if ! $exists; then
116                         echo "The requested branch was not found in any repository."
117                 fi
118                 "$0" branch
119                 ;;
120         branch)
121                 remote=$1
122                 branch=$2
123                 if [ -z "$branch" ]; then
124                         branch=$remote
125                         remote=origin
126                 fi
127                 if [ -z "$branch" ]; then
128                         for d in $repos; do
129                                 cd "$d0/$d"
130                                 r=`git symbolic-ref HEAD`
131                                 r=${r#refs/heads/}
132                                 echo "$d is at $r"
133                                 cd "$d0"
134                         done
135                 else
136                         for d in $repos; do
137                                 cd "$d0/$d"
138                                 a=
139                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
140                                         echo "Branch in $d?"
141                                         read -r a
142                                 done
143                                 if [ x"$a" = x"y" ]; then
144                                         verbose git push "$remote" HEAD:"$branch"
145                                         verbose git checkout --track -b "$branch" "$remote/$branch"
146                                 fi
147                                 cd "$d0"
148                         done
149                         "$0" branch
150                 fi
151                 ;;
152         branches)
153                 for d in $repos; do
154                         cd "$d0/$d"
155                         echo "In $d:"
156                         git branch -a | sed 's/^/  /; /->/d'
157                         cd "$d0"
158                 done
159                 ;;
160         push)
161                 for d in $repos; do
162                         cd "$d0/$d"
163                         r=`git symbolic-ref HEAD`
164                         r=${r#refs/heads/}
165                         a=
166                         if git log "origin/$r".."$r" | grep .; then
167                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
168                                         echo "Push $r in $d?"
169                                         read -r a
170                                 done
171                                 if [ x"$a" = x"y" ]; then
172                                         verbose git push `git config "branch.$r.remote" || echo origin` HEAD
173                                 fi
174                         fi
175                         cd "$d0"
176                 done
177                 ;;
178         compile)
179                 if [ -z "$MAKEFLAGS" ]; then
180                         if [ -f /proc/cpuinfo ]; then
181                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
182                                 if [ $ncpus -gt 1 ]; then
183                                         MAKEFLAGS=-j$ncpus
184                                 fi
185                         fi
186                 fi
187                 verbose cd "$d0/fteqcc"
188                 verbose make $MAKEFLAGS
189                 verbose cd "$d0/data/xonotic-data.pk3dir"
190                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" $MAKEFLAGS
191                 verbose cd "$d0/darkplaces"
192                 verbose make $MAKEFLAGS sv-debug
193                 verbose make $MAKEFLAGS cl-debug
194                 verbose make $MAKEFLAGS sdl-debug
195                 ;;
196         run)
197                 client=-sdl
198                 case "$1" in
199                         sdl|glx|agl|dedicated)
200                                 client=-$1
201                                 shift
202                                 ;;
203                         wgl)
204                                 client=
205                                 shift
206                                 ;;
207                 esac
208                 if ! [ -x "darkplaces/darkplaces$client" ]; then
209                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
210                                 client=$client.exe
211                         else
212                                 echo "Client darkplaces/darkplaces$client not found, aborting"
213                                 exit 1
214                         fi
215                 fi
216                 #verbose "darkplaces/darkplaces$client" -xonotic "$@"
217                 verbose "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
218                 ;;
219         each|foreach)
220                 for d in $repos; do
221                         verbose cd "$d0/$d"
222                         verbose "$@"
223                         cd "$d0"
224                 done
225                 ;;
226         *)
227                 echo "Usage:"
228                 echo "  $0 pull"
229                 echo "  $0 push"
230                 echo "  $0 branches"
231                 echo "  $0 branch <remote> <branchname>"
232                 echo "  $0 checkout"
233                 echo "  $0 compile"
234                 echo "  $0 run <client> <options>"
235                 echo "  $0 each <command>"
236                 ;;
237 esac