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