2006-06-09 17:18:19 by steve
Read the configuration file for our configuration options.
This commit is contained in:
@@ -31,7 +31,7 @@ xen-create-image - Create a new Xen instance
|
||||
--
|
||||
http://www.steve.org.uk/
|
||||
|
||||
$Id: xen-create-image,v 1.10 2006-06-09 17:03:31 steve Exp $
|
||||
$Id: xen-create-image,v 1.11 2006-06-09 17:18:19 steve Exp $
|
||||
|
||||
=cut
|
||||
|
||||
@@ -96,6 +96,12 @@ checkSystem();
|
||||
setupDefaultOptions();
|
||||
|
||||
|
||||
#
|
||||
# Read the global configuration file.
|
||||
#
|
||||
readConfigurationFile();
|
||||
|
||||
|
||||
#
|
||||
# Parse the command line arguments.
|
||||
#
|
||||
@@ -266,6 +272,64 @@ sub setupDefaultOptions
|
||||
|
||||
|
||||
|
||||
|
||||
=head2 readConfigurationFile
|
||||
|
||||
read the global configuration file /etc/xen-tools/xen-tools.conf
|
||||
|
||||
=cut
|
||||
|
||||
sub readConfigurationFile
|
||||
{
|
||||
my $file = '/etc/xen-tools/xen-tools.conf';
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
=head2 parseCommandLineArguments
|
||||
|
||||
Parse the command line arguments this script was given.
|
||||
@@ -325,7 +389,7 @@ sub parseCommandLineArguments
|
||||
|
||||
if ( $VERSION )
|
||||
{
|
||||
my $REVISION = '$Revision: 1.10 $';
|
||||
my $REVISION = '$Revision: 1.11 $';
|
||||
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
@@ -800,7 +864,7 @@ sub runCustomisationHooks
|
||||
print "=============\n";
|
||||
foreach my $key ( sort keys %ENV )
|
||||
{
|
||||
print "\t'" . $key . "' = '" . $CONFIG{$key} . "'\n";
|
||||
print "\t'" . $key . "' = '" . $ENV{$key} . "'\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user