]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - client/make-request.sh
- allow sending commands and build jobs in same batch
[projects/pld-builder.new.git] / client / make-request.sh
CommitLineData
1344b6f1
MM
1#!/bin/sh
2
b4818b81
AM
3# prevent "*" from being expanded in builders var
4cd /usr/share/empty
5
864cdeb5 6builders=
864cdeb5
MM
7with=
8without=
9flags=
10command=
11command_flags=
16b5ec37 12gpg_opts=
e728b34c
ER
13default_branch='HEAD'
14distro=
bcb3a8b8 15url=
218a4c96 16no_depend=no
bfa10c0d
AM
17
18[ -x /usr/bin/python ] && send_mode="python" || send_mode="mail"
544ca060 19
e29fbd39
AG
20if [ -n "$HOME_ETC" ]; then
21 USER_CFG=$HOME_ETC/.requestrc
544ca060 22else
e29fbd39 23 USER_CFG=$HOME/.requestrc
e728b34c 24fi
e29fbd39 25
e728b34c 26if [ ! -f "$USER_CFG" ]; then
e29fbd39 27 echo "Creating config file $USER_CFG. You *must* edit it."
bcb3a8b8 28 cat > $USER_CFG <<EOF
1344b6f1 29priority=2
e728b34c 30requester=deviloper@pld-linux.org
544ca060 31default_key=deviloper@pld-linux.org
bfa10c0d
AM
32send_mode="$send_mode"
33url="$url"
1344b6f1 34mailer="/usr/sbin/sendmail -t"
16b5ec37 35gpg_opts=""
e728b34c 36distro=th
1cd123e3 37url="http://src.th.pld-linux.org:1234/"
1344b6f1 38
a757e911 39# defaults:
771f742d 40f_upgrade=yes
544ca060
MM
41EOF
42exit
43fi
44
e728b34c 45if [ -f "$USER_CFG" ]; then
9cc9841b 46 . $USER_CFG
e728b34c
ER
47fi
48
45d8ed70
ER
49# internal options, not to be overriden
50specs=
51df_fetch=no
a166aeda 52upgrade_macros=no
45d8ed70
ER
53
54die() {
55 echo >&2 "$0: $*"
56 exit 1
57}
58
bfa10c0d 59send_request() {
bcb3a8b8
ER
60 # switch to mail mode, if no url set
61 [ -z "$url" ] && send_mode="mail"
62
bcb3a8b8
ER
63 case "$send_mode" in
64 "mail")
65 echo >&2 "* Sending using mail mode"
66 cat - | $mailer
67 ;;
68 *)
69 echo >&2 "* Sending using http mode to $url"
70 cat - | python -c '
e3a591a1 71import sys, socket, urllib2
bfa10c0d
AM
72
73try:
74 data = sys.stdin.read()
e6aa37ec 75 url = sys.argv[1]
e3a591a1 76 socket.setdefaulttimeout(10)
e6aa37ec 77 req = urllib2.Request(url, data)
e3a591a1 78 f = urllib2.urlopen(req)
bfa10c0d
AM
79 f.close()
80except Exception, e:
e6aa37ec 81 print >> sys.stderr, "Problem while sending request via HTTP: %s: %s" % (url, e)
bfa10c0d 82 sys.exit(1)
f04b3329 83print >> sys.stdout, "Request queued via HTTP."
bfa10c0d 84' "$url"
bcb3a8b8
ER
85 ;;
86 esac
bfa10c0d
AM
87}
88
45d8ed70
ER
89# simple df_fetcher, based on packages/fetchsrc_request
90# TODO: tcp (smtp) mode
91# TODO: adjust for ~/.requestrc config
92df_fetch() {
93 local specs="$@"
94
95 # Sending by
96 local MAILER='/usr/sbin/sendmail'
97 # MAILER='/usr/bin/msmtp'
98 # Sending via
99 local VIA="SENDMAIL"
100 #VIA="localhost"
101 local VIA_ARGS=""
102 #VIA_ARGS="some additional flags"
103 # e.g. for msmtp:
104 # VIA_ARGS='-a gmail'
105 #
106 # DISTFILES EMAIL
107 local DMAIL="distfiles@pld-linux.org"
108
109 local HOST=$(hostname -f)
110 local LOGIN=${requester%@*}
111
112 for spec in $specs; do
113 local SPEC=$(echo "$spec" | sed -e 's|:.*||')
114 local BRANCH=$(echo "$spec" | sed -e 's|.*:||')
115 echo >&2 "Distfiles Request: $SPEC:$BRANCH via $MAILER ${VIA_ARGS:+ ($VIA_ARGS)}"
116 cat <<-EOF | "$MAILER" -t -i $VIA_ARGS
117 To: $DMAIL
118 From: $LOGIN <$LOGIN@$HOST>
119 Subject: fetchsrc_request notify
120 X-CVS-Module: SPECS
121 X-distfiles-request: yes
122 X-Login: $LOGIN
123 X-Spec: $SPEC
124 X-Branch: $BRANCH
125 X-Flags: force-reply
126
127 .
128 EOF
129 done
a757e911 130}
1344b6f1 131
586a5f1f 132usage() {
23e1dcfb
ER
133 cat <<EOF
134Usage: make-request.sh [OPTION] ... [SPECFILE] ....
135
136Mandatory arguments to long options are mandatory for short options too.
137
bb30a063
ER
138 -C, --config-file /path/to/config/file
139 Source additional config file (after $USER_CFG), useful when
140 when sending build requests to Ac/Th from the same account
141 -b 'BUILDER BUILDER ...', --builder='BUILDER BUILDER ...'
23e1dcfb 142 Sends request to given builders (in 'version-arch' format)
bb30a063
ER
143 --with VALUE, --without VALUE
144 Build package with(out) a given bcond
23e1dcfb 145 --kernel VALUE
bb30a063 146 set alt_kernel to VALUE
23e1dcfb 147 --target VALUE
bb30a063 148 set --target to VALUE
23e1dcfb 149 -s BUILD_ID, --skip BUILD_ID[,BUILD_ID][,BUILD_ID]
bb30a063 150 mark build ids on src builder to be skipped
23e1dcfb 151 --branch VALUE
bb30a063
ER
152 specify default branch for specs in request
153 -t, --test-build
0e59dd68
AM
154 Performs a 'test-build'. Package will be uploaded to hidden .test-builds/
155 ftp tree and won't be upgraded on builders.
bb30a063 156 -r, --ready-build
0e59dd68
AM
157 Preforms a 'ready' build. Package will be built and uploaded to test/ ftp tree
158 (and later moved by release manager staff to ready/ and main ftp tree)
bb30a063
ER
159 -u, --upgrade
160 Forces package upgrade (for use with -c or -q, not -t)
161 -n, --no-upgrade
162 Disables package upgrade (for use with -r)
218a4c96 163 -ni, --no-install-br
bb30a063 164 Do not install missing BuildRequires (--nodeps)
218a4c96
ER
165 -nd, --no-depend
166 Do not add dependency of build jobs, each job in batch runs itself
bb30a063
ER
167 -j, --jobs
168 Number of parallel jobs for single build
169 -f, --flag
170 -d, --distro DISTRO
171 Specify value for \$distro
172 -df, --distfiles-fetch[-request] PACKAGE
173 Send distfiles request to fetch sources for PACKAGE
174 -cf, --command-flag
175 Not yet documented
176 -c, --command
177 Executes a given command on builders
178 --test-remove-pkg
179 shortcut for --command poldek -evt ARGS
180 --remove-pkg
181 shortcut for --command poldek -ev --noask ARGS
182 --upgrade-pkg
183 shortcut for --command poldek --up -Uv ARGS
184 --cvsup
185 Updates builders infrastructure (outside chroot)
a166aeda
ER
186 --update-macros
187 Updates rpm-build-macros on src builder
23e1dcfb 188 -q
bb30a063
ER
189 shortcut for --command rpm -q ARGS
190 -g, --gpg-opts "opts"
191 Pass additional options to gpg binary
192 -p, --priority VALUE
193 sets request priority (default 2)
194 -h, --help
195 Displays this help message
23e1dcfb
ER
196EOF
197 exit 0
586a5f1f
AG
198}
199
200
1344b6f1 201while [ $# -gt 0 ] ; do
9cc9841b 202 case "$1" in
bb30a063 203 --distro | -d)
9cc9841b
ER
204 distro=$2
205 shift
206 ;;
207
bb30a063 208 --config-file | -C)
9cc9841b
ER
209 [ -f $2 ] && . $2 || die "Config file not found"
210 shift
211 ;;
212
bb30a063 213 --builder | -b)
9cc9841b
ER
214 builders="$builders $2"
215 shift
216 ;;
217
bb30a063 218 --with)
9cc9841b
ER
219 with="$with $2"
220 shift
221 ;;
222
bb30a063 223 --without)
9cc9841b
ER
224 without="$without $2"
225 shift
226 ;;
227
bb30a063 228 --test-build | -t)
9cc9841b
ER
229 build_mode=test
230 f_upgrade=no
231 ;;
232
bb30a063 233 --kernel)
9cc9841b
ER
234 kernel=$2
235 shift
236 ;;
237
be264f26
ER
238 --target)
239 target=$2
240 shift
241 ;;
242
db286098 243 -s|--skip)
897f56ee 244 skip="$2"
db286098
ER
245 shift
246 ;;
247
11270534
ER
248 --branch)
249 branch=$2
250 shift
251 ;;
252
bb30a063 253 --priority | -p)
9cc9841b
ER
254 priority=$2
255 shift
256 ;;
257
bb30a063 258 --ready-build | -r)
9cc9841b
ER
259 build_mode=ready
260 ;;
261
bb30a063 262 --upgrade | -u)
9cc9841b
ER
263 f_upgrade=yes
264 ;;
265
bb30a063 266 --no-upgrade | -n)
9cc9841b
ER
267 f_upgrade=no
268 ;;
269
218a4c96
ER
270 --no-depend | -nd)
271 no_depend=yes
272 ;;
273
bb30a063 274 --no-install-br | -ni)
9cc9841b
ER
275 flags="$flags no-install-br"
276 ;;
277
bb30a063 278 -j | --jobs)
d8f1c9c0
AM
279 jobs="$2"
280 shift
281 ;;
282
bb30a063 283 --flag | -f)
9cc9841b
ER
284 flags="$flags $2"
285 shift
286 ;;
287
bb30a063 288 --command-flags | -cf)
9cc9841b
ER
289 command_flags="$2"
290 shift
291 ;;
292
bb30a063 293 --command | -c)
9cc9841b 294 command="$2"
30ddd991 295 if [ "$command" = - ]; then
3f77765b
ER
296 echo >&2 "Reading command from STDIN"
297 echo >&2 "---"
298 command=$(cat)
299 echo >&2 "---"
300 fi
9cc9841b
ER
301 f_upgrade=no
302 shift
303 ;;
304 --test-remove-pkg)
305 command="poldek -evt $2"
306 f_upgrade=no
307 shift
308 ;;
309 --remove-pkg)
c4c115cc 310 command="for a in $2; do poldek -ev --noask \$a; done"
9cc9841b
ER
311 f_upgrade=no
312 shift
313 ;;
b098536f 314 --upgrade-pkg|-Uhv)
218a4c96 315 command="poldek --up; poldek -uv $2"
9cc9841b
ER
316 f_upgrade=no
317 shift
318 ;;
319 -q)
320 command="rpm -q $2"
321 f_upgrade=no
322 shift
323 ;;
324
bb30a063 325 --cvsup)
9cc9841b
ER
326 command_flags="no-chroot"
327 command="cvs up"
49a8a604 328 f_upgrade=no
9cc9841b
ER
329 ;;
330
a166aeda
ER
331 --update-macros)
332 upgrade_macros="yes"
333 ;;
334
45d8ed70
ER
335 -df | --distfiles-fetch | --distfiles-fetch-request)
336 df_fetch=yes
337 ;;
338
bb30a063 339 --gpg-opts | -g)
1bf4c407
TP
340 gpg_opts="$2"
341 shift
342 ;;
9cc9841b 343
bb30a063 344 --help | -h)
9cc9841b
ER
345 usage
346 ;;
347
bb30a063 348 -*)
9cc9841b
ER
349 die "unknown knob: $1"
350 ;;
351
bb30a063 352 *:* | *)
9cc9841b
ER
353 specs="$specs $1"
354 ;;
355 esac
356 shift
1344b6f1
MM
357done
358
e728b34c
ER
359case "$distro" in
360ac)
9cc9841b
ER
361 builder_email="builder-ac@pld-linux.org"
362 default_builders="ac-*"
363 default_branch="AC-branch"
8503c5d2 364 url="http://ep09.pld-linux.org:1289/"
a3387055 365 control_url="http://ep09.pld-linux.org/~buildsrc"
9cc9841b 366 ;;
3e991c55 367ac-java) # fake "distro" for java available ac architectures
e4047e17 368 builder_email="builder-ac@pld-linux.org"
9cc9841b
ER
369 default_builders="ac-i586 ac-i686 ac-athlon ac-amd64"
370 default_branch="AC-branch"
8503c5d2 371 url="http://ep09.pld-linux.org:1289/"
9cc9841b 372 ;;
70d46bca 373ac-xen) # fake "distro" for xen-enabled architectures
e4047e17
ER
374 builder_email="builder-ac@pld-linux.org"
375 default_builders="ac-i686 ac-athlon ac-amd64"
376 default_branch="AC-branch"
70d46bca 377 ;;
e728b34c 378ti)
9cc9841b
ER
379 builder_email="builderti@ep09.pld-linux.org"
380 default_builders="ti-*"
5ed6b10a
AM
381 url="http://ep09.pld-linux.org:1231/"
382 control_url="http://ep09.pld-linux.org/~builderti"
9cc9841b 383 ;;
3274da14 384ti-dev)
385 builder_email="buildertidev@ep09.pld-linux.org"
386 default_builders="ti-dev-*"
387 url="http://ep09.pld-linux.org:1232/"
388 control_url="http://ep09.pld-linux.org/~buildertidev"
389 ;;
e728b34c 390th)
f0cfd110 391 builder_email="builderth@pld-linux.org"
9cc9841b 392 default_builders="th-*"
1cd123e3 393 url="http://src.th.pld-linux.org:1234/"
f0cfd110 394 control_url="http://src.th.pld-linux.org"
9cc9841b 395 ;;
3e991c55 396th-java) # fake "distro" for java available th architectures
f0cfd110 397 builder_email="builderth@pld-linux.org"
976435cb 398 default_builders="th-x86_64 th-athlon th-i686"
1cd123e3 399 url="http://src.th.pld-linux.org:1234/"
e219518b 400 ;;
32384897 401aidath)
402 builder_email="builderaidath@ep09.pld-linux.org"
403 default_builders="aidath-*"
404 ;;
14b580de
ER
405*)
406 die "distro \`$distro' not known"
407 ;;
e728b34c
ER
408esac
409
897f56ee
ER
410# need to do this after distro selection
411if [ "$skip" ]; then
9b86ba23
ER
412 skip=$(skip="$skip" control_url="$control_url" python -c '
413import urllib2
414import sys
415import StringIO
416import gzip
417import re
418import os
419import string
420from xml.dom import minidom
421
422skip = os.environ.get("skip").split(",");
423control_url = os.environ.get("control_url")
424
425print >> sys.stderr, "* Check queue_id-s against %s" % control_url
426
427try:
428 headers = { "Cache-Control": "no-cache", "Pragma": "no-cache" }
429 req = urllib2.Request(url=control_url + "/queue.gz", headers=headers)
430 f = urllib2.urlopen(req)
431except Exception, e:
432 print >> sys.stderr, "Fetch error %s: %s" % (control_url + "/queue.gz", e)
433 sys.exit(1)
434
435sio = StringIO.StringIO()
436sio.write(f.read())
437f.close()
438sio.seek(0)
439f = gzip.GzipFile(fileobj = sio)
440
441xml = re.compile("(<queue>.*?</queue>)", re.DOTALL).match(f.read()).group(1)
442d = minidom.parseString(xml)
443
444q = []
445for c in d.documentElement.childNodes:
446 if c.nodeName != "group":
447 continue
448 q.append(c.attributes["id"].value)
449
450err = 0
451for s in skip:
452 if s not in q:
453 print >> sys.stderr, "- Check %s: ERROR: Not valid queue-id" % s
454 err = 1
455 else:
456 print >> sys.stderr, "- Check %s: OK" % s
457if err == 1:
458 sys.exit(1)
459print string.join(skip, ",")
460') || exit $?
897f56ee
ER
461 f_upgrade=no
462 build_mode=test
463 priority=-1
464 command="skip:$skip"
465 command_flags="no-chroot"
466 builders="$distro-src"
467fi
468
11270534
ER
469branch=${branch:-$default_branch}
470
e728b34c 471specs=`for s in $specs; do
9cc9841b 472 case "$s" in
218a4c96
ER
473 ^)
474 # skip marker
475 echo $s
476 ;;
9cc9841b 477 *.spec:*) # spec with branch
b3d9fd17 478 basename $s
9cc9841b
ER
479 ;;
480 *.spec) # spec without branch
b3d9fd17 481 echo $(basename $s):$branch
9cc9841b
ER
482 ;;
483 *:*) # package name with branch
b3d9fd17 484 basename $s | sed -e 's/:/.spec:/'
9cc9841b
ER
485 ;;
486 *) # just package name
b3d9fd17 487 echo $(basename $s).spec:$branch
9cc9841b
ER
488 ;;
489 esac
878677a8 490done`
1344b6f1 491
45d8ed70
ER
492if [ "$df_fetch" = "yes" ]; then
493 df_fetch $specs
494 exit 0
495fi
496
a166aeda 497if [ "$upgrade_macros" = "yes" ]; then
218a4c96 498 command="poldek --up; poldek -uv rpm-build-macros"
a166aeda
ER
499 builders="$distro-src"
500 f_upgrade=no
501 build_mode=test
502fi
503
2f470d17 504if [[ "$requester" != *@* ]] ; then
b3d9fd17 505 requester="$requester@pld-linux.org"
2f470d17
MK
506fi
507
14b580de 508if [ -z "$builders" ] ; then
9cc9841b 509 builders="$default_builders"
a757e911
MM
510fi
511
544ca060 512if [ "$f_upgrade" = "yes" ] ; then
9cc9841b 513 flags="$flags upgrade"
a757e911
MM
514fi
515
e936beda 516if [ "$build_mode" = "test" ] ; then
9cc9841b
ER
517 if [ "$f_upgrade" = "yes" ] ; then
518 die "--upgrade and --test-build are mutually exclusive"
519 fi
520 flags="$flags test-build"
e936beda
MM
521fi
522
e728b34c
ER
523if [ -z "$build_mode" ] ; then
524 # missing build mode, builders go crazy when you proceed"
525 die "please specify build mode"
526fi
527
528
280b1afd 529ok=
e728b34c
ER
530for s in $specs; do
531 ok=1
280b1afd
MM
532done
533
d80e53cf
ER
534if [ -z "$specs" -a -z "$command" ]; then
535 die "no packages to build or command to invoke specified"
280b1afd
MM
536fi
537
1344b6f1
MM
538id=$(uuidgen)
539
540gen_req() {
9cc9841b
ER
541 echo "<group id='$id' no='0' flags='$flags'>"
542 echo " <time>$(date +%s)</time>"
f147040c 543 echo >&2 "* Using priority $priority"
9cc9841b 544 echo " <priority>$priority</priority>"
d8f1c9c0 545 if [ -n "$jobs" ]; then
f147040c 546 echo >&2 "* Using jobs $jobs"
d8f1c9c0
AM
547 echo " <maxjobs>$jobs</maxjobs>"
548 fi
f147040c 549 echo >&2 "* Build mode: $build_mode"
fe7aaa44
ER
550 if [ -z "$url" ]; then
551 echo >&2 "* Using email $builder_email"
552 else
553 echo >&2 "* Using URL $url"
554 fi
f147040c 555 echo >&2 "* Queue-ID: $id"
9cc9841b
ER
556 echo
557
d80e53cf
ER
558 # job to depend on
559 local depend=
560 local b i=1
561 local name branch builders_xml
562
563 for b in $builders; do
564 echo >&2 "* Builder: $b"
565 builders_xml="$builders_xml <builder>$b</builder>"
566 done
567
568 if [ "$command" ]; then
9cc9841b 569 bid=$(uuidgen)
e6aa37ec 570 echo -E >&2 "* Command: $command"
9cc9841b 571 echo " <batch id='$bid' depends-on=''>"
30ddd991
ER
572 echo " <command flags='$command_flags'>"
573 echo -E "$command" | sed -e 's,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g'
574 echo "</command>"
9cc9841b 575 echo " <info></info>"
d80e53cf 576 echo "$builders_xml"
9cc9841b 577 echo " </batch>"
d80e53cf
ER
578 depend=$bid
579 fi
9cc9841b 580
f147040c
AM
581 if [ "$f_upgrade" = "yes" ] ; then
582 echo >&2 "* Upgrade mode: $f_upgrade"
583 fi
e728b34c 584
f147040c 585 for s in $specs; do
218a4c96 586 # skip marker
d80e53cf 587 if [ "$s" = "^" ]; then
218a4c96
ER
588 depend=
589 continue
590 fi
d80e53cf
ER
591 if [ "$no_depend" = yes ]; then
592 depend=
593 fi
f147040c 594 bid=$(uuidgen)
218a4c96
ER
595 echo " <batch id='$bid' depends-on='$depend'>"
596
f147040c
AM
597 name=$(echo "$s" | sed -e 's|:.*||')
598 branch=$(echo "$s" | sed -e 's|.*:||')
218a4c96 599 echo >&2 "* Adding #$i $name:$branch${kernel:+ alt_kernel=$kernel}${target:+ target=$target}${depend:+ depends on $depend}"
f147040c
AM
600 echo " <spec>$name</spec>"
601 echo " <branch>$branch</branch>"
602 echo " ${kernel:+<kernel>$kernel</kernel>}"
603 echo " ${target:+<target>$target</target>}"
604 echo " <info></info>"
605 echo
606 for b in $with; do
607 echo " <with>$b</with>"
608 done
609 for b in $without; do
610 echo " <without>$b</without>"
611 done
612 echo
d80e53cf 613 echo "$builders_xml"
f147040c
AM
614 echo " </batch>"
615 i=$((i+1))
c4aa0539 616
218a4c96
ER
617 # let next job depend on previous
618 depend=$bid
619 done
e728b34c 620
9cc9841b 621 echo "</group>"
1344b6f1
MM
622}
623
624gen_email () {
e728b34c
ER
625 # make request first, so the STDERR/STDOUT streams won't be mixed
626 local req=$(gen_req)
627
1344b6f1 628cat <<EOF
2f470d17 629From: $requester
1344b6f1
MM
630To: $builder_email
631Subject: build request
632Message-Id: <$id@$(hostname)>
633X-New-PLD-Builder: request
2d28916b 634X-Requester-Version: \$Id$
1344b6f1 635
30ddd991 636$(echo -E "$req" | gpg --clearsign --default-key $default_key $gpg_opts)
1344b6f1
MM
637EOF
638}
639
bfa10c0d 640gen_email | send_request
This page took 0.171287 seconds and 4 git commands to generate.