qubes.Template*: Add --refresh option and allow DNF cache to be used.

This commit is contained in:
WillyPillow 2020-07-29 19:46:18 +08:00
parent 9bedf50786
commit b0edd5f209

View File

@ -10,7 +10,8 @@ while IFS= read -r line; do
--enablerepo=*|\ --enablerepo=*|\
--disablerepo=*|\ --disablerepo=*|\
--repoid=*|\ --repoid=*|\
--releasever=*) --releasever=*|\
--refresh)
OPTS+=("$line") OPTS+=("$line")
;; ;;
*) *)
@ -25,13 +26,22 @@ cat > "$repodir/template.repo"
OPTS+=("--setopt=reposdir=${repodir}") OPTS+=("--setopt=reposdir=${repodir}")
OPTS+=("--quiet") OPTS+=("--quiet")
# This creates the hashfile if it doesn't exist, and keep the ctime and mtime
# unchanged otherwise.
# We then copy the {c,m}time to the repo config.
# This allows DNF caching to work properly.
hashfile="/tmp/qvm-template-$(b2sum "$repodir/template.repo" | cut -f1 -d' ')"
touch -a "$hashfile"
touch -r "$hashfile" "$repodir/template.repo"
RET=0 RET=0
if [ "$1" = "query" ]; then if [ "$1" = "query" ]; then
dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{reponame}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|' "$SPEC" dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{reponame}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|' "$SPEC"
RET="$?" RET="$?"
elif [ "$1" = "download" ]; then elif [ "$1" = "download" ]; then
curl --silent -L "$(dnf download "${OPTS[@]}" --url "$SPEC" | shuf -n 1)" -o - url="$(dnf download "${OPTS[@]}" --url "$SPEC" | shuf -n 1)"
curl --silent -L "$url" -o -
RET="$?" RET="$?"
fi fi