@@ -26,11 +26,18 @@ repodir=$(mktemp -d)
2626trap ' rm -r "$repodir"' EXIT
2727cat > " $repodir /template.repo"
2828
29+ DNF5=false
30+ if [ " $( readlink /usr/bin/dnf) " = " dnf5" ]; then
31+ DNF5=true
32+ fi
33+
2934OPTS+=(-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
3542if ! 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"
4956RET=0
5057
5158if [ " $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=" $? "
5465elif [ " $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