From 8c6e03588ac4ffc73f4950660601dbbdbe105f9b Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 14:32:56 +0200 Subject: [PATCH 01/12] vm: Parse all options from when downloading updates (#348) Collect options and pkg names to separate variables and check if any pkg name was given, not any argument. --- common/qubes_download_dom0_updates.sh | 29 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/common/qubes_download_dom0_updates.sh b/common/qubes_download_dom0_updates.sh index 1b1ea0bc..24721842 100755 --- a/common/qubes_download_dom0_updates.sh +++ b/common/qubes_download_dom0_updates.sh @@ -4,14 +4,23 @@ DOM0_UPDATES_DIR=/var/lib/qubes/dom0-updates DOIT=0 GUI=1 +OPTS= +PKGLIST= while [ -n "$1" ]; do - if [ "x--doit" = "x$1" ]; then - DOIT=1 - elif [ "x--nogui" = "x$1" ]; then - GUI=0 - else - break - fi + case "$1" in + --doit) + DOIT=1 + ;; + --nogui) + GUI=0 + ;; + -*) + OPTS="$OPTS $1" + ;; + *) + PKGLIST="$PKGLIST $1" + ;; + esac shift done @@ -23,11 +32,9 @@ fi mkdir -p $DOM0_UPDATES_DIR/etc cp /etc/yum.conf $DOM0_UPDATES_DIR/etc/ -PKGLIST="$*" - if [ "x$PKGLIST" = "x" ]; then echo "Checking for dom0 updates..." - PKGLIST=`yum --installroot $DOM0_UPDATES_DIR check-update -q | cut -f 1 -d ' '` + PKGLIST=`yum --installroot $DOM0_UPDATES_DIR $OPTS check-update -q | cut -f 1 -d ' '` else PKGS_FROM_CMDLINE=1 fi @@ -44,7 +51,7 @@ if [ "$DOIT" != "1" -a "$PKGS_FROM_CMDLINE" != "1" ]; then fi if [ "$PKGS_FROM_CMDLINE" == 1 ]; then - OPTS="--resolve" + OPTS="$OPTS --resolve" GUI=0 fi From e8d84ced0a269b38f845a0aeae4bd0a768be4122 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 14:34:41 +0200 Subject: [PATCH 02/12] vm: dom0 updates - minor cleanup --- common/qubes_download_dom0_updates.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/qubes_download_dom0_updates.sh b/common/qubes_download_dom0_updates.sh index 24721842..e56d3ac5 100755 --- a/common/qubes_download_dom0_updates.sh +++ b/common/qubes_download_dom0_updates.sh @@ -4,7 +4,7 @@ DOM0_UPDATES_DIR=/var/lib/qubes/dom0-updates DOIT=0 GUI=1 -OPTS= +OPTS="--installroot $DOM0_UPDATES_DIR" PKGLIST= while [ -n "$1" ]; do case "$1" in @@ -34,7 +34,7 @@ cp /etc/yum.conf $DOM0_UPDATES_DIR/etc/ if [ "x$PKGLIST" = "x" ]; then echo "Checking for dom0 updates..." - PKGLIST=`yum --installroot $DOM0_UPDATES_DIR $OPTS check-update -q | cut -f 1 -d ' '` + PKGLIST=`yum $OPTS check-update -q | cut -f 1 -d ' '` else PKGS_FROM_CMDLINE=1 fi @@ -61,11 +61,11 @@ set -e if [ "$GUI" = 1 ]; then ( echo "1" - yumdownloader --destdir "$DOM0_UPDATES_DIR/packages" --installroot "$DOM0_UPDATES_DIR" $OPTS $PKGLIST + yumdownloader --destdir "$DOM0_UPDATES_DIR/packages" $OPTS $PKGLIST echo 100 ) | zenity --progress --pulsate --auto-close --auto-kill \ --text="Downloading updates for Dom0, please wait..." --title="Qubes Dom0 updates" else - yumdownloader --destdir "$DOM0_UPDATES_DIR/packages" --installroot "$DOM0_UPDATES_DIR" $OPTS $PKGLIST + yumdownloader --destdir "$DOM0_UPDATES_DIR/packages" $OPTS $PKGLIST fi if ls $DOM0_UPDATES_DIR/packages/*.rpm > /dev/null 2>&1; then From d57804b6a0666631270e44565e313c83eb1e652e Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 14:36:53 +0200 Subject: [PATCH 03/12] vm: allow clean yum cache for dom0 updates (#346) --- common/qubes_download_dom0_updates.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/qubes_download_dom0_updates.sh b/common/qubes_download_dom0_updates.sh index e56d3ac5..c30e5bf6 100755 --- a/common/qubes_download_dom0_updates.sh +++ b/common/qubes_download_dom0_updates.sh @@ -4,6 +4,7 @@ DOM0_UPDATES_DIR=/var/lib/qubes/dom0-updates DOIT=0 GUI=1 +CLEAN=0 OPTS="--installroot $DOM0_UPDATES_DIR" PKGLIST= while [ -n "$1" ]; do @@ -14,6 +15,9 @@ while [ -n "$1" ]; do --nogui) GUI=0 ;; + --clean) + CLEAN=1 + ;; -*) OPTS="$OPTS $1" ;; @@ -32,6 +36,10 @@ fi mkdir -p $DOM0_UPDATES_DIR/etc cp /etc/yum.conf $DOM0_UPDATES_DIR/etc/ +if [ "x$CLEAN" = "1" ]; then + yum $OPTS clean all +fi + if [ "x$PKGLIST" = "x" ]; then echo "Checking for dom0 updates..." PKGLIST=`yum $OPTS check-update -q | cut -f 1 -d ' '` From 972ab21d5fc131b1d731a1be304cd7b0876685ed Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 14:37:52 +0200 Subject: [PATCH 04/12] dom0: rename qvm-dom0-upgrade tool (#350) --- dom0/qvm-tools/{qvm-dom0-upgrade => qvm-dom0-update} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dom0/qvm-tools/{qvm-dom0-upgrade => qvm-dom0-update} (100%) diff --git a/dom0/qvm-tools/qvm-dom0-upgrade b/dom0/qvm-tools/qvm-dom0-update similarity index 100% rename from dom0/qvm-tools/qvm-dom0-upgrade rename to dom0/qvm-tools/qvm-dom0-update From 9395ea239c7e4ae9669a7b481cd993d17e13041a Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 14:57:38 +0200 Subject: [PATCH 05/12] dom0: qvm-dom0-update --help (#349) --- dom0/qvm-tools/qvm-dom0-update | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dom0/qvm-tools/qvm-dom0-update b/dom0/qvm-tools/qvm-dom0-update index 6cd40254..fa5bfda0 100755 --- a/dom0/qvm-tools/qvm-dom0-update +++ b/dom0/qvm-tools/qvm-dom0-update @@ -1,12 +1,22 @@ #!/bin/bash - UPDATEVM=`qvm-get-updatevm` if [ -z "$UPDATEVM" ]; then echo "UpdateVM not set, exiting" exit 1 fi +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 "" + echo "Usage: $0 [--clean] []" + echo " --clean clean yum cache before doing anything" + echo " download (and install if run by root) new packages" + echo " in dom0 instead of updating" + exit +fi + # We should ensure the clocks in Dom0 and UpdateVM are in sync # becuase otherwise yum might complain about future timestamps qvm-sync-dom0-clock From 2bbdb93594881248228ecdad553f20521edfe097 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 15:04:27 +0200 Subject: [PATCH 06/12] dom0/qvm-dom0-update: replace gpk-update-viewer with yum update (#347) --- dom0/qvm-tools/qvm-dom0-update | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dom0/qvm-tools/qvm-dom0-update b/dom0/qvm-tools/qvm-dom0-update index fa5bfda0..36159d74 100755 --- a/dom0/qvm-tools/qvm-dom0-update +++ b/dom0/qvm-tools/qvm-dom0-update @@ -40,9 +40,17 @@ if [ $# -gt 0 ]; then yum install $@ elif [ -f /var/lib/qubes/updates/repodata/repomd.xml ]; then + # Above file exists only when at least one package was downloaded yum check-update if [ $? -eq 100 ]; then - gpk-update-viewer + + ID=$(id -ur) + if [ $ID != 0 ] ; then + echo "This script should be run as root, use sudo next time." + echo "Now you can manually run yum update (use sudo again)." + exit + fi + yum update fi else echo "No updates avaliable" From 2107191ca9337612ac356ef8c8fc148fc17d4afd Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 15:05:26 +0200 Subject: [PATCH 07/12] dom0/qvm-dom0-update: do not use GUI when called from cmdline --- dom0/qvm-tools/qvm-dom0-update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom0/qvm-tools/qvm-dom0-update b/dom0/qvm-tools/qvm-dom0-update index 36159d74..b9dae551 100755 --- a/dom0/qvm-tools/qvm-dom0-update +++ b/dom0/qvm-tools/qvm-dom0-update @@ -26,7 +26,7 @@ echo "Checking for dom0 updates" # Start VM if not running already qvm-run -a $UPDATEVM true || exit 1 /usr/lib/qubes/sync_rpmdb_updatevm.sh || exit 1 -qvm-run --pass_io $UPDATEVM "/usr/lib/qubes/qubes_download_dom0_updates.sh $*" || exit 1 +qvm-run --pass_io $UPDATEVM "/usr/lib/qubes/qubes_download_dom0_updates.sh --doit --nogui $*" || exit 1 # Wait for download completed while pidof -x qubes-receive-updates >/dev/null; do sleep 0.5; done if [ $# -gt 0 ]; then From 02ca39458acb292d607ffc02530dde647331e1d2 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 15:08:29 +0200 Subject: [PATCH 08/12] vm/dom0 updates: Remove useless PKGCOUNT information from message --- common/qubes_download_dom0_updates.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/qubes_download_dom0_updates.sh b/common/qubes_download_dom0_updates.sh index c30e5bf6..132a1619 100755 --- a/common/qubes_download_dom0_updates.sh +++ b/common/qubes_download_dom0_updates.sh @@ -53,9 +53,8 @@ if [ -z "$PKGLIST" ]; then fi if [ "$DOIT" != "1" -a "$PKGS_FROM_CMDLINE" != "1" ]; then - PKGCOUNT=`echo $PKGLIST|wc -w` zenity --question --title="Qubes Dom0 updates" \ - --text="$PKGCOUNT updates for dom0 available. Do you want to download its now?" || exit 0 + --text="There are updates for dom0 available, do you want to download them now?" || exit 0 fi if [ "$PKGS_FROM_CMDLINE" == 1 ]; then From fde8bc35fa3b626b3147a66a0677393a23d74f7a Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 15:25:31 +0200 Subject: [PATCH 09/12] dom0/qvm-backup: Support for NetVMs backup (#345) --- dom0/qvm-tools/qvm-backup | 10 ++++-- dom0/qvm-tools/qvm-backup-restore | 51 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/dom0/qvm-tools/qvm-backup b/dom0/qvm-tools/qvm-backup index 6e83ef98..bd74fb3e 100755 --- a/dom0/qvm-tools/qvm-backup +++ b/dom0/qvm-tools/qvm-backup @@ -88,6 +88,7 @@ def main(): files_to_backup = file_to_backup (qubes_store_filename) appvms_to_backup = [vm for vm in vms_list if vm.is_appvm() and not vm.name.endswith('-dvm')] + netvms_to_backup = [vm for vm in vms_list if vm.is_netvm()] there_are_running_vms = False fields_to_display = [ @@ -113,8 +114,8 @@ def main(): s += fmt.format('-') print s - if len (appvms_to_backup): - for vm in appvms_to_backup: + if len (appvms_to_backup + netvms_to_backup): + for vm in appvms_to_backup + netvms_to_backup: vm_sz = vm.get_disk_usage (vm.private_img) files_to_backup += file_to_backup(vm.private_img, vm_sz ) @@ -148,7 +149,10 @@ def main(): s += fmt.format(vm.name) fmt="{{0:>{0}}} |".format(fields_to_display[1]["width"] + 1) - s += fmt.format("AppVM" + (" + Sys" if vm.is_updateable() else "")) + if vm.is_netvm(): + s += fmt.format("NetVM" + (" + Sys" if vm.is_updateable() else "")) + else: + s += fmt.format("AppVM" + (" + Sys" if vm.is_updateable() else "")) fmt="{{0:>{0}}} |".format(fields_to_display[2]["width"] + 1) s += fmt.format(size_to_human(vm_sz)) diff --git a/dom0/qvm-tools/qvm-backup-restore b/dom0/qvm-tools/qvm-backup-restore index da8101c7..969651e6 100755 --- a/dom0/qvm-tools/qvm-backup-restore +++ b/dom0/qvm-tools/qvm-backup-restore @@ -26,6 +26,7 @@ from qubes.qubes import qubes_store_filename from qubes.qubes import qubes_base_dir from qubes.qubes import qubes_templates_dir from qubes.qubes import qubes_appvms_dir +from qubes.qubes import qubes_servicevms_dir from optparse import OptionParser import os @@ -321,6 +322,56 @@ def main(): host_collection.pop(vm.qid) continue + # ... then NetVMs... + for vm in [ vm for vm in vms_to_restore if vm.is_netvm()]: + + print "-> Restoring NetVM {0}...".format(vm.name) + retcode = subprocess.call (["mkdir", "-p", vm.dir_path]) + if retcode != 0: + print ("*** Cannot create directory: {0}?!".format(dest_dir)) + print ("Skiping...") + continue + + restore_vm_dir (backup_dir, vm.dir_path, qubes_servicevms_dir); + + template_vm = None + if vm.template_vm is not None: + template_name = find_template_name(vm.template_vm.name, options.replace_template) + template_vm = host_collection.get_vm_by_name(template_name) + + if not vm.uses_default_netvm: + uses_default_netvm = False + netvm_vm = host_collection.get_vm_by_name (vm.netvm_vm.name) if vm.netvm_vm is not None else None + else: + uses_default_netvm = True + + updateable = vm.updateable + + try: + vm = host_collection.add_new_netvm(vm.name, template_vm, + conf_file=vm.conf_file, + dir_path=vm.dir_path, + updateable=updateable, + label=vm.label) + except Exception as err: + print "ERROR: {0}".format(err) + print "*** Skiping VM: {0}".format(vm.name) + if vm: + host_collection.pop(vm.qid) + continue + + if not uses_default_netvm: + vm.uses_default_netvm = False + vm.netvm_vm = netvm_vm + + try: + vm.verify_files() + except Exception as err: + print "ERROR: {0}".format(err) + print "*** Skiping VM: {0}".format(vm.name) + host_collection.pop(vm.qid) + continue + # ... then appvms... for vm in [ vm for vm in vms_to_restore if vm.is_appvm()]: From 029e3fc09847bd9a72b870cf49aedb2e8791c8ae Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 16:21:03 +0200 Subject: [PATCH 10/12] dom0/qvm-dom0-update: Filter yum options in dom0 Eg. don't pass --enablerepo to yum install. --- dom0/qvm-tools/qvm-dom0-update | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/dom0/qvm-tools/qvm-dom0-update b/dom0/qvm-tools/qvm-dom0-update index b9dae551..1f261e39 100755 --- a/dom0/qvm-tools/qvm-dom0-update +++ b/dom0/qvm-tools/qvm-dom0-update @@ -29,8 +29,26 @@ qvm-run -a $UPDATEVM true || exit 1 qvm-run --pass_io $UPDATEVM "/usr/lib/qubes/qubes_download_dom0_updates.sh --doit --nogui $*" || exit 1 # Wait for download completed while pidof -x qubes-receive-updates >/dev/null; do sleep 0.5; done -if [ $# -gt 0 ]; then +PKGS= +OPTS= +# Filter out some yum options and collect packages list +while [ $# -gt 0 ]; do + case "$1" in + --enablerepo=*|\ + --disablerepo=*|\ + --clean) + ;; + -*) + OPTS="$OPTS $1" + ;; + *) + PKGS="$PKGS $1" + ;; + esac + shift +done +if [ "x$PKGS" != "x" ]; then ID=$(id -ur) if [ $ID != 0 ] ; then echo "This script should be run as root, use sudo next time." @@ -38,7 +56,7 @@ if [ $# -gt 0 ]; then exit fi - yum install $@ + yum $OPTS install $PKGS elif [ -f /var/lib/qubes/updates/repodata/repomd.xml ]; then # Above file exists only when at least one package was downloaded yum check-update @@ -50,7 +68,7 @@ elif [ -f /var/lib/qubes/updates/repodata/repomd.xml ]; then echo "Now you can manually run yum update (use sudo again)." exit fi - yum update + yum $OPTS update fi else echo "No updates avaliable" From ade25b8c8dbba92c14f29c2da017e40a7b461866 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 16:38:33 +0200 Subject: [PATCH 11/12] dom0/qvm-backup: exclude dom0 from backup --- dom0/qvm-tools/qvm-backup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom0/qvm-tools/qvm-backup b/dom0/qvm-tools/qvm-backup index bd74fb3e..1050784f 100755 --- a/dom0/qvm-tools/qvm-backup +++ b/dom0/qvm-tools/qvm-backup @@ -88,7 +88,7 @@ def main(): files_to_backup = file_to_backup (qubes_store_filename) appvms_to_backup = [vm for vm in vms_list if vm.is_appvm() and not vm.name.endswith('-dvm')] - netvms_to_backup = [vm for vm in vms_list if vm.is_netvm()] + netvms_to_backup = [vm for vm in vms_list if vm.is_netvm() and not vm.qid == 0] there_are_running_vms = False fields_to_display = [ From 813b626d27f5384c7c44ae1837ed6dfbd3393c73 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Mon, 12 Sep 2011 16:40:17 +0200 Subject: [PATCH 12/12] dom0/qvm-backup: include icon only for AppVM (#345) --- dom0/qvm-tools/qvm-backup | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dom0/qvm-tools/qvm-backup b/dom0/qvm-tools/qvm-backup index 1050784f..97b81555 100755 --- a/dom0/qvm-tools/qvm-backup +++ b/dom0/qvm-tools/qvm-backup @@ -120,7 +120,8 @@ def main(): vm_sz = vm.get_disk_usage (vm.private_img) files_to_backup += file_to_backup(vm.private_img, vm_sz ) - files_to_backup += file_to_backup(vm.icon_path) + if vm.is_appvm(): + files_to_backup += file_to_backup(vm.icon_path) if vm.is_updateable(): if os.path.exists(vm.dir_path + "/apps.templates"): # template