Ran through perltidy
This commit is contained in:
parent
be30692061
commit
8be8f39add
1127
bin/xen-create-image
1127
bin/xen-create-image
File diff suppressed because it is too large
Load Diff
@ -140,7 +140,7 @@ $CONFIG{'xen_tools_version'} = $RELEASE;
|
||||
#
|
||||
# Read the global configuration file.
|
||||
#
|
||||
readConfigurationFile( "/etc/xen-tools/xen-tools.conf" );
|
||||
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
|
||||
|
||||
|
||||
#
|
||||
@ -161,7 +161,7 @@ testArguments();
|
||||
if ( -e "/etc/xen/$CONFIG{'hostname'}.cfg" )
|
||||
{
|
||||
die "Configuration file for $CONFIG{'hostname'} already exists"
|
||||
unless( $CONFIG{'force'} );
|
||||
unless ( $CONFIG{'force'} );
|
||||
}
|
||||
|
||||
#
|
||||
@ -197,20 +197,20 @@ exit;
|
||||
|
||||
sub readConfigurationFile
|
||||
{
|
||||
my ($file) = ( @_ );
|
||||
my ($file) = (@_);
|
||||
|
||||
# Don't read the file if it doesn't exist.
|
||||
return if ( ! -e $file );
|
||||
return if ( !-e $file );
|
||||
|
||||
|
||||
my $line = "";
|
||||
|
||||
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
|
||||
|
||||
while (defined($line = <FILE>) )
|
||||
while ( defined( $line = <FILE> ) )
|
||||
{
|
||||
chomp $line;
|
||||
if ($line =~ s/\\$//)
|
||||
if ( $line =~ s/\\$// )
|
||||
{
|
||||
$line .= <FILE>;
|
||||
redo unless eof(FILE);
|
||||
@ -220,7 +220,7 @@ sub readConfigurationFile
|
||||
next if ( $line =~ /^([ \t]*)\#/ );
|
||||
|
||||
# Skip blank lines
|
||||
next if ( length( $line ) < 1 );
|
||||
next if ( length($line) < 1 );
|
||||
|
||||
# Strip trailing comments.
|
||||
if ( $line =~ /(.*)\#(.*)/ )
|
||||
@ -243,6 +243,7 @@ sub readConfigurationFile
|
||||
# command expansion?
|
||||
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
|
||||
{
|
||||
|
||||
# store
|
||||
my $pre = $1;
|
||||
my $cmd = $2;
|
||||
@ -250,18 +251,18 @@ sub readConfigurationFile
|
||||
|
||||
# get output
|
||||
my $output = `$cmd`;
|
||||
chomp( $output );
|
||||
chomp($output);
|
||||
|
||||
# build up replacement.
|
||||
$val = $pre . $output . $post;
|
||||
}
|
||||
|
||||
# Store value.
|
||||
$CONFIG{ $key } = $val;
|
||||
$CONFIG{$key} = $val;
|
||||
}
|
||||
}
|
||||
|
||||
close( FILE );
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
|
||||
@ -286,48 +287,48 @@ sub parseCommandLineArguments
|
||||
#
|
||||
GetOptions(
|
||||
|
||||
# Networking options
|
||||
"dhcp", \$CONFIG{'dhcp'},
|
||||
"gateway=s", \$CONFIG{'gateway'},
|
||||
"broadcast=s", \$CONFIG{'broadcast'},
|
||||
"ip=s", \$CONFIG{'ip'},
|
||||
"netmask=s", \$CONFIG{'netmask'},
|
||||
"hostname=s", \$CONFIG{'hostname'},
|
||||
"memory=s", \$CONFIG{'memory'},
|
||||
"mac=s", \$CONFIG{'mac'},
|
||||
# Networking options
|
||||
"dhcp", \$CONFIG{'dhcp'},
|
||||
"gateway=s", \$CONFIG{'gateway'},
|
||||
"broadcast=s", \$CONFIG{'broadcast'},
|
||||
"ip=s", \$CONFIG{'ip'},
|
||||
"netmask=s", \$CONFIG{'netmask'},
|
||||
"hostname=s", \$CONFIG{'hostname'},
|
||||
"memory=s", \$CONFIG{'memory'},
|
||||
"mac=s", \$CONFIG{'mac'},
|
||||
|
||||
# NFS options.
|
||||
"nfs_server=s", \$CONFIG{'nfs_server'},
|
||||
"nfs_root=s", \$CONFIG{'nfs_root'},
|
||||
# NFS options.
|
||||
"nfs_server=s", \$CONFIG{'nfs_server'},
|
||||
"nfs_root=s", \$CONFIG{'nfs_root'},
|
||||
|
||||
# Misc. options
|
||||
"admins=s", \$CONFIG{'admins'},
|
||||
"kernel=s", \$CONFIG{'kernel'},
|
||||
"initrd=s", \$CONFIG{'initrd'},
|
||||
"force", \$CONFIG{'force'},
|
||||
"template=s", \$CONFIG{'template'},
|
||||
# Misc. options
|
||||
"admins=s", \$CONFIG{'admins'},
|
||||
"kernel=s", \$CONFIG{'kernel'},
|
||||
"initrd=s", \$CONFIG{'initrd'},
|
||||
"force", \$CONFIG{'force'},
|
||||
"template=s", \$CONFIG{'template'},
|
||||
|
||||
# Help options
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"version", \$VERSION
|
||||
# Help options
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"version", \$VERSION
|
||||
|
||||
);
|
||||
);
|
||||
|
||||
pod2usage(1) if $HELP;
|
||||
pod2usage(-verbose => 2 ) if $MANUAL;
|
||||
pod2usage( -verbose => 2 ) if $MANUAL;
|
||||
|
||||
|
||||
if ( $VERSION )
|
||||
if ($VERSION)
|
||||
{
|
||||
my $REVISION = '$Revision: 1.13 $';
|
||||
my $REVISION = '$Revision: 1.13 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
}
|
||||
|
||||
logprint( "xen-create-nfs release $RELEASE - CVS: $REVISION\n" );
|
||||
logprint("xen-create-nfs release $RELEASE - CVS: $REVISION\n");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@ -344,10 +345,11 @@ sub parseCommandLineArguments
|
||||
|
||||
sub testArguments
|
||||
{
|
||||
|
||||
#
|
||||
# Hostname is mandatory
|
||||
#
|
||||
die "No hostname" unless( $CONFIG{'hostname'} );
|
||||
die "No hostname" unless ( $CONFIG{'hostname'} );
|
||||
|
||||
my @network = qw/ ip gateway netmask /;
|
||||
|
||||
@ -356,24 +358,24 @@ sub testArguments
|
||||
#
|
||||
if ( $CONFIG{'dhcp'} )
|
||||
{
|
||||
foreach my $f ( @network )
|
||||
foreach my $f (@network)
|
||||
{
|
||||
delete( $CONFIG{ $f } );
|
||||
delete( $CONFIG{$f} );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach my $f ( @network )
|
||||
foreach my $f (@network)
|
||||
{
|
||||
die "Missing --$f" unless( $CONFIG{$f} );
|
||||
die "Missing --$f" unless ( $CONFIG{$f} );
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# We need an NFS server + root
|
||||
#
|
||||
die "Missing NFS server." unless( $CONFIG{'nfs_server'} );
|
||||
die "Missing NFS root." unless( $CONFIG{'nfs_root'} );
|
||||
die "Missing NFS server." unless ( $CONFIG{'nfs_server'} );
|
||||
die "Missing NFS root." unless ( $CONFIG{'nfs_root'} );
|
||||
|
||||
|
||||
# All OK.
|
||||
@ -381,7 +383,6 @@ sub testArguments
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
This routine is designed to ensure that any users specified with
|
||||
@ -393,6 +394,7 @@ sub testArguments
|
||||
|
||||
sub setupAdminUsers
|
||||
{
|
||||
|
||||
#
|
||||
# If we're not root we can't modify users.
|
||||
#
|
||||
@ -401,16 +403,17 @@ sub setupAdminUsers
|
||||
#
|
||||
# If we don't have a sudoers file then we'll also ignore this.
|
||||
#
|
||||
return if ( ! -e "/etc/sudoers" );
|
||||
return if ( !-e "/etc/sudoers" );
|
||||
|
||||
#
|
||||
# Find the path to the xen-login-shell
|
||||
#
|
||||
my $shell = undef;
|
||||
$shell = "/usr/bin/xen-login-shell" if ( -x "/usr/bin/xen-login-shell" );
|
||||
$shell = "/usr/local/bin/xen-login-shell" if ( -x "/usr/bin/local/xen-login-shell" );
|
||||
$shell = "/usr/local/bin/xen-login-shell"
|
||||
if ( -x "/usr/bin/local/xen-login-shell" );
|
||||
|
||||
return if ( !defined( $shell ) );
|
||||
return if ( !defined($shell) );
|
||||
|
||||
|
||||
#
|
||||
@ -419,6 +422,7 @@ sub setupAdminUsers
|
||||
#
|
||||
foreach my $user ( split( /,/, $ENV{'admins'} ) )
|
||||
{
|
||||
|
||||
# Strip leading and trailing whitespace.
|
||||
$user =~ s/^\s+//;
|
||||
$user =~ s/\s+$//;
|
||||
@ -429,12 +433,14 @@ sub setupAdminUsers
|
||||
# Does the user exist?
|
||||
if ( getpwnam($user) )
|
||||
{
|
||||
|
||||
# Change shell.
|
||||
$CONFIG{'verbose'} && print "Changing shell for $user: $shell\n";
|
||||
system( "chsh", "-s", $shell, $user );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
# Add a new user.
|
||||
$CONFIG{'verbose'} && print "Adding new user: $user\n";
|
||||
system( "useradd", "-s", $shell, $user );
|
||||
@ -443,9 +449,11 @@ sub setupAdminUsers
|
||||
#
|
||||
# Add the entry to /etc/sudoers.
|
||||
#
|
||||
open( SUDOERS, ">>", "/etc/sudoers" ) or warn "Failed to add user to sudoers file : $user - $!";
|
||||
print SUDOERS "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n";
|
||||
close( SUDOERS );
|
||||
open( SUDOERS, ">>", "/etc/sudoers" )
|
||||
or warn "Failed to add user to sudoers file : $user - $!";
|
||||
print SUDOERS
|
||||
"$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n";
|
||||
close(SUDOERS);
|
||||
|
||||
}
|
||||
}
|
||||
@ -461,7 +469,8 @@ sub setupAdminUsers
|
||||
|
||||
sub createNewConfigurationFile
|
||||
{
|
||||
die "Template file missing: $CONFIG{'template'}" unless( -e $CONFIG{'template'} );
|
||||
die "Template file missing: $CONFIG{'template'}"
|
||||
unless ( -e $CONFIG{'template'} );
|
||||
|
||||
#
|
||||
# Load the template.
|
||||
@ -469,7 +478,7 @@ sub createNewConfigurationFile
|
||||
my $template = new Text::Template( TYPE => 'FILE',
|
||||
SOURCE => $CONFIG{'template'} );
|
||||
|
||||
my $result = $template->fill_in( HASH => \%CONFIG );
|
||||
my $result = $template->fill_in( HASH => \%CONFIG );
|
||||
|
||||
#
|
||||
# The file we'll write to.
|
||||
@ -481,5 +490,5 @@ sub createNewConfigurationFile
|
||||
#
|
||||
open( FILE, ">", $file ) or die "Failed to write to $file - $!";
|
||||
print FILE $result;
|
||||
close( FILE );
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
@ -173,13 +173,12 @@ my $RELEASE = '3.9';
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Read the global configuration file if it exists.
|
||||
#
|
||||
if ( -e "/etc/xen-tools/xen-tools.conf" )
|
||||
{
|
||||
readConfigurationFile( "/etc/xen-tools/xen-tools.conf" );
|
||||
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
|
||||
}
|
||||
|
||||
|
||||
@ -199,7 +198,7 @@ checkArguments();
|
||||
#
|
||||
# Abort if non-root user.
|
||||
#
|
||||
if ( (!$CONFIG{'test'}) && ( $EFFECTIVE_USER_ID != 0 ) )
|
||||
if ( ( !$CONFIG{'test'} ) && ( $EFFECTIVE_USER_ID != 0 ) )
|
||||
{
|
||||
print <<E_O_ROOT;
|
||||
|
||||
@ -217,11 +216,11 @@ E_O_ROOT
|
||||
# Loop over the supplied arguments, and attempt to delete each
|
||||
# image.
|
||||
#
|
||||
while( my $name = shift )
|
||||
while ( my $name = shift )
|
||||
{
|
||||
if ( !xenRunning( $name ) )
|
||||
if ( !xenRunning($name) )
|
||||
{
|
||||
deleteXenImage( $name );
|
||||
deleteXenImage($name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -233,11 +232,11 @@ while( my $name = shift )
|
||||
# Also delete any which were specified using the --hostname flag
|
||||
#
|
||||
my $hosts = $CONFIG{'hostname'};
|
||||
foreach my $name ( @$hosts )
|
||||
foreach my $name (@$hosts)
|
||||
{
|
||||
if ( !xenRunning( $name ) )
|
||||
if ( !xenRunning($name) )
|
||||
{
|
||||
deleteXenImage( $name );
|
||||
deleteXenImage($name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -252,7 +251,6 @@ exit 0;
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Read the configuration file specified.
|
||||
@ -263,16 +261,16 @@ exit 0;
|
||||
|
||||
sub readConfigurationFile
|
||||
{
|
||||
my ($file) = ( @_ );
|
||||
my ($file) = (@_);
|
||||
|
||||
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
|
||||
|
||||
my $line = "";
|
||||
my $line = "";
|
||||
|
||||
while (defined($line = <FILE>) )
|
||||
while ( defined( $line = <FILE> ) )
|
||||
{
|
||||
chomp $line;
|
||||
if ($line =~ s/\\$//)
|
||||
if ( $line =~ s/\\$// )
|
||||
{
|
||||
$line .= <FILE>;
|
||||
redo unless eof(FILE);
|
||||
@ -282,7 +280,7 @@ sub readConfigurationFile
|
||||
next if ( $line =~ /^([ \t]*)\#/ );
|
||||
|
||||
# Skip blank lines
|
||||
next if ( length( $line ) < 1 );
|
||||
next if ( length($line) < 1 );
|
||||
|
||||
# Strip trailing comments.
|
||||
if ( $line =~ /(.*)\#(.*)/ )
|
||||
@ -305,6 +303,7 @@ sub readConfigurationFile
|
||||
# command expansion?
|
||||
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
|
||||
{
|
||||
|
||||
# store
|
||||
my $pre = $1;
|
||||
my $cmd = $2;
|
||||
@ -312,23 +311,22 @@ sub readConfigurationFile
|
||||
|
||||
# get output
|
||||
my $output = `$cmd`;
|
||||
chomp( $output );
|
||||
chomp($output);
|
||||
|
||||
# build up replacement.
|
||||
$val = $pre . $output . $post;
|
||||
}
|
||||
|
||||
# Store value.
|
||||
$CONFIG{ $key } = $val;
|
||||
$CONFIG{$key} = $val;
|
||||
}
|
||||
}
|
||||
|
||||
close( FILE );
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Parse the arguments specified upon the command line.
|
||||
@ -346,32 +344,32 @@ sub parseCommandLineArguments
|
||||
# Parse options.
|
||||
#
|
||||
GetOptions(
|
||||
"dir=s", \$CONFIG{'dir'},
|
||||
"lvm=s", \$CONFIG{'lvm'},
|
||||
"evms=s", \$CONFIG{'evms'},
|
||||
"hostname=s@", \$CONFIG{'hostname'},
|
||||
"test", \$CONFIG{'test'},
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
"dir=s", \$CONFIG{'dir'},
|
||||
"lvm=s", \$CONFIG{'lvm'},
|
||||
"evms=s", \$CONFIG{'evms'},
|
||||
"hostname=s@", \$CONFIG{'hostname'},
|
||||
"test", \$CONFIG{'test'},
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
|
||||
pod2usage(1) if $HELP;
|
||||
pod2usage(-verbose => 2 ) if $MANUAL;
|
||||
pod2usage( -verbose => 2 ) if $MANUAL;
|
||||
|
||||
|
||||
if ( $VERSION )
|
||||
if ($VERSION)
|
||||
{
|
||||
my $REVISION = '$Revision: 1.41 $';
|
||||
my $REVISION = '$Revision: 1.41 $';
|
||||
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
}
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
}
|
||||
|
||||
print "xen-delete-image release $RELEASE - CVS: $REVISION\n";
|
||||
exit;
|
||||
print "xen-delete-image release $RELEASE - CVS: $REVISION\n";
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
@ -388,6 +386,7 @@ sub parseCommandLineArguments
|
||||
|
||||
sub checkArguments
|
||||
{
|
||||
|
||||
#
|
||||
# When testing we only care about loopback images, not disk images.
|
||||
#
|
||||
@ -401,7 +400,7 @@ sub checkArguments
|
||||
# Make sure we got one and only one installation method.
|
||||
#
|
||||
my $count = 0;
|
||||
foreach my $type ( qw/dir lvm evms/ )
|
||||
foreach my $type (qw/dir lvm evms/)
|
||||
{
|
||||
$count += 1 if defined( $CONFIG{$type} );
|
||||
}
|
||||
@ -412,17 +411,16 @@ sub checkArguments
|
||||
#
|
||||
if ( $count != 1 )
|
||||
{
|
||||
print "Please select one and only one of the installation methods:\n";
|
||||
print " --dir\n";
|
||||
print " --evms\n";
|
||||
print " --lvm\n";
|
||||
exit;
|
||||
print "Please select one and only one of the installation methods:\n";
|
||||
print " --dir\n";
|
||||
print " --evms\n";
|
||||
print " --lvm\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Test to see if the given instance is running.
|
||||
@ -433,20 +431,20 @@ sub checkArguments
|
||||
|
||||
sub xenRunning
|
||||
{
|
||||
my( $hostname ) = (@_ );
|
||||
my ($hostname) = (@_);
|
||||
|
||||
my $running = 0;
|
||||
|
||||
open( CMD, "xm list $hostname 2>/dev/null |")
|
||||
open( CMD, "xm list $hostname 2>/dev/null |" )
|
||||
or die "Failed to run 'xm list $hostname'";
|
||||
while( <CMD> )
|
||||
while (<CMD>)
|
||||
{
|
||||
my $line = $_;
|
||||
$running = 1 if ( $line =~ /\Q$hostname\E/ )
|
||||
$running = 1 if ( $line =~ /\Q$hostname\E/ );
|
||||
}
|
||||
close( CMD );
|
||||
close(CMD);
|
||||
|
||||
return( $running );
|
||||
return ($running);
|
||||
}
|
||||
|
||||
|
||||
@ -461,7 +459,7 @@ sub xenRunning
|
||||
|
||||
sub deleteXenImage
|
||||
{
|
||||
my ($hostname) = ( @_ );
|
||||
my ($hostname) = (@_);
|
||||
|
||||
#
|
||||
# Collect the names of files to delete.
|
||||
@ -487,12 +485,12 @@ sub deleteXenImage
|
||||
#
|
||||
# If we're working on disk images remove them.
|
||||
#
|
||||
foreach my $file ( @delete )
|
||||
foreach my $file (@delete)
|
||||
{
|
||||
if ( -e $file )
|
||||
{
|
||||
print "Deleting: $file\n";
|
||||
unlink( $file );
|
||||
unlink($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -503,69 +501,71 @@ sub deleteXenImage
|
||||
|
||||
if ( defined( $CONFIG{'dir'} ) )
|
||||
{
|
||||
my $prefix = $CONFIG{'dir'} . "/domains/";
|
||||
my $prefix = $CONFIG{'dir'} . "/domains/";
|
||||
|
||||
#
|
||||
# Now remove the directory.
|
||||
#
|
||||
if ( -d $prefix . $hostname )
|
||||
{
|
||||
print "Removing: " . $prefix . $hostname . "\n";
|
||||
rmdir ( $prefix . $hostname );
|
||||
}
|
||||
#
|
||||
# Now remove the directory.
|
||||
#
|
||||
if ( -d $prefix . $hostname )
|
||||
{
|
||||
print "Removing: " . $prefix . $hostname . "\n";
|
||||
rmdir( $prefix . $hostname );
|
||||
}
|
||||
}
|
||||
elsif ( defined( $CONFIG{'lvm'} ) )
|
||||
{
|
||||
#
|
||||
# LVM volumes
|
||||
#
|
||||
#
|
||||
# TODO: Check we're not mounted.
|
||||
#
|
||||
|
||||
if ( -e "/dev/$CONFIG{'lvm'}/$hostname-swap" )
|
||||
{
|
||||
print "Removing swap volume\n";
|
||||
runCommand( "lvremove /dev/$CONFIG{'lvm'}/$hostname-swap --force" );
|
||||
}
|
||||
#
|
||||
# LVM volumes
|
||||
#
|
||||
#
|
||||
# TODO: Check we're not mounted.
|
||||
#
|
||||
|
||||
if ( -e "/dev/$CONFIG{'lvm'}/$hostname-disk" )
|
||||
{
|
||||
print "Removing LVM disk volume\n";
|
||||
runCommand( "lvremove /dev/$CONFIG{'lvm'}/$hostname-disk --force" );
|
||||
}
|
||||
if ( -e "/dev/$CONFIG{'lvm'}/$hostname-swap" )
|
||||
{
|
||||
print "Removing swap volume\n";
|
||||
runCommand("lvremove /dev/$CONFIG{'lvm'}/$hostname-swap --force");
|
||||
}
|
||||
|
||||
if ( -e "/dev/$CONFIG{'lvm'}/$hostname-disk" )
|
||||
{
|
||||
print "Removing LVM disk volume\n";
|
||||
runCommand("lvremove /dev/$CONFIG{'lvm'}/$hostname-disk --force");
|
||||
}
|
||||
|
||||
}
|
||||
elsif ( defined( $CONFIG{'evms'} ) )
|
||||
{
|
||||
#
|
||||
# EVMS volumes
|
||||
#
|
||||
#
|
||||
# TODO: Check we're not mounted.
|
||||
#
|
||||
|
||||
if ( -e "/dev/evms/$hostname-swap" )
|
||||
{
|
||||
print "Removing EVMS swap volume\n";
|
||||
runCommand( "echo Delete : /dev/evms/$hostname-swap | evms" );
|
||||
runCommand( "echo Delete : $CONFIG{'evms'}/$hostname-swap | evms" );
|
||||
}
|
||||
#
|
||||
# EVMS volumes
|
||||
#
|
||||
#
|
||||
# TODO: Check we're not mounted.
|
||||
#
|
||||
|
||||
if ( -e "/dev/evms/$hostname-disk" )
|
||||
{
|
||||
print "Removing EVMS disk volume\n";
|
||||
runCommand( "echo Delete : /dev/evms/$hostname-disk | evms" );
|
||||
runCommand( "echo Delete : $CONFIG{'evms'}/$hostname-disk | evms" );
|
||||
}
|
||||
if ( -e "/dev/evms/$hostname-swap" )
|
||||
{
|
||||
print "Removing EVMS swap volume\n";
|
||||
runCommand("echo Delete : /dev/evms/$hostname-swap | evms");
|
||||
runCommand("echo Delete : $CONFIG{'evms'}/$hostname-swap | evms");
|
||||
}
|
||||
|
||||
if ( -e "/dev/evms/$hostname-disk" )
|
||||
{
|
||||
print "Removing EVMS disk volume\n";
|
||||
runCommand("echo Delete : /dev/evms/$hostname-disk | evms");
|
||||
runCommand("echo Delete : $CONFIG{'evms'}/$hostname-disk | evms");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Error: No installation type specified\n";
|
||||
print "Can't happen!\n";
|
||||
print "Hostname : $hostname\n";
|
||||
exit 127;
|
||||
print "Error: No installation type specified\n";
|
||||
print "Can't happen!\n";
|
||||
print "Hostname : $hostname\n";
|
||||
exit 127;
|
||||
}
|
||||
}
|
||||
|
||||
@ -584,7 +584,7 @@ sub deleteXenImage
|
||||
|
||||
sub runCommand
|
||||
{
|
||||
my ( $cmd ) = (@_ );
|
||||
my ($cmd) = (@_);
|
||||
|
||||
#
|
||||
# Header.
|
||||
@ -596,14 +596,15 @@ sub runCommand
|
||||
#
|
||||
if ( $CONFIG{'verbose'} )
|
||||
{
|
||||
#
|
||||
# Copy stderr to stdout, so we can see it.
|
||||
#
|
||||
$cmd .= " 2>&1";
|
||||
|
||||
#
|
||||
# Copy stderr to stdout, so we can see it.
|
||||
#
|
||||
$cmd .= " 2>&1";
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd .= " >/dev/null 2>/dev/null" ;
|
||||
$cmd .= " >/dev/null 2>/dev/null";
|
||||
}
|
||||
|
||||
|
||||
@ -614,9 +615,9 @@ sub runCommand
|
||||
|
||||
if ( $? != 0 )
|
||||
{
|
||||
print "Running command '$cmd' failed.\n";
|
||||
print "Aborting\n";
|
||||
exit;
|
||||
print "Running command '$cmd' failed.\n";
|
||||
print "Aborting\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
@ -628,5 +629,5 @@ sub runCommand
|
||||
$CONFIG{'verbose'} && print $output . "\n";
|
||||
$CONFIG{'verbose'} && print "Finished : $cmd\n";
|
||||
|
||||
return( $output );
|
||||
return ($output);
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ my $RELEASE = '3.9';
|
||||
#
|
||||
# Read the global configuration file if it exists.
|
||||
#
|
||||
readConfigurationFile( "/etc/xen-tools/xen-tools.conf" );
|
||||
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
|
||||
|
||||
|
||||
#
|
||||
@ -129,11 +129,11 @@ my @instances = findXenInstances();
|
||||
# Now process each instance.
|
||||
#
|
||||
my $count = 0;
|
||||
foreach my $instance ( @instances )
|
||||
foreach my $instance (@instances)
|
||||
{
|
||||
if ( $count ) { print "\n"; }
|
||||
if ($count) { print "\n"; }
|
||||
|
||||
displayInstance( $instance );
|
||||
displayInstance($instance);
|
||||
$count += 1;
|
||||
}
|
||||
|
||||
@ -155,18 +155,18 @@ exit;
|
||||
|
||||
sub readConfigurationFile
|
||||
{
|
||||
my ($file) = ( @_ );
|
||||
my ($file) = (@_);
|
||||
|
||||
# Don't read the file if it doesn't exist.
|
||||
return if ( ! -e $file );
|
||||
return if ( !-e $file );
|
||||
|
||||
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
|
||||
|
||||
|
||||
while (defined(my $line = <FILE>) )
|
||||
while ( defined( my $line = <FILE> ) )
|
||||
{
|
||||
chomp $line;
|
||||
if ($line =~ s/\\$//)
|
||||
if ( $line =~ s/\\$// )
|
||||
{
|
||||
$line .= <FILE>;
|
||||
redo unless eof(FILE);
|
||||
@ -176,7 +176,7 @@ sub readConfigurationFile
|
||||
next if ( $line =~ /^([ \t]*)\#/ );
|
||||
|
||||
# Skip blank lines
|
||||
next if ( length( $line ) < 1 );
|
||||
next if ( length($line) < 1 );
|
||||
|
||||
# Strip trailing comments.
|
||||
if ( $line =~ /(.*)\#(.*)/ )
|
||||
@ -199,6 +199,7 @@ sub readConfigurationFile
|
||||
# command expansion?
|
||||
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
|
||||
{
|
||||
|
||||
# store
|
||||
my $pre = $1;
|
||||
my $cmd = $2;
|
||||
@ -206,22 +207,21 @@ sub readConfigurationFile
|
||||
|
||||
# get output
|
||||
my $output = `$cmd`;
|
||||
chomp( $output );
|
||||
chomp($output);
|
||||
|
||||
# build up replacement.
|
||||
$val = $pre . $output . $post;
|
||||
}
|
||||
|
||||
# Store value.
|
||||
$CONFIG{ $key } = $val;
|
||||
$CONFIG{$key} = $val;
|
||||
}
|
||||
}
|
||||
close( FILE );
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Parse the arguments specified upon the command line.
|
||||
@ -234,24 +234,20 @@ sub parseCommandLineArguments
|
||||
{
|
||||
my $HELP = 0;
|
||||
my $MANUAL = 0;
|
||||
my $VERSION = 0;
|
||||
my $VERSION = 0;
|
||||
|
||||
# Parse options.
|
||||
#
|
||||
GetOptions(
|
||||
"test=s", \$CONFIG{'prefix'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
GetOptions( "test=s", \$CONFIG{'prefix'}, "help", \$HELP, "manual",
|
||||
\$MANUAL, "version", \$VERSION );
|
||||
|
||||
pod2usage(1) if $HELP;
|
||||
pod2usage(-verbose => 2 ) if $MANUAL;
|
||||
pod2usage( -verbose => 2 ) if $MANUAL;
|
||||
|
||||
|
||||
if ( $VERSION )
|
||||
if ($VERSION)
|
||||
{
|
||||
my $REVISION = '$Revision: 1.30 $';
|
||||
my $REVISION = '$Revision: 1.30 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
@ -282,7 +278,7 @@ sub findXenInstances
|
||||
push @found, $file if ( -e $file );
|
||||
}
|
||||
|
||||
return( @found );
|
||||
return (@found);
|
||||
}
|
||||
|
||||
|
||||
@ -298,14 +294,14 @@ sub findXenInstances
|
||||
|
||||
sub displayInstance
|
||||
{
|
||||
my ( $file ) = ( @_ );
|
||||
my ($file) = (@_);
|
||||
|
||||
#
|
||||
# Read each line.
|
||||
#
|
||||
open( FILY, "<", $file );
|
||||
my @LINES = <FILY>;
|
||||
close( FILY );
|
||||
close(FILY);
|
||||
|
||||
#
|
||||
# Is it dynamic?
|
||||
@ -316,7 +312,7 @@ sub displayInstance
|
||||
my $name = '';
|
||||
my $mem = 0;
|
||||
|
||||
foreach my $line ( @LINES )
|
||||
foreach my $line (@LINES)
|
||||
{
|
||||
if ( $line =~ /^\s*dhcp\s*=\s*"dhcp\"/i )
|
||||
{
|
||||
@ -342,7 +338,7 @@ sub displayInstance
|
||||
|
||||
print "Name: $name\n";
|
||||
print "Memory: $mem\n";
|
||||
print "IP: " . $ip . $mac . "\n" if length( $ip );
|
||||
print "IP: " . $ip . $mac . "\n" if length($ip);
|
||||
print "DHCP" . $mac . "\n" if $dhcp;
|
||||
}
|
||||
|
||||
|
||||
@ -107,8 +107,6 @@ use Text::Template;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Configuration values read from the command line, or configuration file.
|
||||
#
|
||||
@ -125,7 +123,7 @@ my $RELEASE = '3.9';
|
||||
#
|
||||
# Read the global configuration file.
|
||||
#
|
||||
readConfigurationFile( "/etc/xen-tools/xen-tools.conf" );
|
||||
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
|
||||
|
||||
|
||||
#
|
||||
@ -147,11 +145,12 @@ my $path = undef;
|
||||
|
||||
if ( $CONFIG{'dir'} )
|
||||
{
|
||||
|
||||
#
|
||||
# Make sure we can find the disk
|
||||
#
|
||||
$path = $CONFIG{'dir'} . "/domains/" . $CONFIG{'hostname'} . "/disk.img";
|
||||
if ( ! -e $path )
|
||||
if ( !-e $path )
|
||||
{
|
||||
print <<EOF;
|
||||
|
||||
@ -201,15 +200,16 @@ EOF
|
||||
print "DO NOT INTERRUPT\n";
|
||||
|
||||
my $cmd = "dd if=/dev/zero bs=1M count=$CONFIG{'add'}k >> $path";
|
||||
system( $cmd );
|
||||
system($cmd );
|
||||
}
|
||||
elsif ( $CONFIG{'lvm'} )
|
||||
{
|
||||
|
||||
#
|
||||
# Make sure we can find the disk
|
||||
#
|
||||
$path = "/dev/" . $CONFIG{'lvm'} . "/" . $CONFIG{'hostname'} . "-disk";
|
||||
if ( ! -e $path )
|
||||
if ( !-e $path )
|
||||
{
|
||||
print <<EOF;
|
||||
|
||||
@ -258,7 +258,7 @@ EOF
|
||||
|
||||
print "DO NOT INTERRUPT\n";
|
||||
my $cmd = "lvextend -L+$CONFIG{'add'}M $path";
|
||||
system( $cmd );
|
||||
system($cmd );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -271,13 +271,13 @@ else
|
||||
# Check filesystem.
|
||||
#
|
||||
print "Checking filesystem\n";
|
||||
system( "fsck.ext3 -f $path" );
|
||||
system("fsck.ext3 -f $path");
|
||||
|
||||
#
|
||||
# Run ext3resize.
|
||||
#
|
||||
print "Resizing in place\n";
|
||||
system( "resize2fs $path" );
|
||||
system("resize2fs $path");
|
||||
|
||||
|
||||
#
|
||||
@ -298,16 +298,16 @@ exit 0;
|
||||
|
||||
sub readConfigurationFile
|
||||
{
|
||||
my ($file) = ( @_ );
|
||||
my ($file) = (@_);
|
||||
|
||||
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
|
||||
|
||||
my $line = "";
|
||||
my $line = "";
|
||||
|
||||
while (defined($line = <FILE>) )
|
||||
while ( defined( $line = <FILE> ) )
|
||||
{
|
||||
chomp $line;
|
||||
if ($line =~ s/\\$//)
|
||||
if ( $line =~ s/\\$// )
|
||||
{
|
||||
$line .= <FILE>;
|
||||
redo unless eof(FILE);
|
||||
@ -317,7 +317,7 @@ sub readConfigurationFile
|
||||
next if ( $line =~ /^([ \t]*)\#/ );
|
||||
|
||||
# Skip blank lines
|
||||
next if ( length( $line ) < 1 );
|
||||
next if ( length($line) < 1 );
|
||||
|
||||
# Strip trailing comments.
|
||||
if ( $line =~ /(.*)\#(.*)/ )
|
||||
@ -340,6 +340,7 @@ sub readConfigurationFile
|
||||
# command expansion?
|
||||
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
|
||||
{
|
||||
|
||||
# store
|
||||
my $pre = $1;
|
||||
my $cmd = $2;
|
||||
@ -347,18 +348,18 @@ sub readConfigurationFile
|
||||
|
||||
# get output
|
||||
my $output = `$cmd`;
|
||||
chomp( $output );
|
||||
chomp($output);
|
||||
|
||||
# build up replacement.
|
||||
$val = $pre . $output . $post;
|
||||
}
|
||||
|
||||
# Store value.
|
||||
$CONFIG{ $key } = $val;
|
||||
$CONFIG{$key} = $val;
|
||||
}
|
||||
}
|
||||
|
||||
close( FILE );
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
|
||||
@ -387,27 +388,27 @@ sub parseCommandLineArguments
|
||||
#
|
||||
GetOptions(
|
||||
|
||||
# Misc. options
|
||||
"add=s", \$CONFIG{'add'},
|
||||
"dir=s", \$install{'dir'},
|
||||
"lvm=s", \$install{'lvm'},
|
||||
"hostname=s", \$CONFIG{'hostname'},
|
||||
"force", \$CONFIG{'force'},
|
||||
# Misc. options
|
||||
"add=s", \$CONFIG{'add'},
|
||||
"dir=s", \$install{'dir'},
|
||||
"lvm=s", \$install{'lvm'},
|
||||
"hostname=s", \$CONFIG{'hostname'},
|
||||
"force", \$CONFIG{'force'},
|
||||
|
||||
# Help options
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"version", \$VERSION
|
||||
);
|
||||
# Help options
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"version", \$VERSION
|
||||
);
|
||||
|
||||
pod2usage(1) if $HELP;
|
||||
pod2usage(-verbose => 2 ) if $MANUAL;
|
||||
pod2usage( -verbose => 2 ) if $MANUAL;
|
||||
|
||||
|
||||
if ( $VERSION )
|
||||
if ($VERSION)
|
||||
{
|
||||
print( "xen-resize-guest release $RELEASE\n" );
|
||||
print("xen-resize-guest release $RELEASE\n");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
@ -442,6 +443,7 @@ sub parseCommandLineArguments
|
||||
|
||||
sub testArguments
|
||||
{
|
||||
|
||||
#
|
||||
# Make sure we received a hostname.
|
||||
#
|
||||
@ -486,8 +488,8 @@ EOF
|
||||
# We should either have LVM *or* directory - not neither or both.
|
||||
#
|
||||
my $options = 0;
|
||||
$options += 1if ( defined($CONFIG{'lvm'}) && length( $CONFIG{'lvm'} ) );
|
||||
$options += 1if ( defined($CONFIG{'dir'}) && length( $CONFIG{'dir'} ) );
|
||||
$options += 1 if ( defined( $CONFIG{'lvm'} ) && length( $CONFIG{'lvm'} ) );
|
||||
$options += 1 if ( defined( $CONFIG{'dir'} ) && length( $CONFIG{'dir'} ) );
|
||||
|
||||
#
|
||||
# Report
|
||||
@ -528,18 +530,18 @@ EOF
|
||||
|
||||
sub xenRunning
|
||||
{
|
||||
my( $hostname ) = (@_ );
|
||||
my ($hostname) = (@_);
|
||||
|
||||
my $running = 0;
|
||||
|
||||
open( CMD, "xm list $hostname 2>/dev/null |")
|
||||
open( CMD, "xm list $hostname 2>/dev/null |" )
|
||||
or die "Failed to run 'xm list $hostname'";
|
||||
while( <CMD> )
|
||||
while (<CMD>)
|
||||
{
|
||||
my $line = $_;
|
||||
$running = 1 if ( $line =~ /\Q$hostname\E/ )
|
||||
$running = 1 if ( $line =~ /\Q$hostname\E/ );
|
||||
}
|
||||
close( CMD );
|
||||
close(CMD);
|
||||
|
||||
return( $running );
|
||||
return ($running);
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ my $RELEASE = '3.9';
|
||||
#
|
||||
if ( -e "/etc/xen-tools/xen-tools.conf" )
|
||||
{
|
||||
readConfigurationFile( "/etc/xen-tools/xen-tools.conf" );
|
||||
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
|
||||
}
|
||||
|
||||
|
||||
@ -166,11 +166,11 @@ E_O_ROOT
|
||||
#
|
||||
# Loop over the supplied arguments, and attempt to update each image.
|
||||
#
|
||||
while( my $name = shift )
|
||||
while ( my $name = shift )
|
||||
{
|
||||
if ( !xenRunning( $name ) )
|
||||
if ( !xenRunning($name) )
|
||||
{
|
||||
updateXenImage( $name );
|
||||
updateXenImage($name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -196,7 +196,7 @@ exit;
|
||||
|
||||
sub updateXenImage
|
||||
{
|
||||
my ( $name ) = ( @_ );
|
||||
my ($name) = (@_);
|
||||
|
||||
#
|
||||
# Create a temporary directory, and prepare to mount the
|
||||
@ -212,10 +212,11 @@ sub updateXenImage
|
||||
#
|
||||
if ( $CONFIG{'dir'} )
|
||||
{
|
||||
# The loopback image.
|
||||
$img = $CONFIG{'dir'} . "/domains/" . $name . "/disk.img";
|
||||
|
||||
if ( ! -e $img )
|
||||
# The loopback image.
|
||||
$img = $CONFIG{'dir'} . "/domains/" . $name . "/disk.img";
|
||||
|
||||
if ( !-e $img )
|
||||
{
|
||||
print "Disk image '$img' for host '$name' not found\n";
|
||||
return;
|
||||
@ -225,11 +226,12 @@ sub updateXenImage
|
||||
}
|
||||
elsif ( $CONFIG{'lvm'} )
|
||||
{
|
||||
|
||||
# The LVM volume
|
||||
$img = "/dev/" . $CONFIG{'lvm'} . "/$name-disk";
|
||||
|
||||
# make sure it exists.
|
||||
if ( ! -e $img )
|
||||
if ( !-e $img )
|
||||
{
|
||||
print "Logical volume '$img' for host '$name' not found\n";
|
||||
return;
|
||||
@ -239,23 +241,24 @@ sub updateXenImage
|
||||
}
|
||||
elsif ( $CONFIG{'evms'} )
|
||||
{
|
||||
# The EVMS volume -- note, unlike LVM, you don't need the $CONFIG{'evms'}
|
||||
# to see it and mount the volume. $CONFIG{'evms'} is only used for manipulating
|
||||
# the underlying object. Still, I don't want to mess with the parse code and
|
||||
# make it confusing - otherwise --evms takes an argument everywhere but here,
|
||||
# which will confuse users. The better solution is to make it so that --evms can
|
||||
# take a following container, but doesn't require it. For the moment, it is
|
||||
# better to leave it as it is, take a container, and then ignore it.
|
||||
|
||||
# The best way to do it is to just read it out of the configuration file,
|
||||
# tell the user what you got and where you got it from, and not bother the user
|
||||
# with picking --dir or --lvm or --evms at all, but infer it from the config
|
||||
# file's disk = parameter. xen-delete-image might work the same way, but
|
||||
# it could be *slightly* more dangerous in the context of deleting.
|
||||
# The EVMS volume -- note, unlike LVM, you don't need the $CONFIG{'evms'}
|
||||
# to see it and mount the volume. $CONFIG{'evms'} is only used for manipulating
|
||||
# the underlying object. Still, I don't want to mess with the parse code and
|
||||
# make it confusing - otherwise --evms takes an argument everywhere but here,
|
||||
# which will confuse users. The better solution is to make it so that --evms can
|
||||
# take a following container, but doesn't require it. For the moment, it is
|
||||
# better to leave it as it is, take a container, and then ignore it.
|
||||
|
||||
# The best way to do it is to just read it out of the configuration file,
|
||||
# tell the user what you got and where you got it from, and not bother the user
|
||||
# with picking --dir or --lvm or --evms at all, but infer it from the config
|
||||
# file's disk = parameter. xen-delete-image might work the same way, but
|
||||
# it could be *slightly* more dangerous in the context of deleting.
|
||||
$img = "/dev/evms/$name-disk";
|
||||
|
||||
# make sure it exists.
|
||||
if ( ! -e $img )
|
||||
if ( !-e $img )
|
||||
{
|
||||
print "EVMS volume '$img' for host '$name' not found\n";
|
||||
return;
|
||||
@ -276,23 +279,26 @@ sub updateXenImage
|
||||
#
|
||||
# Make sure this is a Debian image.
|
||||
#
|
||||
if ( ( -e $tmp . "/usr/bin/apt-get" ) &&
|
||||
( -x $tmp . "/usr/bin/apt-get" ) )
|
||||
if ( ( -e $tmp . "/usr/bin/apt-get" )
|
||||
&& ( -x $tmp . "/usr/bin/apt-get" ) )
|
||||
{
|
||||
#
|
||||
# Now run the update command.
|
||||
#
|
||||
system( "chroot $tmp /usr/bin/apt-get update" );
|
||||
|
||||
#
|
||||
# Now run the update command.
|
||||
#
|
||||
system("chroot $tmp /usr/bin/apt-get update");
|
||||
|
||||
|
||||
#
|
||||
# Now upgrade
|
||||
#
|
||||
system( "DEBIAN_FRONTEND=noninteractive chroot $tmp /usr/bin/apt-get upgrade --yes --force-yes" );
|
||||
#
|
||||
# Now upgrade
|
||||
#
|
||||
system(
|
||||
"DEBIAN_FRONTEND=noninteractive chroot $tmp /usr/bin/apt-get upgrade --yes --force-yes"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Xen image $name is not a Debian GNU/Linux image. Skipping\n";
|
||||
print "Xen image $name is not a Debian GNU/Linux image. Skipping\n";
|
||||
}
|
||||
|
||||
|
||||
@ -306,8 +312,6 @@ sub updateXenImage
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Test to see if the given instance is running.
|
||||
@ -318,25 +322,24 @@ sub updateXenImage
|
||||
|
||||
sub xenRunning
|
||||
{
|
||||
my( $hostname ) = (@_ );
|
||||
my ($hostname) = (@_);
|
||||
|
||||
my $running = 0;
|
||||
|
||||
open( CMD, "xm list 2>/dev/null |")
|
||||
open( CMD, "xm list 2>/dev/null |" )
|
||||
or die "Failed to run 'xm list $hostname'";
|
||||
while( <CMD> )
|
||||
while (<CMD>)
|
||||
{
|
||||
my $line = $_;
|
||||
$running = 1 if ( $line =~ /\Q$hostname\E/ )
|
||||
$running = 1 if ( $line =~ /\Q$hostname\E/ );
|
||||
}
|
||||
close( CMD );
|
||||
close(CMD);
|
||||
|
||||
return( $running );
|
||||
return ($running);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Read the configuration file specified.
|
||||
@ -347,16 +350,16 @@ sub xenRunning
|
||||
|
||||
sub readConfigurationFile
|
||||
{
|
||||
my ($file) = ( @_ );
|
||||
my ($file) = (@_);
|
||||
|
||||
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
|
||||
|
||||
my $line = "";
|
||||
my $line = "";
|
||||
|
||||
while (defined($line = <FILE>) )
|
||||
while ( defined( $line = <FILE> ) )
|
||||
{
|
||||
chomp $line;
|
||||
if ($line =~ s/\\$//)
|
||||
if ( $line =~ s/\\$// )
|
||||
{
|
||||
$line .= <FILE>;
|
||||
redo unless eof(FILE);
|
||||
@ -366,7 +369,7 @@ sub readConfigurationFile
|
||||
next if ( $line =~ /^([ \t]*)\#/ );
|
||||
|
||||
# Skip blank lines
|
||||
next if ( length( $line ) < 1 );
|
||||
next if ( length($line) < 1 );
|
||||
|
||||
# Strip trailing comments.
|
||||
if ( $line =~ /(.*)\#(.*)/ )
|
||||
@ -389,6 +392,7 @@ sub readConfigurationFile
|
||||
# command expansion?
|
||||
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
|
||||
{
|
||||
|
||||
# store
|
||||
my $pre = $1;
|
||||
my $cmd = $2;
|
||||
@ -396,23 +400,22 @@ sub readConfigurationFile
|
||||
|
||||
# get output
|
||||
my $output = `$cmd`;
|
||||
chomp( $output );
|
||||
chomp($output);
|
||||
|
||||
# build up replacement.
|
||||
$val = $pre . $output . $post;
|
||||
}
|
||||
|
||||
# Store value.
|
||||
$CONFIG{ $key } = $val;
|
||||
$CONFIG{$key} = $val;
|
||||
}
|
||||
}
|
||||
|
||||
close( FILE );
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Parse the arguments specified upon the command line.
|
||||
@ -430,20 +433,17 @@ sub parseCommandLineArguments
|
||||
# Parse options.
|
||||
#
|
||||
GetOptions(
|
||||
"dir=s", \$CONFIG{'dir'},
|
||||
"lvm=s", \$CONFIG{'lvm'},
|
||||
"evms=s", \$CONFIG{'evms'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
"dir=s", \$CONFIG{'dir'}, "lvm=s", \$CONFIG{'lvm'},
|
||||
"evms=s", \$CONFIG{'evms'}, "help", \$HELP,
|
||||
"manual", \$MANUAL, "version", \$VERSION
|
||||
);
|
||||
|
||||
pod2usage(1) if $HELP;
|
||||
pod2usage(-verbose => 2 ) if $MANUAL;
|
||||
pod2usage( -verbose => 2 ) if $MANUAL;
|
||||
|
||||
if ( $VERSION )
|
||||
if ($VERSION)
|
||||
{
|
||||
my $REVISION = '$Revision: 1.29 $';
|
||||
my $REVISION = '$Revision: 1.29 $';
|
||||
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
@ -468,11 +468,12 @@ sub parseCommandLineArguments
|
||||
|
||||
sub checkArguments
|
||||
{
|
||||
|
||||
#
|
||||
# Make sure we got one and only one installation method.
|
||||
#
|
||||
my $count = 0;
|
||||
foreach my $type ( qw/dir lvm evms/ )
|
||||
foreach my $type (qw/dir lvm evms/)
|
||||
{
|
||||
$count += 1 if defined( $CONFIG{$type} );
|
||||
}
|
||||
@ -483,10 +484,10 @@ sub checkArguments
|
||||
#
|
||||
if ( $count != 1 )
|
||||
{
|
||||
print "Please select one and only one of the installation methods:\n";
|
||||
print " --dir\n";
|
||||
print " --evms\n";
|
||||
print " --lvm\n";
|
||||
exit;
|
||||
print "Please select one and only one of the installation methods:\n";
|
||||
print " --dir\n";
|
||||
print " --evms\n";
|
||||
print " --lvm\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,7 +160,6 @@ my $RELEASE = '3.9';
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Parse the command line arguments.
|
||||
#
|
||||
@ -189,9 +188,6 @@ createXenConfig();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Exit cleanly - any errors which have already occurred will result
|
||||
# in "exit 1".
|
||||
@ -200,9 +196,6 @@ exit 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Parse the command line arguments this script was given.
|
||||
@ -221,23 +214,23 @@ sub parseCommandLineArguments
|
||||
# Parse options.
|
||||
#
|
||||
GetOptions(
|
||||
"admins=s", \$ENV{'admins'},
|
||||
"output=s", \$CONFIG{'output'},
|
||||
"extension=s",\$CONFIG{'extension'},
|
||||
"template=s", \$CONFIG{'template'},
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
"admins=s", \$ENV{'admins'},
|
||||
"output=s", \$CONFIG{'output'},
|
||||
"extension=s", \$CONFIG{'extension'},
|
||||
"template=s", \$CONFIG{'template'},
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
|
||||
pod2usage(1) if $HELP;
|
||||
pod2usage(-verbose => 2 ) if $MANUAL;
|
||||
pod2usage( -verbose => 2 ) if $MANUAL;
|
||||
|
||||
|
||||
if ( $VERSION )
|
||||
if ($VERSION)
|
||||
{
|
||||
my $REVISION = '$Revision: 1.47 $';
|
||||
my $REVISION = '$Revision: 1.47 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
@ -260,10 +253,11 @@ sub parseCommandLineArguments
|
||||
|
||||
sub checkArguments
|
||||
{
|
||||
|
||||
#
|
||||
# We require an output location.
|
||||
#
|
||||
if ( ! defined( $CONFIG{'output'} ) )
|
||||
if ( !defined( $CONFIG{'output'} ) )
|
||||
{
|
||||
print "The '--output' argument is mandatory\n";
|
||||
exit 1;
|
||||
@ -272,9 +266,10 @@ sub checkArguments
|
||||
#
|
||||
# The output location should be a directory which exists.
|
||||
#
|
||||
if ( ! -d $CONFIG{'output'} )
|
||||
if ( !-d $CONFIG{'output'} )
|
||||
{
|
||||
print "The output directory we've been given, $CONFIG{'output'}, doesnt exist\n";
|
||||
print
|
||||
"The output directory we've been given, $CONFIG{'output'}, doesnt exist\n";
|
||||
print "Aborting\n";
|
||||
exit 1;
|
||||
}
|
||||
@ -284,9 +279,10 @@ sub checkArguments
|
||||
#
|
||||
if ( defined( $CONFIG{'template'} ) )
|
||||
{
|
||||
if ( ! -e $CONFIG{'template'} )
|
||||
if ( !-e $CONFIG{'template'} )
|
||||
{
|
||||
print "The specified template file, $CONFIG{'template'} does not exist.\n";
|
||||
print
|
||||
"The specified template file, $CONFIG{'template'} does not exist.\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
@ -310,19 +306,20 @@ sub importPartitionsFromEnvironment
|
||||
{
|
||||
@PARTITIONS = ();
|
||||
|
||||
for (my $i=1; $i <= $ENV{'NUMPARTITIONS'}; $i++)
|
||||
for ( my $i = 1 ; $i <= $ENV{'NUMPARTITIONS'} ; $i++ )
|
||||
{
|
||||
my @parts = split(/:/, $ENV{'PARTITION' . $i}, 7);
|
||||
push( @PARTITIONS,
|
||||
{
|
||||
'name' => $parts[0],
|
||||
'size' => $parts[1],
|
||||
'type' => $parts[2],
|
||||
'mountpoint' => $parts[3],
|
||||
'options' => $parts[4],
|
||||
'imagetype' => $parts[5],
|
||||
'image' => $parts[6]
|
||||
}
|
||||
my @parts = split( /:/, $ENV{'PARTITION' . $i}, 7 );
|
||||
push(
|
||||
@PARTITIONS,
|
||||
{
|
||||
'name' => $parts[0],
|
||||
'size' => $parts[1],
|
||||
'type' => $parts[2],
|
||||
'mountpoint' => $parts[3],
|
||||
'options' => $parts[4],
|
||||
'imagetype' => $parts[5],
|
||||
'image' => $parts[6]
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -341,6 +338,7 @@ sub importPartitionsFromEnvironment
|
||||
|
||||
sub createXenConfig
|
||||
{
|
||||
|
||||
#
|
||||
# The output file we're going to process.
|
||||
#
|
||||
@ -416,7 +414,7 @@ sub createXenConfig
|
||||
}
|
||||
else
|
||||
{
|
||||
$ENV{'swap_vbd'} = undef;
|
||||
$ENV{'swap_vbd'} = undef;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -438,7 +436,7 @@ sub createXenConfig
|
||||
# made available to our template file.
|
||||
#
|
||||
my %vars;
|
||||
foreach my $key (sort keys %ENV )
|
||||
foreach my $key ( sort keys %ENV )
|
||||
{
|
||||
$vars{$key} = $ENV{$key};
|
||||
}
|
||||
@ -457,9 +455,9 @@ sub createXenConfig
|
||||
#
|
||||
# Write the output of processing the template file, if it succeeds.
|
||||
#
|
||||
if (defined $result)
|
||||
if ( defined $result )
|
||||
{
|
||||
print FILE $result ;
|
||||
print FILE $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -469,13 +467,12 @@ sub createXenConfig
|
||||
#
|
||||
# Close the output file.
|
||||
#
|
||||
close( FILE );
|
||||
close(FILE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
This routine is designed to ensure that any users specified with
|
||||
@ -487,6 +484,7 @@ sub createXenConfig
|
||||
|
||||
sub setupAdminUsers
|
||||
{
|
||||
|
||||
#
|
||||
# If we're not root we can't modify users.
|
||||
#
|
||||
@ -495,16 +493,17 @@ sub setupAdminUsers
|
||||
#
|
||||
# If we don't have a sudoers file then we'll also ignore this.
|
||||
#
|
||||
return if ( ! -e "/etc/sudoers" );
|
||||
return if ( !-e "/etc/sudoers" );
|
||||
|
||||
#
|
||||
# Find the path to the xen-login-shell
|
||||
#
|
||||
my $shell = undef;
|
||||
$shell = "/usr/bin/xen-login-shell" if ( -x "/usr/bin/xen-login-shell" );
|
||||
$shell = "/usr/local/bin/xen-login-shell" if ( -x "/usr/bin/local/xen-login-shell" );
|
||||
$shell = "/usr/local/bin/xen-login-shell"
|
||||
if ( -x "/usr/bin/local/xen-login-shell" );
|
||||
|
||||
return if ( !defined( $shell ) );
|
||||
return if ( !defined($shell) );
|
||||
|
||||
|
||||
#
|
||||
@ -513,6 +512,7 @@ sub setupAdminUsers
|
||||
#
|
||||
foreach my $user ( split( /,/, $ENV{'admins'} ) )
|
||||
{
|
||||
|
||||
# Strip leading and trailing whitespace.
|
||||
$user =~ s/^\s+//;
|
||||
$user =~ s/\s+$//;
|
||||
@ -523,12 +523,14 @@ sub setupAdminUsers
|
||||
# Does the user exist?
|
||||
if ( getpwnam($user) )
|
||||
{
|
||||
|
||||
# Change shell.
|
||||
$CONFIG{'verbose'} && print "Changing shell for $user: $shell\n";
|
||||
system( "chsh", "-s", $shell, $user );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
# Add a new user.
|
||||
$CONFIG{'verbose'} && print "Adding new user: $user\n";
|
||||
system( "useradd", "-s", $shell, $user );
|
||||
@ -537,9 +539,11 @@ sub setupAdminUsers
|
||||
#
|
||||
# Add the entry to /etc/sudoers.
|
||||
#
|
||||
open( SUDOERS, ">>", "/etc/sudoers" ) or warn "Failed to add user to sudoers file : $user - $!";
|
||||
print SUDOERS "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n";
|
||||
close( SUDOERS );
|
||||
open( SUDOERS, ">>", "/etc/sudoers" )
|
||||
or warn "Failed to add user to sudoers file : $user - $!";
|
||||
print SUDOERS
|
||||
"$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n";
|
||||
close(SUDOERS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +101,6 @@ my $RELEASE = '3.9';
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Parse the command line arguments.
|
||||
#
|
||||
@ -128,9 +127,6 @@ exit 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Parse the command line arguments this script was given.
|
||||
@ -149,28 +145,28 @@ sub parseCommandLineArguments
|
||||
# Parse options.
|
||||
#
|
||||
GetOptions(
|
||||
"location=s", \$CONFIG{'location'},
|
||||
"dist=s", \$CONFIG{'dist'},
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
"location=s", \$CONFIG{'location'},
|
||||
"dist=s", \$CONFIG{'dist'},
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
|
||||
pod2usage(1) if $HELP;
|
||||
pod2usage(-verbose => 2 ) if $MANUAL;
|
||||
pod2usage( -verbose => 2 ) if $MANUAL;
|
||||
|
||||
|
||||
if ( $VERSION )
|
||||
if ($VERSION)
|
||||
{
|
||||
my $REVISION = '$Revision: 1.33 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
}
|
||||
my $REVISION = '$Revision: 1.33 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
}
|
||||
|
||||
print "xt-customize-image release $RELEASE - CVS: $REVISION\n";
|
||||
exit;
|
||||
print "xt-customize-image release $RELEASE - CVS: $REVISION\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,10 +182,11 @@ sub parseCommandLineArguments
|
||||
|
||||
sub checkArguments
|
||||
{
|
||||
|
||||
#
|
||||
# We require a location.
|
||||
#
|
||||
if ( ! defined( $CONFIG{'location'} ) )
|
||||
if ( !defined( $CONFIG{'location'} ) )
|
||||
{
|
||||
print "The '--location' argument is mandatory\n";
|
||||
exit 1;
|
||||
@ -199,7 +196,7 @@ sub checkArguments
|
||||
#
|
||||
# Test that the location we've been given exists
|
||||
#
|
||||
if ( ! -d $CONFIG{'location'} )
|
||||
if ( !-d $CONFIG{'location'} )
|
||||
{
|
||||
print "The installation directory we've been given doesn't exist\n";
|
||||
print "We tried to use : $CONFIG{'location'}\n";
|
||||
@ -210,7 +207,7 @@ sub checkArguments
|
||||
#
|
||||
# We require a distribution name.
|
||||
#
|
||||
if ( ! defined( $CONFIG{'dist'} ) )
|
||||
if ( !defined( $CONFIG{'dist'} ) )
|
||||
{
|
||||
print "The '--dist' argument is mandatory\n";
|
||||
exit 1;
|
||||
@ -224,9 +221,9 @@ sub checkArguments
|
||||
# If there are no scripts then we clearly cannot
|
||||
# customise it!
|
||||
#
|
||||
my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d";
|
||||
my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d";
|
||||
|
||||
if ( ! -d $dir )
|
||||
if ( !-d $dir )
|
||||
{
|
||||
print <<E_OR;
|
||||
|
||||
@ -262,10 +259,11 @@ E_OR
|
||||
|
||||
sub runDistributionHooks
|
||||
{
|
||||
|
||||
#
|
||||
# Hook directory.
|
||||
#
|
||||
my $hooks = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d/";
|
||||
my $hooks = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d/";
|
||||
|
||||
#
|
||||
# Installation prefix
|
||||
@ -290,6 +288,7 @@ sub runDistributionHooks
|
||||
#
|
||||
foreach my $file ( sort( glob( $hooks . "*" ) ) )
|
||||
{
|
||||
|
||||
# skip files that end with .dpkg-new, .dpkg-old or '~'
|
||||
next if ( $file =~ /\.dpkg-(new|old)/ );
|
||||
next if ( $file =~ /~$/ );
|
||||
@ -299,6 +298,7 @@ sub runDistributionHooks
|
||||
#
|
||||
if ( ( -x $file ) && ( -f $file ) )
|
||||
{
|
||||
|
||||
#
|
||||
# Just display the name - no need to see the full path.
|
||||
#
|
||||
@ -321,14 +321,14 @@ sub runDistributionHooks
|
||||
{
|
||||
print "Running hook $name ['$cmd']\n";
|
||||
print "--\n";
|
||||
system( $cmd );
|
||||
system($cmd );
|
||||
print "--\n";
|
||||
print "Done\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Running hook $name\n";
|
||||
system( $cmd );
|
||||
system($cmd );
|
||||
print "hook $name: done.\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,50 +127,41 @@ my $RELEASE = '3.9';
|
||||
# needDirectory Defined if we need an install-source directory specified.
|
||||
#
|
||||
#
|
||||
my %dispatch =
|
||||
(
|
||||
"copy" =>
|
||||
{
|
||||
sub => \&do_copy,
|
||||
needBinary => "/bin/cp",
|
||||
needDirectory => 1,
|
||||
},
|
||||
"debootstrap" =>
|
||||
{
|
||||
sub => \&do_debootstrap,
|
||||
needBinary => "/usr/sbin/debootstrap",
|
||||
},
|
||||
"image-server" =>
|
||||
{
|
||||
sub => \&do_image_server,
|
||||
needURL => 1,
|
||||
},
|
||||
"rinse" =>
|
||||
{
|
||||
sub => \&do_rinse,
|
||||
needBinary => "/usr/bin/rinse",
|
||||
},
|
||||
"rpmstrap" =>
|
||||
{
|
||||
sub => \&do_rpmstrap,
|
||||
needBinary => "/usr/bin/rpmstrap",
|
||||
},
|
||||
"tar" =>
|
||||
{
|
||||
sub => \&do_tar,
|
||||
needBinary => "/bin/tar",
|
||||
needFile => 1,
|
||||
}
|
||||
my %dispatch = (
|
||||
"copy" => {
|
||||
sub => \&do_copy,
|
||||
needBinary => "/bin/cp",
|
||||
needDirectory => 1,
|
||||
},
|
||||
"debootstrap" => {
|
||||
sub => \&do_debootstrap,
|
||||
needBinary => "/usr/sbin/debootstrap",
|
||||
},
|
||||
"image-server" => {
|
||||
sub => \&do_image_server,
|
||||
needURL => 1,
|
||||
},
|
||||
"rinse" => {
|
||||
sub => \&do_rinse,
|
||||
needBinary => "/usr/bin/rinse",
|
||||
},
|
||||
"rpmstrap" => {
|
||||
sub => \&do_rpmstrap,
|
||||
needBinary => "/usr/bin/rpmstrap",
|
||||
},
|
||||
"tar" => {
|
||||
sub => \&do_tar,
|
||||
needBinary => "/bin/tar",
|
||||
needFile => 1,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Read the global configuration file.
|
||||
#
|
||||
readConfigurationFile( "/etc/xen-tools/xen-tools.conf" );
|
||||
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
|
||||
|
||||
|
||||
#
|
||||
@ -193,7 +184,7 @@ if ( $CONFIG{'config'} )
|
||||
}
|
||||
|
||||
# Read the file, if it exists.
|
||||
readConfigurationFile( $path ) if ( -e $path );
|
||||
readConfigurationFile($path) if ( -e $path );
|
||||
}
|
||||
|
||||
|
||||
@ -206,59 +197,65 @@ checkArguments();
|
||||
#
|
||||
# Now lookup our installation type and dispatch control to it.
|
||||
#
|
||||
if ( defined( $CONFIG{'install-method'} ) &&
|
||||
length( $CONFIG{'install-method'} ) )
|
||||
if ( defined( $CONFIG{'install-method'} )
|
||||
&& length( $CONFIG{'install-method'} ) )
|
||||
{
|
||||
|
||||
#
|
||||
# Get the entry from the dispatch table.
|
||||
#
|
||||
my $installer = $dispatch{ lc($CONFIG{'install-method'}) };
|
||||
my $installer = $dispatch{lc( $CONFIG{'install-method'} )};
|
||||
|
||||
if ( defined( $installer ) )
|
||||
if ( defined($installer) )
|
||||
{
|
||||
|
||||
#
|
||||
# If we found it.
|
||||
#
|
||||
|
||||
# Do we need to test for a binary.
|
||||
if ( ( $installer->{'needBinary'} ) &&
|
||||
( ! -x $installer->{'needBinary'} ) )
|
||||
if ( ( $installer->{'needBinary'} )
|
||||
&& ( !-x $installer->{'needBinary'} ) )
|
||||
{
|
||||
print "The following required binary for the installation was not found\n";
|
||||
print
|
||||
"The following required binary for the installation was not found\n";
|
||||
print "\t" . $installer->{'needBinary'} . "\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Do we need a directory specified as the installation source?
|
||||
if ( ( $installer->{'needDirectory'} ) &&
|
||||
( ! $CONFIG{'install-source'} || ! -d $CONFIG{'install-source'} ) )
|
||||
if ( ( $installer->{'needDirectory'} )
|
||||
&& ( !$CONFIG{'install-source'} || !-d $CONFIG{'install-source'} ) )
|
||||
{
|
||||
print "Please specify the source directory with --install-source\n";
|
||||
if ( $CONFIG{'install-source'} )
|
||||
{
|
||||
print "The specified directory $CONFIG{'install-source'} does not exist.\n";
|
||||
print
|
||||
"The specified directory $CONFIG{'install-source'} does not exist.\n";
|
||||
}
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Do we need a file specified as the installation source?
|
||||
if ( ( $installer->{'needFile'} ) &&
|
||||
( ! $CONFIG{'install-source'} || ! -e $CONFIG{'install-source'} ) )
|
||||
if ( ( $installer->{'needFile'} )
|
||||
&& ( !$CONFIG{'install-source'} || !-e $CONFIG{'install-source'} ) )
|
||||
{
|
||||
print "Please specify the source file with --install-source\n";
|
||||
|
||||
if ( $CONFIG{'install-source'} )
|
||||
{
|
||||
print "The specified file $CONFIG{'install-source'} does not exist.\n";
|
||||
print
|
||||
"The specified file $CONFIG{'install-source'} does not exist.\n";
|
||||
}
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Do we need an URL specified as the installation source?
|
||||
if ( ( $installer->{'needURL'} ) &&
|
||||
( ! $CONFIG{'install-source'} ||
|
||||
( $CONFIG{'install-source'} !~ /^http/i ) ) )
|
||||
if (
|
||||
( $installer->{'needURL'} )
|
||||
&& ( !$CONFIG{'install-source'}
|
||||
|| ( $CONFIG{'install-source'} !~ /^http/i ) )
|
||||
)
|
||||
{
|
||||
print "Please specify the image server URL with --install-source\n";
|
||||
exit 1;
|
||||
@ -276,9 +273,9 @@ if ( defined( $CONFIG{'install-method'} ) &&
|
||||
#
|
||||
# Test that we have some "standard" files present.
|
||||
#
|
||||
foreach my $file ( qw( /bin/ls /bin/cp ) )
|
||||
foreach my $file (qw( /bin/ls /bin/cp ))
|
||||
{
|
||||
if ( ! -x $CONFIG{'location'} . $file )
|
||||
if ( !-x $CONFIG{'location'} . $file )
|
||||
{
|
||||
print "The installation of the new system has failed.\n";
|
||||
print "\n";
|
||||
@ -306,10 +303,6 @@ else
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Read the specified configuration file, and update our global configuration
|
||||
@ -321,20 +314,20 @@ else
|
||||
|
||||
sub readConfigurationFile
|
||||
{
|
||||
my ($file) = ( @_ );
|
||||
my ($file) = (@_);
|
||||
|
||||
# Don't read the file if it doesn't exist.
|
||||
return if ( ! -e $file );
|
||||
return if ( !-e $file );
|
||||
|
||||
|
||||
my $line = "";
|
||||
|
||||
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
|
||||
|
||||
while (defined($line = <FILE>) )
|
||||
while ( defined( $line = <FILE> ) )
|
||||
{
|
||||
chomp $line;
|
||||
if ($line =~ s/\\$//)
|
||||
if ( $line =~ s/\\$// )
|
||||
{
|
||||
$line .= <FILE>;
|
||||
redo unless eof(FILE);
|
||||
@ -344,7 +337,7 @@ sub readConfigurationFile
|
||||
next if ( $line =~ /^([ \t]*)\#/ );
|
||||
|
||||
# Skip blank lines
|
||||
next if ( length( $line ) < 1 );
|
||||
next if ( length($line) < 1 );
|
||||
|
||||
# Strip trailing comments.
|
||||
if ( $line =~ /(.*)\#(.*)/ )
|
||||
@ -367,6 +360,7 @@ sub readConfigurationFile
|
||||
# command expansion?
|
||||
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
|
||||
{
|
||||
|
||||
# store
|
||||
my $pre = $1;
|
||||
my $cmd = $2;
|
||||
@ -374,18 +368,18 @@ sub readConfigurationFile
|
||||
|
||||
# get output
|
||||
my $output = `$cmd`;
|
||||
chomp( $output );
|
||||
chomp($output);
|
||||
|
||||
# build up replacement.
|
||||
$val = $pre . $output . $post;
|
||||
}
|
||||
|
||||
# Store value.
|
||||
$CONFIG{ $key } = $val;
|
||||
$CONFIG{$key} = $val;
|
||||
}
|
||||
}
|
||||
|
||||
close( FILE );
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
|
||||
@ -408,35 +402,36 @@ sub parseCommandLineArguments
|
||||
# Parse options.
|
||||
#
|
||||
GetOptions(
|
||||
# Mandatory
|
||||
"location=s", \$CONFIG{'location'},
|
||||
"dist=s", \$CONFIG{'dist'},
|
||||
"hostname=s", \$CONFIG{'hostname'},
|
||||
|
||||
# Installation method
|
||||
"install-method=s", \$CONFIG{'install-method'},
|
||||
"install-source=s", \$CONFIG{'install-source'},
|
||||
# Mandatory
|
||||
"location=s", \$CONFIG{'location'},
|
||||
"dist=s", \$CONFIG{'dist'},
|
||||
"hostname=s", \$CONFIG{'hostname'},
|
||||
|
||||
# Misc
|
||||
"arch=s", \$CONFIG{'arch'},
|
||||
"cache=s", \$CONFIG{'cache'},
|
||||
"config=s", \$CONFIG{'config'},
|
||||
"mirror=s", \$CONFIG{'mirror'},
|
||||
# Installation method
|
||||
"install-method=s", \$CONFIG{'install-method'},
|
||||
"install-source=s", \$CONFIG{'install-source'},
|
||||
|
||||
# Help.
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
# Misc
|
||||
"arch=s", \$CONFIG{'arch'},
|
||||
"cache=s", \$CONFIG{'cache'},
|
||||
"config=s", \$CONFIG{'config'},
|
||||
"mirror=s", \$CONFIG{'mirror'},
|
||||
|
||||
# Help.
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
"help", \$HELP,
|
||||
"manual", \$MANUAL,
|
||||
"version", \$VERSION
|
||||
);
|
||||
|
||||
pod2usage(1) if $HELP;
|
||||
pod2usage(-verbose => 2 ) if $MANUAL;
|
||||
pod2usage( -verbose => 2 ) if $MANUAL;
|
||||
|
||||
|
||||
if ( $VERSION )
|
||||
if ($VERSION)
|
||||
{
|
||||
my $REVISION = '$Revision: 1.65 $';
|
||||
my $REVISION = '$Revision: 1.65 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
@ -459,10 +454,11 @@ sub parseCommandLineArguments
|
||||
|
||||
sub checkArguments
|
||||
{
|
||||
|
||||
#
|
||||
# We require a location.
|
||||
#
|
||||
if ( ! defined( $CONFIG{'location'} ) )
|
||||
if ( !defined( $CONFIG{'location'} ) )
|
||||
{
|
||||
print "The '--location' argument is mandatory\n";
|
||||
exit 1;
|
||||
@ -472,7 +468,7 @@ sub checkArguments
|
||||
#
|
||||
# Test that the location we've been given exists
|
||||
#
|
||||
if ( ! -d $CONFIG{'location'} )
|
||||
if ( !-d $CONFIG{'location'} )
|
||||
{
|
||||
print "The installation directory we've been given doesn't exist\n";
|
||||
print "We tried to use : $CONFIG{'location'}\n";
|
||||
@ -483,7 +479,7 @@ sub checkArguments
|
||||
#
|
||||
# We require a distribution name.
|
||||
#
|
||||
if ( ! defined( $CONFIG{'dist'} ) )
|
||||
if ( !defined( $CONFIG{'dist'} ) )
|
||||
{
|
||||
print "The '--dist' argument is mandatory\n";
|
||||
exit 1;
|
||||
@ -497,9 +493,9 @@ sub checkArguments
|
||||
# If there are no scripts then we clearly cannot
|
||||
# customise it!
|
||||
#
|
||||
my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d";
|
||||
my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d";
|
||||
|
||||
if ( ! -d $dir )
|
||||
if ( !-d $dir )
|
||||
{
|
||||
print <<E_OR;
|
||||
|
||||
@ -524,7 +520,8 @@ E_OR
|
||||
{
|
||||
foreach my $recognised ( keys %dispatch )
|
||||
{
|
||||
$valid = 1 if ( lc($CONFIG{'install-method'}) eq lc($recognised) );
|
||||
$valid = 1
|
||||
if ( lc( $CONFIG{'install-method'} ) eq lc($recognised) );
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -552,7 +549,6 @@ EOF
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
A utility method to run a system command. We will capture the return
|
||||
@ -566,7 +562,7 @@ EOF
|
||||
|
||||
sub runCommand
|
||||
{
|
||||
my ( $cmd ) = (@_ );
|
||||
my ($cmd) = (@_);
|
||||
|
||||
#
|
||||
# Command start.
|
||||
@ -595,12 +591,11 @@ sub runCommand
|
||||
#
|
||||
$CONFIG{'verbose'} && print "Finished : $cmd\n";
|
||||
|
||||
return( $output );
|
||||
return ($output);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
This function will copy all the .deb files from one directory
|
||||
@ -613,7 +608,7 @@ sub runCommand
|
||||
|
||||
sub copyDebFiles
|
||||
{
|
||||
my ( $source, $dest ) = ( @_ );
|
||||
my ( $source, $dest ) = (@_);
|
||||
|
||||
print "Copying files from $source -> $dest\n";
|
||||
|
||||
@ -631,7 +626,7 @@ sub copyDebFiles
|
||||
#
|
||||
# Only copy if the file doesn't already exist.
|
||||
#
|
||||
if ( ! ( -e $dest . "/" . $name ) )
|
||||
if ( !( -e $dest . "/" . $name ) )
|
||||
{
|
||||
File::Copy::cp( $file, $dest );
|
||||
}
|
||||
@ -642,8 +637,6 @@ sub copyDebFiles
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Installation functions follow.
|
||||
@ -652,7 +645,6 @@ sub copyDebFiles
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Install a new image of a distribution using `cp`.
|
||||
@ -663,14 +655,15 @@ sub copyDebFiles
|
||||
|
||||
sub do_copy
|
||||
{
|
||||
|
||||
#
|
||||
# Find the copy command to run from the configuration file.
|
||||
#
|
||||
my $cmd = $CONFIG{'copy-cmd'} ;
|
||||
if ( !defined( $cmd ) )
|
||||
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.
|
||||
$cmd = '/bin/cp -a $src/* $dest'; # Note: single quotes.
|
||||
}
|
||||
|
||||
#
|
||||
@ -682,12 +675,11 @@ sub do_copy
|
||||
#
|
||||
# Run the copy command.
|
||||
#
|
||||
runCommand( $cmd );
|
||||
runCommand($cmd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Install a new image of Debian using 'debootstrap'.
|
||||
@ -698,12 +690,13 @@ sub do_copy
|
||||
|
||||
sub do_debootstrap
|
||||
{
|
||||
|
||||
#
|
||||
# The command is a little configurable - mostly to allow you
|
||||
# to use cdebootstrap.
|
||||
#
|
||||
my $cmd = $CONFIG{'debootstrap-cmd'} ;
|
||||
if ( !defined( $cmd ) )
|
||||
my $cmd = $CONFIG{'debootstrap-cmd'};
|
||||
if ( !defined($cmd) )
|
||||
{
|
||||
print "Falling back to default debootstrap command\n";
|
||||
$cmd = '/usr/sbin/debootstrap';
|
||||
@ -717,9 +710,10 @@ sub do_debootstrap
|
||||
if ( $CONFIG{'cache'} eq "yes" )
|
||||
{
|
||||
print "\nCopying files from host to image.\n";
|
||||
runCommand( "mkdir -p $CONFIG{'location'}/var/cache/apt/archives" );
|
||||
copyDebFiles( "/var/cache/apt/archives", "$CONFIG{'location'}/var/cache/apt/archives" );
|
||||
print( "Done\n" );
|
||||
runCommand("mkdir -p $CONFIG{'location'}/var/cache/apt/archives");
|
||||
copyDebFiles( "/var/cache/apt/archives",
|
||||
"$CONFIG{'location'}/var/cache/apt/archives" );
|
||||
print("Done\n");
|
||||
}
|
||||
|
||||
#
|
||||
@ -736,19 +730,20 @@ sub do_debootstrap
|
||||
#
|
||||
if ( $CONFIG{'arch'} )
|
||||
{
|
||||
$EXTRA .= " --arch $CONFIG{'arch'}"
|
||||
$EXTRA .= " --arch $CONFIG{'arch'}";
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# This is the command we'll run
|
||||
#
|
||||
my $command = "$cmd $EXTRA $CONFIG{'dist'} $CONFIG{'location'} $CONFIG{'mirror'}";
|
||||
my $command =
|
||||
"$cmd $EXTRA $CONFIG{'dist'} $CONFIG{'location'} $CONFIG{'mirror'}";
|
||||
|
||||
#
|
||||
# Run the command.
|
||||
#
|
||||
runCommand( $command );
|
||||
runCommand($command);
|
||||
|
||||
|
||||
#
|
||||
@ -760,7 +755,7 @@ sub do_debootstrap
|
||||
print "\nCopying files from new installation to host.\n";
|
||||
copyDebFiles( "$CONFIG{'location'}/var/cache/apt/archives",
|
||||
"/var/cache/apt/archives" );
|
||||
print( "Done\n" );
|
||||
print("Done\n");
|
||||
}
|
||||
|
||||
|
||||
@ -768,7 +763,6 @@ sub do_debootstrap
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Install a system using the image-server.
|
||||
@ -781,6 +775,7 @@ sub do_debootstrap
|
||||
|
||||
sub do_image_server
|
||||
{
|
||||
|
||||
#
|
||||
# Load the modules we require.
|
||||
#
|
||||
@ -793,8 +788,8 @@ sub do_image_server
|
||||
# which users will not require for the typical installation
|
||||
# method(s).
|
||||
#
|
||||
eval( $test );
|
||||
if ( $@ )
|
||||
eval($test);
|
||||
if ($@)
|
||||
{
|
||||
die "The module LDP::UserAgent wasn't found...\n";
|
||||
}
|
||||
@ -818,15 +813,16 @@ sub do_image_server
|
||||
#
|
||||
$request .= "&arch=amd64";
|
||||
$request .= "&root_device=/dev/sda";
|
||||
$request .= "&ip1=" . $ENV{'ip1'};
|
||||
$request .= "&dist=" . CGI::escapeHTML( $CONFIG{'dist'} );
|
||||
$request .= "&ip1=" . $ENV{'ip1'};
|
||||
$request .= "&dist=" . CGI::escapeHTML( $CONFIG{'dist'} );
|
||||
$request .= "&hostname=" . CGI::escapeHTML( $CONFIG{'hostname'} );
|
||||
|
||||
#
|
||||
# We only care about some keys
|
||||
#
|
||||
foreach my $k ( qw/ dhcp broadcast gateway netmask / )
|
||||
foreach my $k (qw/ dhcp broadcast gateway netmask /)
|
||||
{
|
||||
|
||||
# Skip values which aren't defined.
|
||||
next unless defined $ENV{$k};
|
||||
|
||||
@ -848,8 +844,8 @@ sub do_image_server
|
||||
#
|
||||
# Do the creation step
|
||||
#
|
||||
my $response = $ua->get( $request );
|
||||
if ($response->is_success)
|
||||
my $response = $ua->get($request);
|
||||
if ( $response->is_success )
|
||||
{
|
||||
my $content = $response->content;
|
||||
|
||||
@ -857,70 +853,74 @@ sub do_image_server
|
||||
{
|
||||
my $session = $1;
|
||||
my $new = $CONFIG{'install-source'};
|
||||
$new .= "/fetch.cgi?session=$session";
|
||||
$new .= "/fetch.cgi?session=$session";
|
||||
my $attempt = 1;
|
||||
|
||||
# Make sure we don't wait indefinitely.
|
||||
while( $attempt < $attempts )
|
||||
while ( $attempt < $attempts )
|
||||
{
|
||||
$CONFIG{'verbose'} && print "Request: [$attempt/$attempts]\n";
|
||||
|
||||
#
|
||||
# Make a request to see if our tar file is ready yet.
|
||||
#
|
||||
$response = $ua->head( $new );
|
||||
$response = $ua->head($new);
|
||||
if ( $response->is_success )
|
||||
{
|
||||
|
||||
#
|
||||
# Get the headers
|
||||
#
|
||||
my $header = $response->headers();
|
||||
my $type = $header->{'content-type'};
|
||||
my $header = $response->headers();
|
||||
my $type = $header->{'content-type'};
|
||||
|
||||
#
|
||||
# OK our file is correct.
|
||||
#
|
||||
if ( $type =~ /tar/ )
|
||||
{
|
||||
|
||||
#
|
||||
# Download it to the installation root.
|
||||
#
|
||||
$ua->get( $new,
|
||||
":content_file" => $CONFIG{'location'} . "/$session.tar"
|
||||
);
|
||||
":content_file" => $CONFIG{'location'}
|
||||
. "/$session.tar" );
|
||||
|
||||
#
|
||||
# If it worked .. then untar, remove, and return.
|
||||
#
|
||||
system( "cd $CONFIG{'location'} && tar --numeric-owner -xf $session.tar && rm -f $CONFIG{'location'}/$session.tar" );
|
||||
system(
|
||||
"cd $CONFIG{'location'} && tar --numeric-owner -xf $session.tar && rm -f $CONFIG{'location'}/$session.tar"
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
sleep( $sleep );
|
||||
sleep($sleep);
|
||||
$attempt += 1;
|
||||
|
||||
}
|
||||
print ( "ERROR: Timeout waiting for image to be ready." );
|
||||
print("ERROR: Timeout waiting for image to be ready.");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
print( "ERROR: Failed to find session. Received this:\n$content\n" );
|
||||
print(
|
||||
"ERROR: Failed to find session. Received this:\n$content\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print( "ERROR: Submitting the image create request failed:\n" . $response->status_line );
|
||||
print( "ERROR: Submitting the image create request failed:\n"
|
||||
. $response->status_line );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Install a new distribution of GNU/Linux using the rpmstrap tool.
|
||||
@ -931,17 +931,19 @@ sub do_image_server
|
||||
|
||||
sub do_rinse
|
||||
{
|
||||
|
||||
#
|
||||
# The command we're going to run.
|
||||
#
|
||||
my $command = "rinse --distribution=$CONFIG{'dist'} --directory=$CONFIG{'location'}";
|
||||
my $command =
|
||||
"rinse --distribution=$CONFIG{'dist'} --directory=$CONFIG{'location'}";
|
||||
|
||||
#
|
||||
# Propogate the --arch argument
|
||||
#
|
||||
if ( $CONFIG{'arch'} )
|
||||
{
|
||||
$command .= " --arch $CONFIG{'arch'}"
|
||||
$command .= " --arch $CONFIG{'arch'}";
|
||||
}
|
||||
|
||||
|
||||
@ -953,7 +955,7 @@ sub do_rinse
|
||||
$command .= " --verbose";
|
||||
}
|
||||
|
||||
runCommand( $command );
|
||||
runCommand($command);
|
||||
}
|
||||
|
||||
|
||||
@ -972,7 +974,7 @@ sub do_rpmstrap
|
||||
#
|
||||
# Propogate the verbosity setting.
|
||||
#
|
||||
my $EXTRA='';
|
||||
my $EXTRA = '';
|
||||
if ( $CONFIG{'verbose'} )
|
||||
{
|
||||
$EXTRA .= " --verbose";
|
||||
@ -990,18 +992,17 @@ sub do_rpmstrap
|
||||
# Setup mirror if present.
|
||||
#
|
||||
my $mirror = "";
|
||||
$mirror = $CONFIG{'mirror'} if ( $CONFIG{'mirror'} );
|
||||
$mirror = $CONFIG{'mirror'} if ( $CONFIG{'mirror'} );
|
||||
|
||||
#
|
||||
# The command we're going to run.
|
||||
#
|
||||
my $command = "rpmstrap $EXTRA $CONFIG{'dist'} $CONFIG{'location'} $mirror";
|
||||
runCommand( $command );
|
||||
runCommand($command);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Install a new image of a distribution using `tar`.
|
||||
@ -1012,14 +1013,15 @@ sub do_rpmstrap
|
||||
|
||||
sub do_tar
|
||||
{
|
||||
|
||||
#
|
||||
# Find the tar command to run from the configuration file.
|
||||
#
|
||||
my $cmd = $CONFIG{'tar-cmd'} ;
|
||||
if ( !defined( $cmd ) )
|
||||
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.
|
||||
$cmd = '/bin/tar --numeric-owner -xvf $src'; # Note: single quotes.
|
||||
}
|
||||
|
||||
#
|
||||
@ -1030,5 +1032,5 @@ sub do_tar
|
||||
#
|
||||
# Run a command to copy an installed system into the new root.
|
||||
#
|
||||
runCommand( "cd $CONFIG{'location'} && $cmd" );
|
||||
runCommand("cd $CONFIG{'location'} && $cmd");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user