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