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