From 9c1d749ec8988151b68e11b93cc4d2a8b71f5f76 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 9 Jun 2006 13:26:01 +0000 Subject: [PATCH] 2006-06-09 13:26:01 by steve Added 99% of the code. NOTE: --location must be absolute, or the chdir() breaks things. FIXME? --- bin/xt-customize-image | 216 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 210 insertions(+), 6 deletions(-) diff --git a/bin/xt-customize-image b/bin/xt-customize-image index 63aaa84..ccda181 100755 --- a/bin/xt-customize-image +++ b/bin/xt-customize-image @@ -15,6 +15,9 @@ --manual Read this scripts manual. --version Show the version number and exit. + Debugging Options: + --verbose Be verbose in our execution. + Mandatory Options: --location The location of the new installation --dist The name of the distribution which has been installed. @@ -47,7 +50,7 @@ -- http://www.steve.org.uk/ - $Id: xt-customize-image,v 1.3 2006-06-09 12:48:22 steve Exp $ + $Id: xt-customize-image,v 1.4 2006-06-09 13:26:01 steve Exp $ =cut @@ -70,6 +73,24 @@ The LICENSE file contains the full text of the license. # 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 file. +# +my %CONFIG; + +# +# Release number. +# +my $RELEASE = '2.0'; + + # @@ -81,7 +102,7 @@ use strict; # --dist = { sid sarge etch centos4 gentoo .. etc } # # - +parseCommandLineArguments(); # @@ -90,16 +111,199 @@ use strict; # Distro hook directory must exist: /usr/lib/${distro}.d/ # # Mountpoint must exist: ${location} - +checkArguments(); # # Run each relevent hook script. # -# NOTE: Must change to the directory of the scripts prior to running them -# so that ../common.sh exists and is accessible. -# # +runDistributionHooks(); + # Exit cleanly # +exit 0; + + + + + + +=head2 parseArguments + + Parse the command line arguments this script was given. + +=cut + +sub parseCommandLineArguments +{ + my $HELP = 0; + my $MANUAL = 0; + my $VERSION = 0; + + # Parse options. + # + GetOptions( + "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; + + + if ( $VERSION ) + { + my $REVISION = '$Revision: 1.4 $'; + + if ( $REVISION =~ /1.([0-9.]+) / ) + { + $REVISION = $1; + } + + print "xt-customize-image release $RELEASE - CVS: $REVISION\n"; + exit; + + } +} + + + +=head2 checkArguments + + Test that the command line arguments we were given make sense. + +=cut + +sub checkArguments +{ + # + # Test that the location we've been told contains + # a fresh installation of Linux exists + # + if ( ! -d $CONFIG{'location'} ) + { + print "The installation directory we've been given doesn't exist\n"; + print "We tried to use : $CONFIG{'location'}\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 <