diff --git a/bin/xt-install-image b/bin/xt-install-image index 775904c..e307a19 100755 --- a/bin/xt-install-image +++ b/bin/xt-install-image @@ -80,7 +80,7 @@ Install the distribution specified by the B<--dist> argument using the debootstr -- http://www.steve.org.uk/ - $Id: xt-install-image,v 1.34 2006-08-27 21:31:30 steve Exp $ + $Id: xt-install-image,v 1.35 2006-09-10 20:51:55 steve Exp $ =cut @@ -115,6 +115,13 @@ my %CONFIG; my $RELEASE = '2.5'; + +# +# Read the global configuration file. +# +readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); + + # # Parse the command line arguments. # @@ -144,9 +151,27 @@ if ( $CONFIG{'copy'} ) } # - # Run a command to copy an installed system into the new root. + # Find the copy command from the configuration file, + # with a suitable default if one isn't found. # - runCommand( "/bin/cp -a $CONFIG{'copy'}/* $CONFIG{'location'}" ); + my $cmd = $CONFIG{'copy-cmd'} ; + if ( !defined( $cmd ) ) + { + print "Falling back to default copy command\n"; + $cmd = '/bin/cp -a $src/* $dest'; # Note: single quotes. + } + + # + # Expand the source and the destination. + # + $cmd =~ s/\$src/$CONFIG{'copy'}/g; + $cmd =~ s/\$dest/$CONFIG{'location'}/g; + + # + # Run the copy command. + # + runCommand( $cmd ); + } elsif ( $CONFIG{'tar'} ) { @@ -159,10 +184,26 @@ elsif ( $CONFIG{'tar'} ) exit 1; } + # + # Find the copy command from the configuration file, + # with a suitable default if one isn't found. + # + my $cmd = $CONFIG{'tar-cmd'} ; + if ( !defined( $cmd ) ) + { + print "Falling back to default tar command\n"; + $cmd = '/bin/tar --numeric-owner -xvf $src'; # Note: single quotes. + } + + # + # Expand the tarfile. + # + $cmd =~ s/\$src/$CONFIG{'tar'}/g; + # # Run a command to copy an installed system into the new root. # - runCommand( "cd $CONFIG{'location'} && tar -xvf $CONFIG{'tar'}" ); + runCommand( "cd $CONFIG{'location'} && $cmd" ); } elsif ( $CONFIG{'debootstrap'} ) { @@ -228,6 +269,69 @@ exit 0; +=begin doc + + read the global configuration file /etc/xen-tools/xen-tools.conf + +=end doc + +=cut + +sub readConfigurationFile +{ + my ($file) = ( @_ ); + + # Don't read the file if it doesn't exist. + return if ( ! -e $file ); + + + my $line = ""; + + open( FILE, "<", $file ) or die "Cannot read file '$file' - $!"; + + while (defined($line = ) ) + { + chomp $line; + if ($line =~ s/\\$//) + { + $line .= ; + redo unless eof(FILE); + } + + # Skip lines beginning with comments + next if ( $line =~ /^([ \t]*)\#/ ); + + # Skip blank lines + next if ( length( $line ) < 1 ); + + # Strip trailing comments. + if ( $line =~ /(.*)\#(.*)/ ) + { + $line = $1; + } + + # Find variable settings + if ( $line =~ /([^=]+)=([^\n]+)/ ) + { + my $key = $1; + my $val = $2; + + # Strip leading and trailing whitespace. + $key =~ s/^\s+//; + $key =~ s/\s+$//; + $val =~ s/^\s+//; + $val =~ s/\s+$//; + + # Store value. + $CONFIG{ $key } = $val; + } + } + + close( FILE ); +} + + + =begin doc Parse the command line arguments this script was given. @@ -275,7 +379,7 @@ sub parseCommandLineArguments if ( $VERSION ) { - my $REVISION = '$Revision: 1.34 $'; + my $REVISION = '$Revision: 1.35 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { $REVISION = $1; diff --git a/etc/xen-tools.conf b/etc/xen-tools.conf index a7523a8..a7ec93a 100644 --- a/etc/xen-tools.conf +++ b/etc/xen-tools.conf @@ -66,6 +66,25 @@ # tar = /path/to/img.tar # +# +## +# Command definitions. +## +# +# The "debootstrap" and "rpmstrap" commands are hardwired, but if you +# wish to alter the commands invoked when using the "--copy" + "--tar" +# options you can adjust these two settings: +# +# --copy: +# copy-cmd = /bin/cp -a $src/* $dest +# +# --tar: +# tar-cmd = /bin/tar --numeric-owner -xvf $src +# +# + + + # ## # Disk and Sizing options.