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