Skip to content

Commit bc8476f

Browse files
committed
Fix DNF5 repoquery
related: QubesOS/qubes-core-admin-client#308
1 parent 468e15f commit bc8476f

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

qubes-rpc/qvm-template-repo-query

100755100644
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ repodir=$(mktemp -d)
2626
trap 'rm -r "$repodir"' EXIT
2727
cat > "$repodir/template.repo"
2828

29+
DNF5=false
30+
if [ "$(readlink /usr/bin/dnf)" = "dnf5" ]; then
31+
DNF5=true
32+
fi
33+
2934
OPTS+=(-y "--setopt=reposdir=${repodir}" --quiet)
3035

31-
# use vendored 'downloadurl' dnf-plugin (fork of 'download' plugin), to print
32-
# all mirrors
33-
OPTS+=("--setopt=pluginpath=/usr/lib/qubes/dnf-plugins")
36+
if ! $DNF5; then
37+
# use vendored 'downloadurl' dnf-plugin (fork of 'download' plugin), to print
38+
# all mirrors
39+
OPTS+=("--setopt=pluginpath=/usr/lib/qubes/dnf-plugins")
40+
fi
3441

3542
if ! command -v dnf >/dev/null; then
3643
echo "ERROR: dnf command is missing, please use newer template for your UpdateVM to download templates." >&2
@@ -49,16 +56,38 @@ touch -r "$hashfile" "$repodir/template.repo"
4956
RET=0
5057

5158
if [ "$1" = "query" ]; then
52-
dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{reponame}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|' "$SPEC"
59+
if $DNF5; then
60+
dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{repoid}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|\n' "$SPEC"
61+
else
62+
dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{repoid}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|' "$SPEC"
63+
fi
5364
RET="$?"
5465
elif [ "$1" = "download" ]; then
5566
# Download/retry algorithm: take mirrors in random order. In this order,
5667
# try to download from the first one - if download failed but anything was
5768
# downloaded - retry from the same one. If download failed and nothing was
5869
# downloaded, go to the next one. The intention is to retry on interrupted
5970
# connection, but skip mirrors that are not synchronized yet.
60-
urls="$(dnf downloadurl "${OPTS[@]}" --url --all-mirrors "$SPEC" | shuf)"
61-
readarray -t urls <<<"$urls"
71+
declare -a urls=()
72+
if $DNF5 && dnf download --help | grep -q allmirrors; then
73+
# The smartest case. DNF5 on Fedora 41 with --allmirrors patch
74+
urls="$(dnf download "${OPTS[@]}" --url --allmirrors "$SPEC")"
75+
readarray -d ' ' -t urls <<<"$urls"
76+
urls=( $(shuf -e "${urls[@]}") )
77+
elif $DNF5; then
78+
# The middle case. DNF5 on Fedora 41 before --allmirror patch
79+
# TODO: Phase out after DNF5 --allmirrors patch is released
80+
url="$(dnf download "${OPTS[@]}" --url "$SPEC")"
81+
urls+=($url)
82+
else
83+
# The old DNF4 on Fedora 40 and other old templates
84+
# use vendored 'downloadurl' dnf-plugin (fork of 'download' plugin),
85+
# to print all mirrors.
86+
# TODO: Phase out after DNF4 is EOL
87+
OPTS+=("--setopt=pluginpath=/usr/lib/qubes/dnf-plugins")
88+
urls="$(dnf downloadurl "${OPTS[@]}" --url --all-mirrors "$SPEC" | shuf)"
89+
readarray -t urls <<<"$urls"
90+
fi
6291
downloaded=0
6392
status_file="$repodir/download-status.tmp"
6493
for url in "${urls[@]}"; do

0 commit comments

Comments
 (0)