#!/usr/bin/perl -w =head1 NAME xt-customize-image - Customize a freshly installed copy of GNU/Linux =cut =head1 SYNOPSIS xt-customize-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. Mandatory Options: --location The location of the new installation --dist The name of the distribution which has been installed. All other options from xen-create-image, such as the new IP address(es) to give to the new instance, will be passed as environmental variables. =cut =head1 NOTES This script is invoked by xen-create-image after it has created a fresh installation of Linux withing a temporary location. This script will be invoked with a full copy of the arguments from xen-create-image in its environment, along with several command line arguments. The command line arguments which are mandatory are: --location - The temporary installation root of the new install --dist - The distribution which has been installed. =cut =head1 HOOK SCRIPTS The distribution name is used to locate an appropriate collection of scripts, or hooks, to execute to do the actual customisation. The hooks will each be executed with a single parameter which is the directory path to the new instance. This argument is taken from the --location option. For the distribution named 'foo' the scripts will be loaded and executed from '/usr/lib/xen-tools/foo.d'. Each executable will be loaded and executed in sorted order. =cut =head1 AUTHORS Steve Kemp, http://www.steve.org.uk/ Axel Beckert, http://noone.org/abe/ Stéphane Jourdois =cut =head1 LICENSE Copyright (c) 2005-2009 by Steve Kemp, (c) 2010 by The Xen-Tools Development Team. 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; # # Configuration values read from the command line. # # We do not need to read any configuration file. # my %CONFIG; # # Release number. # my $RELEASE = '4.4~dev'; # # Parse the command line arguments. # parseCommandLineArguments(); # # Check our arguments. # checkArguments(); # # Run each relevant hook scripts. # runDistributionHooks(); # # Exit cleanly - any errors which have already occurred will result # in "exit 1". # exit 0; =begin doc Parse the command line arguments this script was given. =end doc =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) { print "xt-customize-image release $RELEASE\n"; exit; } } =begin doc Test that the command line arguments we were given make sense. =end doc =cut sub checkArguments { # # We require a location. # if ( !defined( $CONFIG{ 'location' } ) ) { print "The '--location' argument is mandatory\n"; exit 1; } # # Test that the location we've been given 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; } # # 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 <