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