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