dom0-updates: restructure the script to not update metadata twice

When `qubes-dom0-update --refresh` was called, the script checked
metadata twice - once to check updates availability, then to actually
download them. This two stage approach is needed only on Debian, when
--downloadonly option is not supported. Rearrange code accordingly.

Also, drop --doit option (ignore it), as the same (but more readable)
can be achieved with --check-only.
This commit is contained in:
Marek Marczykowski-Górecki 2017-05-20 03:49:13 +02:00
parent 22e261f909
commit dc8047c3bb
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -2,7 +2,6 @@
DOM0_UPDATES_DIR=/var/lib/qubes/dom0-updates
DOIT=0
GUI=1
CLEAN=0
CHECK_ONLY=0
@ -17,7 +16,7 @@ export LC_ALL=C
while [ -n "$1" ]; do
case "$1" in
--doit)
DOIT=1
# ignore
;;
--nogui)
GUI=0
@ -80,45 +79,30 @@ if [ "$CLEAN" = "1" ]; then
rm -rf $DOM0_UPDATES_DIR/var/cache/yum/*
fi
if [ "x$PKGLIST" = "x" ]; then
# just check for updates, but don't download any package
if [ "x$PKGLIST" = "x" -a "$CHECK_ONLY" = "1" ]; then
echo "Checking for dom0 updates..." >&2
UPDATES_FULL=`$YUM $OPTS check-update`
check_update_retcode=$?
UPDATES_FULL=`echo "$UPDATES_FULL" | grep -v "^Loaded plugins:\|^$"`
if [ $check_update_retcode -eq 1 ]; then
# Exit here if yum have reported an error. Exit code 100 isn't an
# error, it's "updates available" info, so check specifically for exit code 1
exit 1
fi
UPDATES=`echo "$UPDATES_FULL" | grep -v "^Obsoleting\|Could not" | cut -f 1 -d ' '`
if [ -z "$UPDATES" -a $check_update_retcode -eq 100 ]; then
# save not empty string for below condition (-z "$UPDATES"), but blank
# to not confuse the user wwith magic strings in messages
UPDATES=" "
if [ $check_update_retcode -eq 100 ]; then
echo "Available updates: "
echo "$UPDATES_FULL"
exit 100
else
echo "No new updates available"
if [ "$GUI" = 1 ]; then
zenity --info --text="No new updates available"
fi
exit 0
fi
else
PKGS_FROM_CMDLINE=1
fi
if [ -z "$PKGLIST" -a -z "$UPDATES" ]; then
echo "No new updates available"
if [ "$GUI" = 1 ]; then
zenity --info --text="No new updates available"
fi
exit 0
fi
if [ "$CHECK_ONLY" = "1" ]; then
echo "Available updates: "
echo "$UPDATES_FULL"
exit 100
fi
if [ "$DOIT" != "1" -a "$PKGS_FROM_CMDLINE" != "1" ]; then
zenity --question --title="Qubes Dom0 updates" \
--text="There are updates for dom0 available, do you want to download them now?" || exit 0
fi
# now, we will download something
YUM_COMMAND="fakeroot $YUM $YUM_ACTION -y --downloadonly"
# check for --downloadonly option - if not supported (Debian), fallback to
# yumdownloader
@ -132,6 +116,13 @@ if ! $YUM --help | grep -q downloadonly; then
exit 1
fi
if [ "$YUM_ACTION" = "upgrade" ]; then
UPDATES_FULL=`$YUM $OPTS check-update $PKGLIST`
check_update_retcode=$?
UPDATES=`echo "$UPDATES_FULL" | grep -v "^Obsoleting\|Could not" | cut -f 1 -d ' '`
if [ -z "$UPDATES" -a $check_update_retcode -eq 0 ]; then
echo "No new updates available"
exit 0
fi
PKGLIST=$UPDATES
fi
YUM_COMMAND="yumdownloader --destdir=$DOM0_UPDATES_DIR/packages --resolve"