Merge branch 'master' of git.qubes-os.org:/var/lib/qubes/git/marmarek/core

Conflicts:
	dom0/qvm-tools/qvm-backup-restore
This commit is contained in:
Joanna Rutkowska 2011-09-13 10:33:42 +02:00
commit 099e8a47a9
5 changed files with 163 additions and 57 deletions

View File

@ -4,14 +4,27 @@ DOM0_UPDATES_DIR=/var/lib/qubes/dom0-updates
DOIT=0
GUI=1
CLEAN=0
OPTS="--installroot $DOM0_UPDATES_DIR"
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
;;
--clean)
CLEAN=1
;;
-*)
OPTS="$OPTS $1"
;;
*)
PKGLIST="$PKGLIST $1"
;;
esac
shift
done
@ -23,11 +36,13 @@ fi
mkdir -p $DOM0_UPDATES_DIR/etc
cp /etc/yum.conf $DOM0_UPDATES_DIR/etc/
PKGLIST="$*"
if [ "x$CLEAN" = "1" ]; then
yum $OPTS clean all
fi
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 $OPTS check-update -q | cut -f 1 -d ' '`
else
PKGS_FROM_CMDLINE=1
fi
@ -38,13 +53,12 @@ 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
OPTS="--resolve"
OPTS="$OPTS --resolve"
GUI=0
fi
@ -54,11 +68,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

View File

@ -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() and not vm.qid == 0]
there_are_running_vms = False
fields_to_display = [
@ -113,13 +114,14 @@ 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 )
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
@ -148,7 +150,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))

View File

@ -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
@ -327,6 +328,56 @@ def main():
print "ERROR during appmenu restore: {0}".format(err)
print "*** VM '{0}' will not have appmenus".format(vm.name)
# ... 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()]:

75
dom0/qvm-tools/qvm-dom0-update Executable file
View File

@ -0,0 +1,75 @@
#!/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] [<pkg list>]"
echo " --clean clean yum cache before doing anything"
echo " <pkg list> 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
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 --doit --nogui $*" || exit 1
# Wait for download completed
while pidof -x qubes-receive-updates >/dev/null; do sleep 0.5; done
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."
echo "Now you can manually run yum install (use sudo again)."
exit
fi
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
if [ $? -eq 100 ]; then
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 $OPTS update
fi
else
echo "No updates avaliable"
fi

View File

@ -1,39 +0,0 @@
#!/bin/bash
UPDATEVM=`qvm-get-updatevm`
if [ -z "$UPDATEVM" ]; then
echo "UpdateVM not set, exiting"
exit 1
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
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
# Wait for download completed
while pidof -x qubes-receive-updates >/dev/null; do sleep 0.5; done
if [ $# -gt 0 ]; then
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 install (use sudo again)."
exit
fi
yum install $@
elif [ -f /var/lib/qubes/updates/repodata/repomd.xml ]; then
yum check-update
if [ $? -eq 100 ]; then
gpk-update-viewer
fi
else
echo "No updates avaliable"
fi