]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - client/make-request.sh
- add -Uhv = upgrade alias
[projects/pld-builder.new.git] / client / make-request.sh
CommitLineData
1344b6f1
MM
1#!/bin/sh
2
864cdeb5
MM
3builders=
4specs=
5with=
6without=
7flags=
8command=
9command_flags=
16b5ec37 10gpg_opts=
e728b34c
ER
11default_branch='HEAD'
12distro=
bfa10c0d
AM
13url="http://ep09.pld-linux.org:1234/"
14
15[ -x /usr/bin/python ] && send_mode="python" || send_mode="mail"
544ca060 16
e29fbd39
AG
17if [ -n "$HOME_ETC" ]; then
18 USER_CFG=$HOME_ETC/.requestrc
544ca060 19else
e29fbd39 20 USER_CFG=$HOME/.requestrc
e728b34c 21fi
e29fbd39 22
e728b34c 23if [ ! -f "$USER_CFG" ]; then
e29fbd39 24 echo "Creating config file $USER_CFG. You *must* edit it."
e728b34c 25 cat >$USER_CFG <<'EOF'
1344b6f1 26priority=2
e728b34c 27requester=deviloper@pld-linux.org
544ca060 28default_key=deviloper@pld-linux.org
bfa10c0d
AM
29send_mode="$send_mode"
30url="$url"
1344b6f1 31mailer="/usr/sbin/sendmail -t"
16b5ec37 32gpg_opts=""
e728b34c 33distro=th
1344b6f1 34
a757e911 35# defaults:
771f742d 36f_upgrade=yes
544ca060
MM
37EOF
38exit
39fi
40
e728b34c 41if [ -f "$USER_CFG" ]; then
9cc9841b 42 . $USER_CFG
e728b34c
ER
43fi
44
bfa10c0d
AM
45send_request() {
46 case "$send_mode" in
47 "mail")
48 cat - | $mailer
49 ;;
50 *)
51 cat - | python -c '
52import sys, urllib2
53
54try:
55 data = sys.stdin.read()
56 req = urllib2.Request(sys.argv[1], data)
57 f = urllib2.urlopen(req, timeout=10)
58 f.close()
59except Exception, e:
60 print >> sys.stderr, "Problem while sending request: %s" % e
61 sys.exit(1)
cd28f421 62print >> sys.stdout, "Request queued."
bfa10c0d
AM
63' "$url"
64 ;;
65 esac
66}
67
11270534
ER
68die() {
69 echo >&2 "$0: $*"
9cc9841b 70 exit 1
a757e911 71}
1344b6f1 72
586a5f1f 73usage() {
9cc9841b
ER
74 echo "Usage: make-request.sh [OPTION] ... [SPECFILE] ...."
75 echo ""
76 echo "Mandatory arguments to long options are mandatory for short options too."
77 echo " -C --config-file /path/to/config/file"
78 echo " Source additional config file (after $USER_CFG), useful when"
79 echo " when sending build requests to Ac/Th from the same account"
80 echo " -b 'BUILDER BUILDER ...' --builder='BUILDER BUILDER ...'"
81 echo " Sends request to given builders"
82 echo " --with VALUE --without VALUE"
83 echo " Build package with(out) a given bcond"
84 echo " --kernel VALUE"
85 echo " set alt_kernel to VALUE"
be264f26
ER
86 echo " --target VALUE"
87 echo " set --target to VALUE"
11270534
ER
88 echo " --branch VALUE"
89 echo " specify default branch for specs in request"
9cc9841b
ER
90 echo " -t --test-build"
91 echo " Performs a 'test-build'. Package will be uploaded to test/ tree"
92 echo " and won't be upgraded on builders"
93 echo " -r --ready-build"
94 echo " Build and upgrade package and upload it to ready/ tree"
95 echo " -u --upgrade"
96 echo " Forces package upgrade (for use with -t)"
97 echo " -n --no-upgrade"
98 echo " Disables package upgrade (for use with -r)"
99 echo " -ni -no-install-br"
100 echo " Do not install missing BuildRequires (--nodeps)"
101 echo " -f --flag"
102 echo " -d --distro"
103 echo " Specify value for \$distro"
104 echo " -cf --command-flag"
105 echo " Not yet documented"
106 echo " -c --command"
107 echo " Executes a given command on builders"
108 echo " --test-remove-pkg"
109 echo " shortcut for --command poldek -evt ARGS"
110 echo " --remove-pkg"
111 echo " shortcut for --command poldek -ev --noask ARGS"
112 echo " --upgrade-pkg"
c983e07f 113 echo " shortcut for --command poldek --up -Uv ARGS"
9cc9841b
ER
114 echo " --cvsup"
115 echo " Updates builders infrastructure (outside chroot)"
116 echo " -q "
117 echo " shortcut for --command rpm -q ARGS"
118 echo " -g --gpg-opts \"opts\""
119 echo " Pass additional options to gpg binary"
120 echo " -p --priority VALUE"
121 echo " sets request priority (default 2)"
122 echo " -h --help"
123 echo " Displays this help message"
124 exit 0;
586a5f1f
AG
125}
126
127
1344b6f1 128while [ $# -gt 0 ] ; do
9cc9841b
ER
129 case "$1" in
130 --distro | -d )
131 distro=$2
132 shift
133 ;;
134
135 --config-file | -C )
136 [ -f $2 ] && . $2 || die "Config file not found"
137 shift
138 ;;
139
140 --builder | -b )
141 builders="$builders $2"
142 shift
143 ;;
144
145 --with )
146 with="$with $2"
147 shift
148 ;;
149
150 --without )
151 without="$without $2"
152 shift
153 ;;
154
155 --test-build | -t )
156 build_mode=test
157 f_upgrade=no
158 ;;
159
160 --kernel )
161 kernel=$2
162 shift
163 ;;
164
be264f26
ER
165 --target)
166 target=$2
167 shift
168 ;;
169
11270534
ER
170 --branch)
171 branch=$2
172 shift
173 ;;
174
9cc9841b
ER
175 --priority | -p )
176 priority=$2
177 shift
178 ;;
179
180 --ready-build | -r )
181 build_mode=ready
182 ;;
183
184 --upgrade | -u )
185 f_upgrade=yes
186 ;;
187
188 --no-upgrade | -n )
189 f_upgrade=no
190 ;;
191
192 --no-install-br | -ni )
193 flags="$flags no-install-br"
194 ;;
195
196 --flag | -f )
197 flags="$flags $2"
198 shift
199 ;;
200
201 --command-flags | -cf )
202 command_flags="$2"
203 shift
204 ;;
205
206 --command | -c )
207 command="$2"
208 f_upgrade=no
209 shift
210 ;;
211 --test-remove-pkg)
212 command="poldek -evt $2"
213 f_upgrade=no
214 shift
215 ;;
216 --remove-pkg)
217 command="poldek -ev --noask $2"
218 f_upgrade=no
219 shift
220 ;;
b098536f 221 --upgrade-pkg|-Uhv)
c983e07f 222 command="poldek --up -Uv $2"
9cc9841b
ER
223 f_upgrade=no
224 shift
225 ;;
226 -q)
227 command="rpm -q $2"
228 f_upgrade=no
229 shift
230 ;;
231
232 --cvsup )
233 command_flags="no-chroot"
234 command="cvs up"
49a8a604 235 f_upgrade=no
9cc9841b
ER
236 ;;
237
238 --gpg-opts | -g )
239 gpg_opts="$2"
240 shift
241 ;;
242
243 --help | -h )
244 usage
245 ;;
246
247 -* )
248 die "unknown knob: $1"
249 ;;
250
251 *:* | * )
252 specs="$specs $1"
253 ;;
254 esac
255 shift
1344b6f1
MM
256done
257
e728b34c
ER
258case "$distro" in
259ac)
9cc9841b
ER
260 builder_email="builder-ac@pld-linux.org"
261 default_builders="ac-*"
262 default_branch="AC-branch"
263 ;;
3e991c55 264ac-java) # fake "distro" for java available ac architectures
e4047e17 265 builder_email="builder-ac@pld-linux.org"
9cc9841b
ER
266 default_builders="ac-i586 ac-i686 ac-athlon ac-amd64"
267 default_branch="AC-branch"
268 ;;
70d46bca 269ac-xen) # fake "distro" for xen-enabled architectures
e4047e17
ER
270 builder_email="builder-ac@pld-linux.org"
271 default_builders="ac-i686 ac-athlon ac-amd64"
272 default_branch="AC-branch"
70d46bca 273 ;;
e728b34c 274ti)
9cc9841b
ER
275 builder_email="builderti@ep09.pld-linux.org"
276 default_builders="ti-*"
277 ;;
e728b34c 278th)
9cc9841b
ER
279 builder_email="builderth@ep09.pld-linux.org"
280 default_builders="th-*"
281 ;;
3e991c55 282th-java) # fake "distro" for java available th architectures
e219518b 283 builder_email="builderth@ep09.pld-linux.org"
976435cb 284 default_builders="th-x86_64 th-athlon th-i686"
e219518b 285 ;;
32384897 286aidath)
287 builder_email="builderaidath@ep09.pld-linux.org"
288 default_builders="aidath-*"
289 ;;
14b580de
ER
290*)
291 die "distro \`$distro' not known"
292 ;;
e728b34c
ER
293esac
294
11270534
ER
295branch=${branch:-$default_branch}
296
e728b34c 297specs=`for s in $specs; do
9cc9841b
ER
298 case "$s" in
299 *.spec:*) # spec with branch
300 echo $s
301 ;;
302 *.spec) # spec without branch
11270534 303 echo $s:$branch
9cc9841b
ER
304 ;;
305 *:*) # package name with branch
306 echo $s | sed -e 's/:/.spec:/'
307 ;;
308 *) # just package name
11270534 309 echo $s.spec:$branch
9cc9841b
ER
310 ;;
311 esac
878677a8 312done`
1344b6f1 313
2f470d17 314if [[ "$requester" != *@* ]] ; then
9cc9841b 315 requester="$requester@pld-linux.org"
2f470d17
MK
316fi
317
14b580de 318if [ -z "$builders" ] ; then
9cc9841b 319 builders="$default_builders"
a757e911
MM
320fi
321
544ca060 322if [ "$f_upgrade" = "yes" ] ; then
9cc9841b 323 flags="$flags upgrade"
a757e911
MM
324fi
325
e936beda 326if [ "$build_mode" = "test" ] ; then
9cc9841b
ER
327 if [ "$f_upgrade" = "yes" ] ; then
328 die "--upgrade and --test-build are mutually exclusive"
329 fi
330 flags="$flags test-build"
e936beda
MM
331fi
332
e728b34c
ER
333if [ -z "$build_mode" ] ; then
334 # missing build mode, builders go crazy when you proceed"
335 die "please specify build mode"
336fi
337
338
280b1afd 339ok=
e728b34c
ER
340for s in $specs; do
341 ok=1
280b1afd
MM
342done
343
344if [ "$ok" = "" ] ; then
9cc9841b
ER
345 if [ "$command" = "" ] ; then
346 die "no specs passed"
347 fi
c4aa0539 348else
9cc9841b
ER
349 if [ "$command" != "" ] ; then
350 die "cannot pass specs and --command"
351 fi
280b1afd
MM
352fi
353
1344b6f1
MM
354id=$(uuidgen)
355
356gen_req() {
9cc9841b
ER
357 echo "<group id='$id' no='0' flags='$flags'>"
358 echo " <time>$(date +%s)</time>"
359 echo " <priority>$priority</priority>"
360 echo
361
362 if [ "$command" != "" ] ; then
363 bid=$(uuidgen)
a32d5b77 364 echo >&2 "* Command: $command"
9cc9841b 365 echo " <batch id='$bid' depends-on=''>"
037ca246 366 echo " <command flags='$command_flags'>$(echo "$command" | sed -e 's,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g')</command>"
9cc9841b 367 echo " <info></info>"
14b580de
ER
368 for b in $builders; do
369 echo >&2 "* Builder: $b"
9cc9841b
ER
370 echo " <builder>$b</builder>"
371 done
372 echo " </batch>"
373 else
374
375 echo >&2 "* Using priority $priority"
376 echo >&2 "* Using email $builder_email"
377 echo >&2 "* Build mode: $build_mode"
e728b34c
ER
378 if [ "$f_upgrade" = "yes" ] ; then
379 echo >&2 "* Upgrade mode: $f_upgrade"
380 fi
9cc9841b 381 echo >&2 "* Queue-ID: $id"
e728b34c 382
9cc9841b
ER
383 # first id:
384 fid=
e728b34c 385 i=1
4d222cff
ER
386
387 for b in $builders; do
388 echo >&2 "* Builder: $b"
389 done
9cc9841b
ER
390 for s in $specs; do
391 bid=$(uuidgen)
392 echo " <batch id='$bid' depends-on='$fid'>"
393 [ "$fid" = "" ] && fid="$bid"
394 name=$(echo "$s" | sed -e 's|:.*||')
395 branch=$(echo "$s" | sed -e 's|.*:||')
be264f26 396 echo >&2 "* Adding #$i $name:$branch${kernel:+ alt_kernel=$kernel}${target:+ target=$target}"
9cc9841b
ER
397 echo " <spec>$name</spec>"
398 echo " <branch>$branch</branch>"
399 echo " ${kernel:+<kernel>$kernel</kernel>}"
be264f26 400 echo " ${target:+<target>$target</target>}"
9cc9841b
ER
401 echo " <info></info>"
402 echo
403 for b in $with; do
404 echo " <with>$b</with>"
405 done
406 for b in $without; do
407 echo " <without>$b</without>"
408 done
409 echo
410 for b in $builders; do
411 echo " <builder>$b</builder>"
412 done
413 echo " </batch>"
e728b34c 414 i=$((i+1))
9cc9841b 415 done
c4aa0539 416
9cc9841b 417 fi
e728b34c 418
9cc9841b 419 echo "</group>"
1344b6f1
MM
420}
421
422gen_email () {
e728b34c
ER
423 # make request first, so the STDERR/STDOUT streams won't be mixed
424 local req=$(gen_req)
425
1344b6f1 426cat <<EOF
2f470d17 427From: $requester
1344b6f1
MM
428To: $builder_email
429Subject: build request
430Message-Id: <$id@$(hostname)>
431X-New-PLD-Builder: request
2d28916b 432X-Requester-Version: \$Id$
1344b6f1 433
e728b34c 434$(echo "$req" | gpg --clearsign --default-key $default_key $gpg_opts)
1344b6f1
MM
435EOF
436}
437
bfa10c0d 438gen_email | send_request
This page took 0.197144 seconds and 4 git commands to generate.