From f356b6065c095211836fe83ab9e805e9d4bdc3db Mon Sep 17 00:00:00 2001 From: Dmitry Nedospasov Date: Wed, 2 Jun 2010 16:43:48 +0200 Subject: [PATCH] Added cachedir option for manually setting a cache directory This way .debs actually get copied somewhere on non Debian/Ubuntu systems, and also this way the cache directory can be overriden, so that the host's apt-cache doesn't get cluttered with guest .debs. --- bin/xen-create-image | 6 ++++++ bin/xt-install-image | 15 ++++++++++----- etc/xen-tools.conf | 8 ++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index 1b8a5a4..cd336c8 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -1269,6 +1269,7 @@ sub setupDefaultOptions $CONFIG{ 'size' } = '2000Mb'; $CONFIG{ 'swap' } = '128M'; $CONFIG{ 'cache' } = 'yes'; + $CONFIG{ 'cachedir' } = '/var/cache/apt/archives/'; $CONFIG{ 'image' } = 'sparse'; $CONFIG{ 'vcpus' } = '1'; @@ -1515,6 +1516,7 @@ sub parseCommandLineArguments "fs=s", \$CONFIG{ 'fs' }, "boot", \$CONFIG{ 'boot' }, "cache=s", \$CONFIG{ 'cache' }, + "cachedir=s", \$CONFIG{ 'cachedir' }, "config=s", \$CONFIG{ 'config' }, "ide", \$CONFIG{ 'ide' }, "scsi", \$CONFIG{ 'scsi' }, @@ -3251,6 +3253,10 @@ sub installSystem # $cmd .= " --cache=$CONFIG{'cache'}" if length( $CONFIG{ 'cache' } ); + # + # Add on the current cachedir setting + # + $cmd .= " --cachedir=$CONFIG{'cachedir'}" if length( $CONFIG{ 'cachedir' } ); # # Propagate --verbose diff --git a/bin/xt-install-image b/bin/xt-install-image index 3aab3ab..243be19 100755 --- a/bin/xt-install-image +++ b/bin/xt-install-image @@ -391,6 +391,7 @@ sub parseCommandLineArguments # Misc "arch=s", \$CONFIG{ 'arch' }, "cache=s", \$CONFIG{ 'cache' }, + "cachedir=s", \$CONFIG{ 'cachedir' }, "config=s", \$CONFIG{ 'config' }, "mirror=s", \$CONFIG{ 'mirror' }, @@ -702,7 +703,7 @@ sub do_debootstrap # to use cdebootstrap. # my $cmd = $CONFIG{ 'debootstrap-cmd' }; - my $cachepath = '/var/cache/apt/archives/'; + my $cachedir = $CONFIG{ 'cachedir' }; if ( !$cmd ) { if (-x '/usr/sbin/debootstrap') { @@ -724,12 +725,16 @@ sub do_debootstrap if ( $CONFIG{ 'cache' } eq "yes" ) { print "\nCopying files from host to image.\n"; - unless( -d $cachepath ) { - $cachepath = '/var/cache/xen-tools/archives'; - system "mkdir -p $cachepath"; + unless( -d $cachedir ) { + my $xtcache = '/var/cache/xen-tools/archives/'; + print("$cachedir not found, defaulting to $xtcache\n"); + unless ( -d $xtcache ) { + system "mkdir -p $xtcache"; + } + $cachedir = $xtcache; } runCommand("mkdir -p $CONFIG{'location'}/var/cache/apt/archives"); - copyDebFiles( "$cachepath", + copyDebFiles( "$cachedir", "$CONFIG{'location'}/var/cache/apt/archives" ); print("Done\n"); } diff --git a/etc/xen-tools.conf b/etc/xen-tools.conf index 690519d..2123f58 100644 --- a/etc/xen-tools.conf +++ b/etc/xen-tools.conf @@ -180,6 +180,14 @@ image = sparse # Specify sparse vs. full disk images. # cache = no # +# +# The default cachedir is, /var/cache/apt/archives/, however if it +# does not exist it will default to /var/cache/xen-tools/archives/ +# Uncomment the line below to set it to something else. +# +# cachedir = /var/cache/xen-tools/archives/ +# + # # Uncomment the following line if you wish to interactively setup # a new root password for images.