diff --git a/bin/xen-create-image b/bin/xen-create-image index c93b9d4..dc763a0 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -1,33 +1,111 @@ #!/usr/bin/perl -w -# -# Parse arguments, and call 'xt-install-image' + 'xt-customize-image' -# appropriately. -# +=head1 NAME + + xen-create-image - Create a new Xen instance + +=cut + +=head1 SYNOPSIS + + xen-create-image [options] + + Help Options: + --help Show this scripts help information. + --manual Read this scripts manual. + --version Show the version number and exit. + + Debugging Options: + --verbose Be verbose in our execution. + +=cut + +=head1 NOTES + +=cut + + +=head1 AUTHOR + + Steve + -- + http://www.steve.org.uk/ + + $Id: xen-create-image,v 1.3 2006-06-09 14:41:22 steve Exp $ + +=cut + + +=head1 LICENSE + +Copyright (c) 2005-2006 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 Env; +use Getopt::Long; +use Pod::Usage; # -# Read configuration file. +# Configuration values read initially from the global configuration +# file, then optionally overridden by the command line. # +my %CONFIG; + +# +# Release number. +# +my $RELEASE = '2.0'; + + + # -# Parse arguments +# Check the environment # +checkSystem(); # -# Check arguments. +# Parse the command line arguments. # +parseCommandLineArguments(); # -# Create temporary directory to perform installation into +# Check our arguments # +checkArguments(); +# +# Create and mount the images if we're using loopback filesystems. +# +if ( $CONFIG{'dir'} ) +{ +} + +# +# Create the LVM partitions if we're using LVM. +# +if ( $CONFIG{'loopback'} ) +{ +} + + +# +# Mount the image. +# + # # Call xt-install-image to do the install. # @@ -40,7 +118,7 @@ use strict; # -# Unmount the temporary directory. +# Unmount the disk image, and remove the temporary directory. # @@ -52,3 +130,136 @@ use strict; # # Report success. # + + + + +=head2 checkSystem + + Test that this system is fully setup for the new xen-create-image + script. + + This means that the two binaries xt-install-image and xt-customize-image + are present. + +=cut + +sub checkSystem +{ + if ( ! -x "/usr/bin/xt-customize-image" ) + { + print "The script 'xt-customize-image' was not found."; + print "\nAborting\n\n"; + } + if ( ! -x "/usr/bin/xt-install-image" ) + { + print "The script 'xt-install-image' was not found."; + print "\nAborting\n\n"; + } +} + + + + +=head2 parseCommandLineArguments + + Parse the command line arguments this script was given. + +=cut + +sub parseCommandLineArguments +{ + my $HELP = 0; + my $MANUAL = 0; + my $VERSION = 0; + + # + # Parse options. + # + GetOptions( + # Mandatory + "dist=s", \$CONFIG{'dist'}, + + # Locations + "dir=s", \$CONFIG{'dir'}, + "lvm=s", \$CONFIG{'lvm'}, + + # Exclusive + "copy=s", \$CONFIG{'rpmstrap'}, + "debootstrap", \$CONFIG{'debootstrap'}, + "rpmstrap", \$CONFIG{'rpmstrap'}, + "tar=s", \$CONFIG{'tar'}, + + # Help options + "verbose", \$CONFIG{'verbose'}, + "debug", \$CONFIG{'verbose'}, + "help", \$HELP, + "manual", \$MANUAL, + "version", \$VERSION + ); + + pod2usage(1) if $HELP; + pod2usage(-verbose => 2 ) if $MANUAL; + + + if ( $VERSION ) + { + my $REVISION = '$Revision: 1.3 $'; + + if ( $REVISION =~ /1.([0-9.]+) / ) + { + $REVISION = $1; + } + + print "xen-create-image release $RELEASE - CVS: $REVISION\n"; + exit; + + } +} + + +=head2 checkArguments + + Test that the command line arguments we were given make sense. + +=cut + +sub checkArguments +{ + # + # We require a distribution name. + # + if ( ! defined( $CONFIG{'dist'} ) ) + { + print "The '--dist' argument is mandatory\n"; + exit 1; + } + + # + # Test that the distribution name we've been given + # to configure has a collection of hook scripts. + # + # If there are no scripts then we clearly cannot + # customise it! + # + my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d"; + + if ( ! -d $dir ) + { + print <