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