-
Notifications
You must be signed in to change notification settings - Fork 8
/
mtps-get-task
executable file
·795 lines (728 loc) · 21.9 KB
/
mtps-get-task
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
#!/usr/bin/bash -efu
shopt -s extglob
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2018, 2023
# Author: Andrei Stepanov <[email protected]>
# Source `mtps-setup' from $PATH
if command -v "mtps-setup" >/dev/null; then source "mtps-setup"; fi
# If previous fails source `mtps-setup` from this script dir
if [ -z "${YUMDNFCMD:-}" ]; then source "$(dirname "${BASH_SOURCE[0]}")/mtps-setup" || ( echo "Cannot source mtps-setup" >&2; exit 91 ); fi
RET_NO_RPMS_IN_BREW=7
RET_NO_RPMS_IN_REPOS=8
RET_EMPTY_REPOQUERY=11
task_result2rpms() {
local arch="$1" && shift
local xml="$1" && shift
local tmpfile
tmpfile="$(mktemp)"
echo "$xml" > "$tmpfile"
local cmd="cat //member[name='rpms']//value/string/text()"
local rpms
rpms="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p' | sed -n -e "/\.$arch\.rpm/p")"
# e.g. tasks/7171/57387171/libcap-static-2.48-9.el9_0.x86_64.rpm. Don't strip the prefix off here, we need it.
debug "$arch rpms:\n${rpms}\n---"
echo "$rpms"
}
task_result2srpm() {
local xml="$1" && shift
local tmpfile
tmpfile="$(mktemp)"
echo "$xml" > "$tmpfile"
local cmd="cat //member[name='srpms']//value/string/text()"
local srpm
srpm="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p' | sed -n -e "/\.rpm/p")"
# e.g. tasks/3126/110193126/keyutils-1.6.3-1.fc40.src.rpm. Don't strip the prefix off here, we need it.
debug "srpm: ${srpm}\n---"
echo "$srpm"
}
task_request2is_scratch() {
local xml="$1" && shift
local is_scratch
is_scratch="$(echo "$xml" | xmllint --xpath 'string(//member[name="scratch"]/value/boolean/text())' -)"
[[ "$is_scratch" == '1' ]] && is_scratch="yes" || is_scratch="no"
debug "Is scratch: $is_scratch"
echo "$is_scratch"
}
build2volume_name() {
local xml="$1" && shift
local volume_name
volume_name="$(echo "$xml" | xmllint --xpath 'string(//member[name="volume_name"]/value/string/text())' -)"
debug "Volume name: $volume_name"
echo "$volume_name"
}
build2build_source() {
local xml="$1" && shift
local build_source
build_source="$(echo "$xml" | xmllint --xpath 'string(//member[name="source"]/value/string/text())' -)"
debug "Build source: $build_source"
echo "$build_source"
}
builds2nvr() {
local xml="$1" && shift
local nvr
nvr="$(echo "$xml" | xmllint --xpath 'string(//member[name="nvr"]/value/string/text())' -)"
debug "NVR: $nvr"
echo "$nvr"
}
builds2build_id() {
local xml="$1" && shift
local buildid
buildid="$(echo "$xml" | xmllint --xpath 'string(//member[name="build_id"]/value/int/text())' -)"
debug "build id: $buildid"
echo "$buildid"
}
buildtags_from_answer() {
local xml="$1" && shift
local tmpfile
tmpfile="$(mktemp)"
echo "$xml" > "$tmpfile"
local cmd="cat //member[name='name']/value/string/text()"
local tags
tags="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')"
debug "Build tags:\n${tags}\n---"
echo "$tags"
}
children_from_answer() {
local xml="$1" && shift
local tmpfile
tmpfile="$(mktemp)"
echo "$xml" > "$tmpfile"
local cmd="cat //member[name='id']/value/int/text()"
local children
children="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')"
debug "Task children:\n${children}\n---"
echo "$children"
}
send_query() {
local query="$1" && shift
local answer
answer="$(curl --silent -k --data "$query" "$BREWHUB")"
debug "Brew answer: ${answer:0:200}...(truncated)"
echo "$answer"
}
# Use:
#
# 'koji list-api' to get a list of available XMLRPC.
# 'brew --debug-xmlrpc' to get XML
#
brew_get_build() {
# getBuild query
# Build can be: NVR or build number.
local build="$1" && shift
local query="$(cat << EOF
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>getBuild</methodName>
<params>
<value>$build</value>
<param>
</param>
</params>
</methodCall>
EOF
)"
debug "Brew query for listBuildRPMs: ${query:0:200}...(truncated)"
send_query "$query"
}
brew_list_build_tags() {
# listTags query
# Build can be: build number.
local build="$1" && shift
local query="$(cat << EOF
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>listTags</methodName>
<params>
<param>
<value><int>$build</int></value>
</param>
</params>
</methodCall>
EOF
)"
debug "Brew query for listTags: ${query:0:200}...(truncated)"
send_query "$query"
}
brew_list_builds() {
# listBuilds query
local task="$1" && shift
local query="$(cat << EOF
<?xml version='1.0'?>
<methodCall>
<methodName>listBuilds</methodName>
<params>
<param>
<value><struct>
<member>
<name>__starstar</name>
<value><boolean>1</boolean></value>
</member>
<member>
<name>taskID</name>
<value><int>$task</int></value>
</member>
</struct></value>
</param>
</params>
</methodCall>
EOF
)"
debug "Brew query for listBuilds: ${query:0:200}...(truncated)"
send_query "$query"
}
brew_get_task_result() {
# getTaskResult query
# Build can be: NVR or build number.
local task="$1" && shift
local query="$(cat << EOF
<?xml version='1.0'?>
<methodCall>
<methodName>getTaskResult</methodName>
<params>
<param>
<value><int>$task</int></value>
</param>
</params>
</methodCall>
EOF
)"
debug "Brew query for getTaskResult: ${query:0:200}...(truncated)"
send_query "$query"
}
brew_get_user() {
# getUser query
local user_id="$1" && shift
local query="$(cat << EOF
<?xml version='1.0'?>
<methodCall>
<methodName>getUser</methodName>
<params>
<param>
<value><int>$user_id</int></value>
</param>
</params>
</methodCall>
EOF
)"
debug "Brew query for getUser: ${query:0:200}...(truncated)"
send_query "$query"
}
brew_get_task_info() {
# getTaskInfo query
local task="$1" && shift
local query="$(cat << EOF
<?xml version='1.0'?>
<methodCall>
<methodName>getTaskInfo</methodName>
<params>
<param>
<value><int>$task</int></value>
</param>
</params>
</methodCall>
EOF
)"
debug "Brew query for getTaskInfo: ${query:0:200}...(truncated)"
send_query "$query"
}
brew_get_task_request() {
# getTaskRequest query
local task="$1" && shift
local query="$(cat << EOF
<?xml version='1.0'?>
<methodCall>
<methodName>getTaskRequest</methodName>
<params>
<param>
<value><int>$task</int></value>
</param>
</params>
</methodCall>
EOF
)"
debug "Brew query for getTaskRequest: ${query:0:200}...(truncated)"
send_query "$query"
}
taskinfo2owner() {
local xml="$1" && shift
local tmpfile
tmpfile="$(mktemp)"
echo "$xml" > "$tmpfile"
local cmd="cat //member[name='owner']/value/int/text()"
local owner
owner="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')"
debug "Task owner id:\n${owner}\n---"
echo "$owner"
}
task_request2target() {
local xml="$1" && shift
local tmpfile
tmpfile="$(mktemp)"
echo "$xml" > "$tmpfile"
local cmd="cat //params/param[1]/value/array/data[1]/value[2]/string/text()"
local target
target="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')"
debug "Task target:\n${target}\n---"
echo "$target"
}
ownerinfo2user() {
local xml="$1" && shift
local tmpfile
tmpfile="$(mktemp)"
echo "$xml" > "$tmpfile"
local cmd="cat //member[name='name']/value/string/text()"
local owner
owner="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')"
debug "Task owner name:\n${owner}\n---"
echo "$owner"
}
ownerinfo2krb() {
local xml="$1" && shift
local tmpfile
tmpfile="$(mktemp)"
echo "$xml" > "$tmpfile"
local cmd="cat //member[name='krb_principal']/value/string/text()"
local email
email="$(echo "$cmd" | xmllint --shell "$tmpfile" | sed -n -e '/^[[:alnum:]]/p')"
debug "Task owner email:\n${email}\n---"
echo "$email"
}
brew_get_task_children() {
# getTaskChildren query
# Build can be: NVR or build number.
local task="$1" && shift
local query="$(cat << EOF
<?xml version='1.0'?>
<methodCall>
<methodName>getTaskChildren</methodName>
<params>
<param>
<value><int>$task</int></value>
</param>
</params>
</methodCall>
EOF
)"
debug "Brew query for getTaskChildren: ${query:0:200}...(truncated)"
send_query "$query"
}
mk_repo() {
local task_id="$1" && shift
local repo_dir="$1" && shift
local repo_enabled="${1:0}" && shift
repo_dir="${repo_dir##/}"
repo_dir="${repo_dir%%/}"
local repo="$(cat << EOF
[brew-${task_id}]
name=Repo for $task_id Brew build
baseurl=file:///${repo_dir}/
enabled=$repo_enabled
gpgcheck=0
EOF
)"
debug "Repo file text: ${repo:0:200}...(truncated)"
echo "$repo"
}
mk_named_repo() {
local repo_name="$1" && shift
local repo_dir="$1" && shift
local repo_enabled="${1:0}" && shift
repo_dir="${repo_dir##/}"
repo_dir="${repo_dir%%/}"
local repo="$(cat << EOF
[${repo_name}]
name=Repo for $repo_name
baseurl=file:///${repo_dir}/
enabled=$repo_enabled
gpgcheck=0
module_hotfixes=1
EOF
)"
debug "Repo file text: ${repo:0:200}...(truncated)"
echo "$repo"
}
msg_usage() {
cat << EOF
Get RPM for Brew task.
Usage:
$PROG <options>
Options:
-a, --arch=ARCH download for specified ARCH
-r, --recursive download also from child tasks
-c, --createrepo create a repo metadata at REPODIR
-t, --task=TASKID Task ID
-i, --installrepofile add to this system a .repo file for REPODIR
-d, --download=REPODIR download RPM to REPODIR
-s, --srpm print only SRPM information, URL, pkgname
--onlyinrepo do not download RPMs that are absent in official repos
--repofilename used as /etc/yum.repos.d/REPOFILENAME.repo
--owner print only owner information
-h, --help display this help and exit
-v, --verbose turn on debug
EOF
}
from_rpm_name() {
# Input: 1:bar-9-123a.ia64.rpm or foo-1.0-1.i386
# Mimic splitFilename() from https://github.com/rpm-software-management/yum/blob/master/rpmUtils/miscutils.py
local filename="$1" && shift
# One of: name, ver, rel, epoch, arch
local req_info="$1" && shift
# Drop .rpm
filename="${filename%%.rpm}"
# Arch
local arch="${filename##*.}"
debug "${filename} arch: ${arch}"
[[ $req_info == 'arch' ]] && echo "$arch" && return
# Release
local rel="${filename##*-}"
rel="${rel%.*}"
debug "${filename} rel: ${rel}"
[[ $req_info == 'rel' ]] && echo "$rel" && return
# Version
local ver="${filename%-${rel}.${arch}}"
ver="${ver##*-}"
debug "${filename} ver: ${ver}"
[[ $req_info == 'ver' ]] && echo "$ver" && return
# Name
local epoch_name="${filename%-${ver}-${rel}.${arch}}"
name="${epoch_name##*:}"
debug "${filename} name: ${name}"
[[ $req_info == 'name' ]] && echo "$name" && return
# Epoch
local epoch="${epoch_name%${name}}"
epoch="${epoch//:/}"
debug "${filename} epoch: ${epoch:-none}"
[[ $req_info == 'epoch' ]] && echo "$epoch" && return
}
filter_available() {
local arch="$1" && shift
local rpms="$1" && shift
local rpms_filtered=
local name=
for rpm in $rpms; do
rpm_file="$(basename "$rpm")"
name="$(from_rpm_name "${rpm_file}" "name")"
"$YUMDNFCMD" info "${name}.${arch}" >/dev/null 2>&1
ret="$?"
if [ "$ret" -ne 0 ]; then
echo "Skipping as it is absent in shipped repos: $name" >&2
continue
fi
rpms_filtered="${rpms_filtered:+$rpms_filtered }${rpm}"
done
echo "$rpms_filtered"
}
download_rpm() {
local url="$1" && shift
if [ -z "$DOWNLOAD" ]; then
return
fi
mkdir -p "$REPODIR"
REPODIR="$(realpath "$REPODIR")"
pushd "$REPODIR" > /dev/null
curl --retry 5 --insecure --fail --location --show-error --remote-name --remote-header-name "$url"
popd > /dev/null
}
mk_url() {
local filename="$1" && shift
local srpm_filename="$1" && shift
local is_scratch="$1" && shift
if [ "$is_scratch" == "no" ]; then
# https://download.devel.redhat.com/brewroot/packages/curl/7.61.1/34.el8/x86_64/curl-7.61.1-34.el8.x86_64.rpm
# https://kojipkgs.fedoraproject.org//packages/packit/0.87.1/1.fc40/src/packit-0.87.1-1.fc40.src.rpm
filename=$(basename "$filename")
srpm_filename=$(basename "$srpm_filename")
name="$(from_rpm_name "${srpm_filename}" "name")"
rel="$(from_rpm_name "${srpm_filename}" "rel")"
ver="$(from_rpm_name "${srpm_filename}" "ver")"
arch="$(from_rpm_name "${filename}" "arch")"
url="${BREWROOT}/packages/${srpm_pkg_name}/${ver}/${rel}/${arch}/$filename"
else
# https://download.devel.redhat.com/brewroot/work/tasks/237/57520237/curl-7.61.1-34.el8.x86_64.rpm
# https://kojipkgs.fedoraproject.org//work/tasks/9873/109769873/packit-0.87.1-1.fc40.src.rpm
url="${BREWROOT}/work/${filename}"
fi
debug "URL for ${filename}: ${url}"
echo "$url"
}
# Entry
: "${PROG:=${0##*/}}"
: "${ARCH:=$(uname -m)}"
: "${DEBUG:=}"
: "${TASK:=}"
: "${SRPM:=}"
: "${OWNER:=}"
: "${REPOFILENAME:=}"
: "${REPODIR:=repodir}"
: "${BREWHUB:=https://brewhub.engineering.redhat.com/brewhub}"
: "${DOWNLOAD:=}"
: "${BREWROOT:=https://download.devel.redhat.com/brewroot}"
: "${RECURSIVE:=}"
: "${CREATEREPO:=}"
: "${ONLYINREPO:=}"
: "${CREATEREPO_BIN:=}"
: "${INSTALLREPOFILE:=}"
#opt_str="$@"
opt=$(getopt -n "$0" --options "hvrd:t:a:cis" --longoptions "help,verbose,repofilename:,download:,task:,arch:,createrepo,installrepofile,onlyinrepo,owner,recursive,srpm" -- "$@")
eval set -- "$opt"
while [[ $# -gt 0 ]]; do
case "$1" in
-t|--task)
TASK="$2"
shift 2
;;
-a|--arch)
ARCH="$2"
shift 2
;;
-d|--download)
DOWNLOAD="yes"
REPODIR="$2"
shift 2
;;
-c|--createrepo)
CREATEREPO="yes"
shift
;;
-s|--srpm)
SRPM="yes"
shift
;;
--owner)
OWNER="yes"
shift
;;
-r|--recursive)
RECURSIVE="yes"
shift
;;
--onlyinrepo)
ONLYINREPO="yes"
shift
;;
-i|--installrepofile)
INSTALLREPOFILE="yes"
shift
;;
--repofilename)
REPOFILENAME="$2"
shift 2
;;
-v|--verbose)
DEBUG="yes"
shift
;;
-h|--help)
msg_usage
exit 0
;;
--)
shift
;;
*)
msg_usage
exit 1
esac
done
# Test correct invocation
if [ -z "$TASK" ]; then
echo "Use: $PROG -h for help."
exit
fi
mkdir -p "${LOGS_DIR:=mtps-logs}"
LOGS_DIR="$(realpath "$LOGS_DIR")"
while true; do
TESTRUN_ID="$(date +%H%M%S)"
logfname="${LOGS_DIR%%/}/${TESTRUN_ID}-${TASK}-mtps-get-task.log"
logfname_skip="$(dirname "$logfname")/SKIP-$(basename "$logfname")"
logfname_pass="$(dirname "$logfname")/PASS-$(basename "$logfname")"
logfname_fail="$(dirname "$logfname")/FAIL-$(basename "$logfname")"
logfname_warn="$(dirname "$logfname")/WARN-$(basename "$logfname")"
if [[ -e "$logfname" || -e "$logfname_pass" || -e "$logfname_fail" ]]; then
sleep 1
continue
fi
break
done
exec &> >(tee -a "$logfname")
exec 2>&1
do_clean_exit() {
rc=$?
trap - SIGINT SIGTERM SIGABRT EXIT # clear the trap
new_logfname="$logfname_fail"
if [[ "$rc" -eq 0 ]]; then
new_logfname="$logfname_pass"
elif [[ "$rc" -eq $RET_NO_RPMS_IN_BREW ]]; then
new_logfname="$logfname_skip"
elif [[ "$rc" -eq $RET_NO_RPMS_IN_REPOS || "$rc" -eq $RET_EMPTY_REPOQUERY ]]; then
new_logfname="$logfname_warn"
fi
# Close tee pipes
for pid in $(ps -o pid --no-headers --ppid $$); do
if [ -n "$(ps -p $pid -o pid=)" ]; then
kill -s HUP $pid
fi
done
mv -f "$logfname" "$new_logfname"
exit $rc
}
trap do_clean_exit SIGINT SIGTERM SIGABRT EXIT
debug "Task: $TASK"
debug "Arch: $ARCH"
debug "Srpm: $SRPM"
debug "Owner: $OWNER"
debug "Store RPMS at: ${REPODIR}"
debug "Create repo: ${CREATEREPO:-no}"
debug "Download recursively from children tasks: ${RECURSIVE:-no}"
task_info="$(brew_get_task_info "$TASK")"
task_owner_id="$(taskinfo2owner "$task_info")"
owner_info="$(brew_get_user "$task_owner_id")"
task_request="$(brew_get_task_request "$TASK")"
is_scratch="$(task_request2is_scratch "$task_request")"
echo "Owner user: $(ownerinfo2user "$owner_info")"
echo "Owner krb: $(ownerinfo2krb "$owner_info")"
echo "Task target: $(task_request2target "$task_request")"
echo "Is scratch build: $is_scratch"
if [ -n "$OWNER" ]; then
# Print only owner information
exit 0
fi
# Works only for parent task
listbuilds="$(brew_list_builds "$TASK")"
nvr="$(builds2nvr "$listbuilds")"
buildid="$(builds2build_id "$listbuilds")"
listbuildtags="$(brew_list_build_tags "$buildid")"
buildtags="$(buildtags_from_answer "$listbuildtags")"
buildtags="$(echo "$buildtags" | tr '\n' ' ')"
buildtags="${buildtags%% }"
TASKS="$TASK"
if [ -n "$RECURSIVE" ]; then
task_children="$(brew_get_task_children "$TASK")"
task_children="$(children_from_answer "$task_children")"
TASKS="$TASKS $task_children"
TASKS="${TASKS%% }"
fi
srpm_url=
volume_name=
build_source=
srpm_pkg_file=
srpm_pkg_name=
rpms_from_task_all=""
rpms_from_task_noarch_all=""
for task in $TASKS; do
debug "Process task: $task"
task_result="$(brew_get_task_result "$task")" # Holds plain XML
rpms_from_task="$(task_result2rpms "$ARCH" "$task_result")"
rpms_from_task_noarch="$(task_result2rpms "noarch" "$task_result")"
srpm="$(task_result2srpm "$task_result")"
if [ -n "$srpm" ]; then
srpm_pkg_file="$(basename "$srpm")"
srpm_pkg_name="$(from_rpm_name "${srpm_pkg_file}" "name")"
if [ -z "$nvr" ]; then
nvr="${srpm_pkg_file%%.src.rpm}"
fi
build="$(brew_get_build "$nvr")"
volume_name="$(build2volume_name "$build")"
build_source="$(build2build_source "$build")"
srpm_url="$(mk_url "$srpm" "$srpm_pkg_file" "$is_scratch")"
fi
rpms_from_task_all+=" $rpms_from_task"
rpms_from_task_noarch_all+=" $rpms_from_task_noarch"
done
# remove trailing whitespaces
rpms_from_task_all="${rpms_from_task_all%%+( )}"
rpms_from_task_noarch_all="${rpms_from_task_noarch_all%%+( )}"
echo "NVR: $nvr"
echo "BUILD ID: $buildid"
echo "BUILD TAGS: $buildtags"
echo "SRPM PKG NAME: $srpm_pkg_name"
echo "SRPM PKG FILE: $srpm_pkg_file"
echo "SRPM URL: $srpm_url"
echo "BUILD SOURCE: $build_source"
if [ -n "$SRPM" ]; then
# Print only SRPM information
exit 0
fi
if [ -z "${rpms_from_task_all}${rpms_from_task_noarch_all}" ]; then
echo "There are no ${ARCH}/noarch RPMs for Brew/Koji task ${TASK}"
exit "$RET_NO_RPMS_IN_BREW"
fi
if [ -n "$ONLYINREPO" ]; then
# Purpose:
#
# * Brew builds always have 1 input SRPM.
# * Brew builds can have many RPMs.
#
# RCM team can choose only some RPM. And make AppStream / BaseOS / Compose
# only from some RPMs, ignoring other RPMs from Brew build. This options
# says to ignore RPMs that are absent.
rpms_from_task_all="$(filter_available "$ARCH" "$rpms_from_task_all")"
rpms_from_task_noarch_all="$(filter_available "noarch" "$rpms_from_task_noarch_all")"
fi
if [ -z "${rpms_from_task_all}${rpms_from_task_noarch_all}" ]; then
# all packages have been filtered out above
echo "None of the packages is available in repos. Is it a new package?"
exit "$RET_NO_RPMS_IN_REPOS"
fi
declare -A urls # associative array (dictionary, map)
for pkg in $rpms_from_task_all $rpms_from_task_noarch_all; do
url="$(mk_url "$pkg" "$srpm_pkg_file" "$is_scratch")"
urls["$url"]=1 # in order to deduplicate, store url as key, value is unimportant
done
# Iterate over keys
for url in "${!urls[@]}"; do
echo "$url"
download_rpm "$url"
done
if [[ -z "$CREATEREPO" || ! -d "$REPODIR" ]]; then
echo "Not creating repo"
exit 0
fi
which 'createrepo' >/dev/null 2>&1 && CREATEREPO_BIN="createrepo" || :
which 'createrepo_c' >/dev/null 2>&1 && CREATEREPO_BIN="createrepo_c" || :
if [ -z "$CREATEREPO_BIN" ]; then
echo "Install createrepo[_c] to create repositories."
exit 1
fi
echo "Using $CREATEREPO_BIN"
"$CREATEREPO_BIN" --database "$REPODIR"
if [ -n "$REPOFILENAME" ]; then
repo_file_text="$(mk_named_repo "$REPOFILENAME" "$REPODIR" "1")"
repo_name="$REPOFILENAME"
else
repo_file_text="$(mk_repo "$TASK" "$REPODIR" "1")"
repo_name="brew-${TASK}"
fi
id="$(id -u)"
if [[ -n "$INSTALLREPOFILE" && "$id" -eq 0 ]]; then
repofile="/etc/yum.repos.d/${repo_name}.repo"
echo "Creating repo file: $repofile"
echo "$repo_file_text" > "$repofile"
fi
echo "Repo file content:"
echo "$repo_file_text"
# Query packages in the created repo
nevras_in_repo="$(
repoquery --repoid="$repo_name" --all \
--qf "%{repoid} %{name}-%{epoch}:%{version}-%{release}.%{arch}" 2>&1 | \
sed -n -e "/^${repo_name}[[:space:]]/ s/^${repo_name}[[:space:]]//p"
)"
# Exclude SRPMs
nevras_in_repo="$(echo "$nevras_in_repo" | sed -n -e "/\.src$/d;p")"
if [ -z "${nevras_in_repo// /}" ]; then
# Yum/dnf thinks there are no packages in the testing repo.
# This usually happens when the packages are filtered out
# because they (different version-release) are included
# in an (enabled) module.
exit "$RET_EMPTY_REPOQUERY"
fi