diff --git a/xen-create-image b/xen-create-image index 6aaf1d0..4531b3d 100755 --- a/xen-create-image +++ b/xen-create-image @@ -190,7 +190,7 @@ broadcast = 255.255.255.0 -- http://www.steve.org.uk/ - $Id: xen-create-image,v 1.24 2005-12-19 17:17:04 steve Exp $ + $Id: xen-create-image,v 1.25 2005-12-19 17:39:19 steve Exp $ =cut @@ -220,6 +220,7 @@ use Pod::Usage; + # # Configuration options, initially read from the configuration files # but may be overridden by the command line. @@ -908,9 +909,9 @@ sub fixupInittab # # Leave line unchanged - but change 'tty1' to 'console'. # - if ( $line =~ /(.*) tty[0-9]/ ) + if ( $line =~ /(.*)tty1$/ ) { - $line = $1 . " console"; + $line = $1 . "console"; } # diff --git a/xen-list-images b/xen-list-images new file mode 100755 index 0000000..868b0cb --- /dev/null +++ b/xen-list-images @@ -0,0 +1,221 @@ +#!/usr/bin/perl -w + +=head1 NAME + + xen-list-images - List all the created and configured Xen images. + +=head1 SYNOPSIS + + xen-list-image [options] + + --dir Specify where the output images are located. + +=cut + + + +=head1 OPTIONS + +=over 8 + +=item B<--dir> +Specify the output directory where images were saved. + +=item B<--help> +Show the script help + +=item B<--manual> +Read the manual + + + +=back + +=cut + + +=head1 DESCRIPTION + + + xen-list-images is a simple script which will display all the + images which have been created in a given directory. + +=cut + + +=head1 AUTHOR + + + Steve + -- + http://www.steve.org.uk/ + + $Id: xen-list-images,v 1.1 2005-12-19 17:39:19 steve Exp $ + +=cut + + +=head1 LICENSE + +Copyright (c) 2005 by Steve Kemp. All rights reserved. + +This module is free software; +you can redistribute it and/or modify it under +the same terms as Perl itself. +The LICENSE file contains the full text of the license. + +=cut + + +use strict; +use Getopt::Long; +use Pod::Usage; + + +# +# Configuration options, initially read from the configuration files +# but may be overridden by the command line. +# +# Command line flags *always* take precedence over the configuration files(s). +# +my %CONFIG; + + + + +# +# Read configuration file(s) if they exist. +# +if ( -e "/etc/xen-tools/xen-tools.conf" ) +{ + readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); +} +if ( -e $ENV{'HOME'} . ".xen-tools.conf" ) +{ + readConfigurationFile( $ENV{'HOME'} . ".xen-tools.conf" ); +} + + +# +# Parse command line arguments, these override the values from the +# configuration file. +# +parseCommandLineArguments(); + + + +my $dir = $CONFIG{'dir'} . "/domains/"; + +foreach my $entry ( glob( $dir . "*" ) ) +{ + if ( $entry =~ /(.*)\/domains\/(.*)/ ) + { + $entry = $2; + } + + # + # Xen configuration file. + # + if ( -e "/etc/xen/" . $entry . ".cfg" ) + { + # + # Disk && Swap files. + # + if ( ( -e $CONFIG{'dir'} . "/domains/$entry/disk.img" ) && + ( -e $CONFIG{'dir'} . "/domains/$entry/swap.img" ) ) + { + print "Image: $entry\n"; + } + } +} + + +# +# All done. +# +exit; + + + +=head2 readConfigurationFile + + Read the configuration file specified. + +=cut + +sub readConfigurationFile +{ + my ($file) = ( @_ ); + + open( FILE, "<", $file ) or die "Cannot read file '$file' - $!"; + + my $line = ""; + + 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 ); +} + + + + +=head2 parseCommandLineArguments + + Parse the arguments specified upon the command line. + +=cut + +sub parseCommandLineArguments +{ + my $HELP = 0; + my $MANUAL = 0; + + # Parse options. + # + GetOptions( + "dir=s", \$CONFIG{'dir'}, + "help", \$HELP, + "manual", \$MANUAL + ); + + pod2usage(1) if $HELP; + pod2usage(-verbose => 2 ) if $MANUAL; +} + +