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