1
0
mirror of synced 2026-02-12 02:17:12 +00:00

2006-09-10 20:51:55 by steve

When using either --tar or --copy to install a new system allow that
 command to be specified in the configuration file.

  See: #385024.

  TODO: Completely free-form installation method?!
This commit is contained in:
steve
2006-09-10 20:51:56 +00:00
parent 79eb1beb68
commit de0754e17e
2 changed files with 128 additions and 5 deletions

View File

@@ -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 = <FILE>) )
{
chomp $line;
if ($line =~ s/\\$//)
{
$line .= <FILE>;
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;

View File

@@ -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.