2006-06-09 13:26:01 by steve
Added 99% of the code. NOTE: --location must be absolute, or the chdir() breaks things. FIXME?
This commit is contained in:
@@ -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 <<E_OR;
|
||||
|
||||
We're trying to configure an installation of $CONFIG{'dist'} in
|
||||
$CONFIG{'location'} - but there is no hook directory for us to use.
|
||||
|
||||
This means we don't know how to configure this installation.
|
||||
|
||||
We'd expect the hook directory to be : $dir
|
||||
|
||||
Aborting.
|
||||
E_OR
|
||||
exit 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
=head2 runDistributionHooks
|
||||
|
||||
This function does the real work of running each of our hook scripts.
|
||||
|
||||
Each hook script is executed in turn, ignoring emacs save files and
|
||||
dpkg-temporary files.
|
||||
|
||||
We will give each script the name of the directory containing the
|
||||
installation as a single argument.
|
||||
|
||||
NOTE: We must change to the directory of the scripts prior to running them
|
||||
so that ../common.sh exists and is accessible.
|
||||
|
||||
=cut
|
||||
|
||||
sub runDistributionHooks
|
||||
{
|
||||
#
|
||||
# Hook directory.
|
||||
#
|
||||
my $hooks = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d/";
|
||||
|
||||
chdir( $hooks );
|
||||
#
|
||||
# Installation prefix
|
||||
#
|
||||
my $prefix = $CONFIG{'location'};
|
||||
|
||||
#
|
||||
# If we're running verbosely then setup the client environment
|
||||
# appropriately.
|
||||
#
|
||||
# This is useful in case this script is called outwith the usual
|
||||
# xen-create-image framework.
|
||||
#
|
||||
if ( $CONFIG{'verbose'} )
|
||||
{
|
||||
$ENV{'verbose'} = 1;
|
||||
}
|
||||
|
||||
#
|
||||
# Make sure that our scripts run in sorted order, as
|
||||
# the user would expect.
|
||||
#
|
||||
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 =~ /~$/ );
|
||||
|
||||
#
|
||||
# Only run executable files.
|
||||
#
|
||||
if ( ( -x $file ) && ( -f $file ) )
|
||||
{
|
||||
#
|
||||
# Just display the name - no need to see the full path.
|
||||
#
|
||||
my $name = $file;
|
||||
if ( $file =~ /(.*)\/(.*)/ )
|
||||
{
|
||||
$name = $2;
|
||||
}
|
||||
|
||||
#
|
||||
# Complete path to the file.
|
||||
#
|
||||
my $cmd = $hooks . $name . " $CONFIG{'location'}";
|
||||
|
||||
if ( $CONFIG{'verbose'} )
|
||||
{
|
||||
print "Running hook $name ['$cmd']";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Running hook $name";
|
||||
}
|
||||
|
||||
system( $cmd );
|
||||
|
||||
print " - done.\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user