2011-06-22 00:44:48 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
DOM0_UPDATES_DIR=/var/lib/qubes/dom0-updates
|
|
|
|
|
|
|
|
DOIT=0
|
|
|
|
GUI=1
|
2011-09-12 14:36:53 +02:00
|
|
|
CLEAN=0
|
2011-09-15 00:18:56 +02:00
|
|
|
CHECK_ONLY=0
|
2012-02-14 21:08:48 +01:00
|
|
|
OPTS="--installroot $DOM0_UPDATES_DIR --config=$DOM0_UPDATES_DIR/etc/yum.conf"
|
2016-06-01 04:40:56 +02:00
|
|
|
# DNF uses /etc/yum.repos.d, even when --installroot is specified
|
|
|
|
OPTS="$OPTS --setopt=reposdir=$DOM0_UPDATES_DIR/etc/yum.repos.d"
|
2011-09-12 14:32:56 +02:00
|
|
|
PKGLIST=
|
2015-03-26 00:59:28 +01:00
|
|
|
YUM_ACTION=
|
|
|
|
|
2014-01-10 03:34:16 +01:00
|
|
|
export LC_ALL=C
|
|
|
|
|
2011-06-22 00:44:48 +02:00
|
|
|
while [ -n "$1" ]; do
|
2011-09-12 14:32:56 +02:00
|
|
|
case "$1" in
|
|
|
|
--doit)
|
|
|
|
DOIT=1
|
|
|
|
;;
|
|
|
|
--nogui)
|
|
|
|
GUI=0
|
|
|
|
;;
|
2011-10-07 21:13:00 +02:00
|
|
|
--gui)
|
|
|
|
GUI=1
|
|
|
|
;;
|
2011-09-12 14:36:53 +02:00
|
|
|
--clean)
|
|
|
|
CLEAN=1
|
|
|
|
;;
|
2011-09-15 00:18:56 +02:00
|
|
|
--check-only)
|
|
|
|
CHECK_ONLY=1
|
|
|
|
;;
|
2015-03-26 00:59:28 +01:00
|
|
|
--action=*)
|
|
|
|
YUM_ACTION=${1#--action=}
|
|
|
|
;;
|
2011-09-12 14:32:56 +02:00
|
|
|
-*)
|
|
|
|
OPTS="$OPTS $1"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
PKGLIST="$PKGLIST $1"
|
2015-03-26 00:59:28 +01:00
|
|
|
if [ -z "$YUM_ACTION" ]; then
|
|
|
|
YUM_ACTION=install
|
|
|
|
fi
|
2011-09-12 14:32:56 +02:00
|
|
|
;;
|
|
|
|
esac
|
2011-06-22 00:44:48 +02:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2015-03-26 00:59:28 +01:00
|
|
|
if [ -z "$YUM_ACTION" ]; then
|
|
|
|
YUM_ACTION=upgrade
|
|
|
|
fi
|
|
|
|
|
2015-11-10 16:37:14 +01:00
|
|
|
YUM="yum"
|
2016-06-01 04:40:56 +02:00
|
|
|
if type dnf >/dev/null 2>&1; then
|
|
|
|
YUM="dnf"
|
2015-11-10 16:37:14 +01:00
|
|
|
fi
|
|
|
|
|
2011-06-22 00:44:48 +02:00
|
|
|
if ! [ -d "$DOM0_UPDATES_DIR" ]; then
|
2011-09-15 00:19:48 +02:00
|
|
|
echo "Dom0 updates dir does not exists: $DOM0_UPDATES_DIR" >&2
|
2011-06-22 00:44:48 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p $DOM0_UPDATES_DIR/etc
|
2011-09-14 00:35:49 +02:00
|
|
|
sed -i '/^reposdir\s*=/d' $DOM0_UPDATES_DIR/etc/yum.conf
|
2011-06-22 00:44:48 +02:00
|
|
|
|
2015-06-16 02:22:42 +02:00
|
|
|
if [ -e /etc/debian_version ]; then
|
|
|
|
# Default rpm configuration on Debian uses ~/.rpmdb for rpm database (as
|
|
|
|
# rpm isn't native package manager there)
|
|
|
|
mkdir -p "$DOM0_UPDATES_DIR$HOME"
|
|
|
|
ln -nsf "$DOM0_UPDATES_DIR/var/lib/rpm" "$DOM0_UPDATES_DIR$HOME/.rpmdb"
|
|
|
|
fi
|
2012-06-13 01:59:25 +02:00
|
|
|
# Rebuild rpm database in case of different rpm version
|
|
|
|
rm -f $DOM0_UPDATES_DIR/var/lib/rpm/__*
|
|
|
|
rpm --root=$DOM0_UPDATES_DIR --rebuilddb
|
|
|
|
|
2011-09-15 00:14:13 +02:00
|
|
|
if [ "$CLEAN" = "1" ]; then
|
2015-11-10 16:37:14 +01:00
|
|
|
$YUM $OPTS clean all
|
2011-09-14 20:19:53 +02:00
|
|
|
rm -f $DOM0_UPDATES_DIR/packages/*
|
2016-06-01 04:40:56 +02:00
|
|
|
rm -f $DOM0_UPDATES_DIR/var/cache/yum/*
|
2011-09-12 14:36:53 +02:00
|
|
|
fi
|
|
|
|
|
2011-07-16 01:57:27 +02:00
|
|
|
if [ "x$PKGLIST" = "x" ]; then
|
2011-09-15 00:19:48 +02:00
|
|
|
echo "Checking for dom0 updates..." >&2
|
2015-12-26 04:43:23 +01:00
|
|
|
UPDATES_FULL=`$YUM $OPTS check-update`
|
2015-11-10 16:37:14 +01:00
|
|
|
check_update_retcode=$?
|
2015-12-26 04:43:23 +01:00
|
|
|
UPDATES_FULL=`echo "$UPDATES_FULL" | grep -v "^Loaded plugins:\|^$"`
|
2015-11-10 16:37:14 +01:00
|
|
|
if [ $check_update_retcode -eq 1 ]; then
|
2015-10-10 22:01:02 +02:00
|
|
|
# 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
|
2015-11-11 05:14:16 +01:00
|
|
|
UPDATES=`echo "$UPDATES_FULL" | grep -v "^Obsoleting\|Could not" | cut -f 1 -d ' '`
|
2015-11-10 16:37:14 +01:00
|
|
|
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=" "
|
|
|
|
fi
|
2011-07-24 21:54:10 +02:00
|
|
|
else
|
|
|
|
PKGS_FROM_CMDLINE=1
|
2011-07-16 01:57:27 +02:00
|
|
|
fi
|
2011-06-22 00:44:48 +02:00
|
|
|
|
2014-03-28 06:52:31 +01:00
|
|
|
if [ -z "$PKGLIST" -a -z "$UPDATES" ]; then
|
2015-07-19 01:59:07 +02:00
|
|
|
echo "No new updates available"
|
2012-04-25 00:25:54 +02:00
|
|
|
if [ "$GUI" = 1 ]; then
|
|
|
|
zenity --info --text="No new updates available"
|
|
|
|
fi
|
2011-06-22 00:44:48 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2011-09-15 13:34:14 +02:00
|
|
|
if [ "$CHECK_ONLY" = "1" ]; then
|
2015-11-11 05:14:16 +01:00
|
|
|
echo "Available updates: "
|
|
|
|
echo "$UPDATES_FULL"
|
2011-09-15 13:34:14 +02:00
|
|
|
exit 100
|
|
|
|
fi
|
|
|
|
|
2011-07-24 21:54:10 +02:00
|
|
|
if [ "$DOIT" != "1" -a "$PKGS_FROM_CMDLINE" != "1" ]; then
|
2011-06-22 00:44:48 +02:00
|
|
|
zenity --question --title="Qubes Dom0 updates" \
|
2011-09-12 15:08:29 +02:00
|
|
|
--text="There are updates for dom0 available, do you want to download them now?" || exit 0
|
2011-06-22 00:44:48 +02:00
|
|
|
fi
|
|
|
|
|
2016-06-01 04:40:56 +02:00
|
|
|
YUM_COMMAND="fakeroot $YUM $YUM_ACTION -y --downloadonly"
|
2015-06-16 02:22:42 +02:00
|
|
|
# check for --downloadonly option - if not supported (Debian), fallback to
|
|
|
|
# yumdownloader
|
2015-11-10 16:37:14 +01:00
|
|
|
if ! $YUM --help | grep -q downloadonly; then
|
2015-06-16 02:22:42 +02:00
|
|
|
if [ "$YUM_ACTION" != "install" -a "$YUM_ACTION" != "upgrade" ]; then
|
2015-10-11 01:47:03 +02:00
|
|
|
echo "ERROR: yum version installed in VM `hostname` does not suppport --downloadonly option" >&2
|
2015-06-16 02:22:42 +02:00
|
|
|
echo "ERROR: only 'install' and 'upgrade' actions supported ($YUM_ACTION not)" >&2
|
|
|
|
if [ "$GUI" = 1 ]; then
|
|
|
|
zenity --error --text="yum version too old for '$YUM_ACTION' action, see console for details"
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ "$YUM_ACTION" = "upgrade" ]; then
|
|
|
|
PKGLIST=$UPDATES
|
|
|
|
fi
|
|
|
|
YUM_COMMAND="yumdownloader --destdir=$DOM0_UPDATES_DIR/packages --resolve"
|
|
|
|
fi
|
|
|
|
|
2011-06-22 00:44:48 +02:00
|
|
|
mkdir -p "$DOM0_UPDATES_DIR/packages"
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "$GUI" = 1 ]; then
|
|
|
|
( echo "1"
|
2015-06-16 02:22:42 +02:00
|
|
|
$YUM_COMMAND $OPTS $PKGLIST
|
2011-06-22 00:44:48 +02:00
|
|
|
echo 100 ) | zenity --progress --pulsate --auto-close --auto-kill \
|
|
|
|
--text="Downloading updates for Dom0, please wait..." --title="Qubes Dom0 updates"
|
|
|
|
else
|
2015-06-16 02:22:42 +02:00
|
|
|
$YUM_COMMAND $OPTS $PKGLIST
|
2011-06-22 00:44:48 +02:00
|
|
|
fi
|
|
|
|
|
2016-06-01 04:40:56 +02:00
|
|
|
find $DOM0_UPDATES_DIR/var/cache/yum -name '*.rpm' -print0 |\
|
|
|
|
xargs -0 -r ln -f -t $DOM0_UPDATES_DIR/packages/
|
|
|
|
|
2011-07-24 21:54:10 +02:00
|
|
|
if ls $DOM0_UPDATES_DIR/packages/*.rpm > /dev/null 2>&1; then
|
2015-09-03 16:56:29 +02:00
|
|
|
cmd="/usr/lib/qubes/qrexec-client-vm dom0 qubes.ReceiveUpdates /usr/lib/qubes/qfile-agent"
|
|
|
|
qrexec_exit_code=0
|
|
|
|
$cmd $DOM0_UPDATES_DIR/packages/*.rpm || { qrexec_exit_code=$? ; true; };
|
|
|
|
if [ ! "$qrexec_exit_code" = "0" ]; then
|
|
|
|
echo "'$cmd $DOM0_UPDATES_DIR/packages/*.rpm' failed with exit code ${qrexec_exit_code}!" >&2
|
|
|
|
exit $qrexec_exit_code
|
|
|
|
fi
|
2011-07-24 21:54:10 +02:00
|
|
|
else
|
|
|
|
echo "No packages downloaded"
|
|
|
|
fi
|