2011-06-22 00:44:48 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-02-07 03:07:43 +01:00
|
|
|
UPDATEVM=`qubes-prefs --get updatevm`
|
2012-07-14 15:55:46 +02:00
|
|
|
UPDATES_STAT_FILE=/var/lib/qubes/updates/dom0-updates-available
|
|
|
|
|
2011-06-22 00:44:48 +02:00
|
|
|
if [ -z "$UPDATEVM" ]; then
|
|
|
|
echo "UpdateVM not set, exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-09-12 14:57:38 +02:00
|
|
|
if [ "$1" = "--help" ]; then
|
|
|
|
echo "This tool is used to download packages for dom0. Without package list"
|
|
|
|
echo "it checks for updates for installed packages"
|
|
|
|
echo ""
|
2011-10-07 21:25:38 +02:00
|
|
|
echo "Usage: $0 [--clean] [--check-only] [--gui] [<pkg list>]"
|
2011-09-12 14:57:38 +02:00
|
|
|
echo " --clean clean yum cache before doing anything"
|
2011-10-07 21:25:38 +02:00
|
|
|
echo " --check-only only check for updates (no install)"
|
|
|
|
echo " --gui use gpk-update-viewer for update selection"
|
2011-09-12 14:57:38 +02:00
|
|
|
echo " <pkg list> download (and install if run by root) new packages"
|
|
|
|
echo " in dom0 instead of updating"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2011-09-12 16:21:03 +02:00
|
|
|
PKGS=
|
2011-10-07 21:25:38 +02:00
|
|
|
YUM_OPTS=
|
|
|
|
GUI=
|
|
|
|
CHECK_ONLY=
|
2011-10-17 23:27:29 +02:00
|
|
|
ALL_OPTS=$*
|
2011-09-12 16:21:03 +02:00
|
|
|
# Filter out some yum options and collect packages list
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--enablerepo=*|\
|
|
|
|
--disablerepo=*|\
|
|
|
|
--clean)
|
|
|
|
;;
|
2011-10-07 21:25:38 +02:00
|
|
|
--gui)
|
|
|
|
GUI=1
|
|
|
|
;;
|
|
|
|
--check-only)
|
|
|
|
CHECK_ONLY=1
|
|
|
|
;;
|
2011-09-12 16:21:03 +02:00
|
|
|
-*)
|
2011-10-07 21:25:38 +02:00
|
|
|
YUM_OPTS="$YUM_OPTS $1"
|
2011-09-12 16:21:03 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
PKGS="$PKGS $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
2011-09-08 14:12:56 +02:00
|
|
|
|
2011-10-07 21:25:38 +02:00
|
|
|
ID=$(id -ur)
|
2011-10-10 15:34:24 +02:00
|
|
|
if [ $ID != 0 -a -z "$GUI" -a -z "$CHECK_ONLY" ] ; then
|
2011-10-07 21:25:38 +02:00
|
|
|
echo "This script should be run as root (when used in console mode), use sudo." >&2
|
2013-02-22 21:21:31 +01:00
|
|
|
exit 1
|
2011-10-07 21:25:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$GUI" == "1" -a -n "$PKGS" ]; then
|
|
|
|
echo "ERROR: GUI mode can be used only for updates" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Do not start VM automaticaly when running from cron (only checking for updates)
|
|
|
|
if [ "$CHECK_ONLY" == "1" ] && ! xl domid $UPDATEVM > /dev/null 2>&1; then
|
|
|
|
echo "ERROR: UpdateVM not running, not starting it in non-interactive mode" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We should ensure the clocks in Dom0 and UpdateVM are in sync
|
|
|
|
# becuase otherwise yum might complain about future timestamps
|
2012-02-01 17:08:07 +01:00
|
|
|
qvm-sync-clock
|
2011-10-07 21:25:38 +02:00
|
|
|
|
|
|
|
echo "Checking for dom0 updates" >&2
|
|
|
|
|
|
|
|
# Start VM if not running already
|
|
|
|
qvm-run -a $UPDATEVM true || exit 1
|
|
|
|
|
2012-07-16 13:31:43 +02:00
|
|
|
/usr/lib/qubes/qrexec_client -d "$UPDATEVM" -l 'tar c /var/lib/rpm /etc/yum.repos.d /etc/yum.conf 2>/dev/null' 'user:tar x -C /var/lib/qubes/dom0-updates' 2> /dev/null
|
2011-10-07 21:25:38 +02:00
|
|
|
|
2012-02-01 16:04:52 +01:00
|
|
|
qvm-run --pass-io $UPDATEVM "/usr/lib/qubes/qubes_download_dom0_updates.sh --doit --nogui $ALL_OPTS"
|
2011-10-07 21:25:38 +02:00
|
|
|
RETCODE=$?
|
|
|
|
if [ "$CHECK_ONLY" == "1" ]; then
|
|
|
|
exit $RETCODE
|
|
|
|
elif [ "$RETCODE" -ne 0 ]; then
|
|
|
|
exit $RETCODE
|
|
|
|
fi
|
|
|
|
# Wait for download completed
|
|
|
|
while pidof -x qubes-receive-updates >/dev/null; do sleep 0.5; done
|
|
|
|
|
2012-07-30 22:45:05 +02:00
|
|
|
if [ -r /var/lib/qubes/updates/errors ]; then
|
|
|
|
echo "*** ERROR while receiving updates:" >&2
|
|
|
|
cat /var/lib/qubes/updates/errors >&2
|
|
|
|
echo "--> if you want to use packages that were downloaded correctly, use yum directly now" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-09-12 16:21:03 +02:00
|
|
|
if [ "x$PKGS" != "x" ]; then
|
2011-10-07 21:25:38 +02:00
|
|
|
yum $YUM_OPTS install $PKGS
|
2011-07-24 21:54:10 +02:00
|
|
|
elif [ -f /var/lib/qubes/updates/repodata/repomd.xml ]; then
|
2011-09-12 15:04:27 +02:00
|
|
|
# Above file exists only when at least one package was downloaded
|
2011-10-07 21:25:38 +02:00
|
|
|
if [ "$GUI" == "1" ]; then
|
|
|
|
gpk-update-viewer
|
|
|
|
else
|
|
|
|
yum check-update
|
|
|
|
if [ $? -eq 100 ]; then
|
|
|
|
yum $YUM_OPTS update
|
|
|
|
fi
|
2011-07-24 21:54:10 +02:00
|
|
|
fi
|
2012-07-29 02:34:45 +02:00
|
|
|
yum -q check-update && rm -f $UPDATES_STAT_FILE
|
2011-07-24 21:54:10 +02:00
|
|
|
else
|
2011-10-07 21:25:38 +02:00
|
|
|
echo "No updates avaliable" >&2
|
2011-06-22 00:44:48 +02:00
|
|
|
fi
|