From f73eb76b1e875945dc3de45dec72a8623c7bf081 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 13 Oct 2008 18:32:06 +0000 Subject: [PATCH] Document state of Debian package 3.9-5 --- Makefile | 15 +- bin/xen-create-image | 1138 ++++++++++++++----------- bin/xen-create-nfs | 119 +-- bin/xen-delete-image | 223 ++--- bin/xen-list-images | 52 +- bin/xen-resize-guest | 82 +- bin/xen-update-image | 135 +-- bin/xt-create-xen-config | 100 +-- bin/xt-customize-image | 56 +- bin/xt-install-image | 302 +++---- debian/changelog | 11 +- debian/control | 2 +- hooks/centos-4/15-setup-arch | 44 + hooks/centos-4/50-setup-hostname | 2 +- hooks/centos-5/15-setup-arch | 44 + hooks/centos-5/50-setup-hostname | 3 +- hooks/dapper/50-setup-hostname | 2 +- hooks/debian/50-setup-hostname | 2 +- hooks/edgy/50-setup-hostname | 3 +- hooks/fedora-core-6/15-setup-arch | 44 + hooks/fedora-core-6/50-setup-hostname | 3 +- hooks/fedora-core-6/90-make-fstab | 2 +- hooks/gentoo/50-setup-hostname | 2 +- t/modules.sh | 2 +- t/modules.t | 4 - t/quoted-strings.t | 78 ++ 26 files changed, 1430 insertions(+), 1040 deletions(-) create mode 100644 hooks/centos-4/15-setup-arch create mode 100644 hooks/centos-5/15-setup-arch create mode 100644 hooks/fedora-core-6/15-setup-arch create mode 100644 t/quoted-strings.t diff --git a/Makefile b/Makefile index 99d1c31..8536ab7 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ manpages: # # Make a new release tarball, and make a GPG signature. # -release: fixup-perms update-version update-modules clean changelog +release: tidy fixup-perms update-version update-modules clean changelog rm -rf $(DIST_PREFIX)/$(BASE)-$(VERSION) rm -f $(DIST_PREFIX)/$(BASE)-$(VERSION).tar.gz cp -R . $(DIST_PREFIX)/$(BASE)-$(VERSION) @@ -228,6 +228,17 @@ test-verbose: +# +# Run our main script(s) through perltidy +# +tidy: + if [ -x /usr/bin/perltidy ]; then \ + for i in bin/*-*; do \ + echo "tidying $$i"; \ + perltidy -b -nt -bt=2 -sbt=1 -bl -mbl=3 -sbl -bbs -bbb -anl -lp $$i \ + ; done \ + ; fi + # # Uninstall the software, completely. # @@ -258,7 +269,7 @@ uninstall: # # NOTE: Removes empty local directories. # -update: +update: hg pull --update 2>/dev/null diff --git a/bin/xen-create-image b/bin/xen-create-image index 3a7ab90..aca00ac 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -665,8 +665,6 @@ my $RELEASE = '3.9'; - - # # Setup default options. # @@ -676,7 +674,7 @@ setupDefaultOptions(); # # Read the global configuration file. # -readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); +readConfigurationFile("/etc/xen-tools/xen-tools.conf"); # @@ -701,13 +699,12 @@ if ( $CONFIG{'config'} ) # Read the file, if it exists. if ( -e $path ) { - readConfigurationFile( $path ); + readConfigurationFile($path); } else { logprint( "The specified configuration file does not exist: '$path'\n", - "Aborting\n\n" - ); + "Aborting\n\n" ); exit 127; } } @@ -722,7 +719,7 @@ if ( $CONFIG{'debug'} ) { print $key; print " : " . $CONFIG{$key} if ( $CONFIG{$key} ); - print "\n"; + print "\n"; } exit 127; } @@ -771,9 +768,10 @@ checkBinariesPresent(); # if ( !$#PARTITIONS ) { - populatePartitionsData() if ( ( $CONFIG{'dir'} ) || - ( $CONFIG{'evms'} ) || - ( $CONFIG{'lvm'} ) ); + populatePartitionsData() + if ( ( $CONFIG{'dir'} ) + || ( $CONFIG{'evms'} ) + || ( $CONFIG{'lvm'} ) ); } @@ -789,6 +787,7 @@ showSummary(); # if ( $CONFIG{'dir'} ) { + # # Test to see if "loop" module is loaded. This is probably # not required, except for paranoia. @@ -802,6 +801,7 @@ if ( $CONFIG{'dir'} ) } elsif ( $CONFIG{'lvm'} ) { + # # Create our LVM partitions. # @@ -809,6 +809,7 @@ elsif ( $CONFIG{'lvm'} ) } elsif ( $CONFIG{'evms'} ) { + # # Create our EVMS partitions. # @@ -816,6 +817,7 @@ elsif ( $CONFIG{'evms'} ) } elsif ( $CONFIG{'image-dev'} ) { + # # Use physical disc # @@ -823,10 +825,10 @@ elsif ( $CONFIG{'image-dev'} ) } else { + # Can't happen we didn't get an installation type. logprint( "Error: No recognised installation type.\n", - "Please specify a directory, lvm, or evms volume to use.\n" - ); + "Please specify a directory, lvm, or evms volume to use.\n" ); $FAIL = 1; exit 127; } @@ -855,6 +857,7 @@ exportEnvironment(); # if ( $CONFIG{'install'} ) { + # # Install the system. # @@ -863,9 +866,9 @@ if ( $CONFIG{'install'} ) # # Did that work? # - if ( ! -x $MOUNT_POINT . "/bin/ls" ) + if ( !-x $MOUNT_POINT . "/bin/ls" ) { - logprint( "System installation failed. Aborting\n"); + logprint("System installation failed. Aborting\n"); $FAIL = 1; exit 127; } @@ -873,7 +876,7 @@ if ( $CONFIG{'install'} ) # # Now customize the installation - setting up networking, etc. # - if( $CONFIG{'hooks'} ) + if ( $CONFIG{'hooks'} ) { runCustomisationHooks(); } @@ -881,8 +884,6 @@ if ( $CONFIG{'install'} ) - - # # Run any specified role scripts. # @@ -904,7 +905,7 @@ setupRootPassword() if ( $CONFIG{'passwd'} ); # # Report success. # -logprint( "All done\n"); +logprint("All done\n"); # @@ -913,10 +914,11 @@ logprint( "All done\n"); # if ( $CONFIG{'boot'} ) { + # # Unmount the image and any subsequent mounts. # - unMountImage( $MOUNT_POINT ); + unMountImage($MOUNT_POINT); # # Mark us as unmounted. @@ -932,14 +934,15 @@ if ( $CONFIG{'boot'} ) # if ( -d "/etc/xen/auto" ) { - my $cfg = $CONFIG{'output'} . "/" . $CONFIG{'hostname'} . $CONFIG{'extension'}; + my $cfg = + $CONFIG{'output'} . "/" . $CONFIG{'hostname'} . $CONFIG{'extension'}; - if ( ! -e $cfg ) + if ( !-e $cfg ) { - logprint( "Creating auto-start symlink to: $cfg\n" ); + logprint("Creating auto-start symlink to: $cfg\n"); my $link = "ln -s $cfg /etc/xen/auto/"; - runCommand( $link ); + runCommand($link); } } @@ -951,18 +954,21 @@ if ( $CONFIG{'boot'} ) $CONFIG{'pid'} = fork(); if ( $CONFIG{'pid'} ) { + # Parent. exit; } else { + # Config file. - my $cfg = $CONFIG{'output'} . "/" . $CONFIG{'hostname'} . $CONFIG{'extension'}; + my $cfg = + $CONFIG{'output'} . "/" . $CONFIG{'hostname'} . $CONFIG{'extension'}; # Child. - system( "$CONFIG{'xm'} create $cfg >/dev/null 2>/dev/null" ); + system("$CONFIG{'xm'} create $cfg >/dev/null 2>/dev/null"); - logprint( "Started new Xen guest: $CONFIG{'hostname'} [$cfg]\n" ); + logprint("Started new Xen guest: $CONFIG{'hostname'} [$cfg]\n"); } } @@ -988,15 +994,14 @@ exit 0; sub checkSystem { - my @required = qw ( / xt-customize-image xt-install-image xt-create-xen-config / ); + my @required = + qw ( / xt-customize-image xt-install-image xt-create-xen-config / ); - foreach my $bin ( @required ) + foreach my $bin (@required) { - if ( ! defined( findBinary( $bin ) ) ) + if ( !defined( findBinary($bin) ) ) { - logprint("The script '$bin' was not found.\n", - "Aborting\n\n" - ); + logprint( "The script '$bin' was not found.\n", "Aborting\n\n" ); exit 127; } } @@ -1007,8 +1012,8 @@ sub checkSystem # running is pointless. # my $test = "use Text::Template"; - eval( $test ); - if ( ( $@ ) && ( ! $CONFIG{'force'} ) ) + eval($test); + if ( ($@) && ( !$CONFIG{'force'} ) ) { print < ) + while () { - next if ( ! $_ || !length( $_ ) ); + next if ( !$_ || !length($_) ); # vif if ( $_ =~ /^\(vif-script ([^)]+)/ ) @@ -1095,10 +1102,10 @@ sub testXenConfig $cfg{'network-script'} = $1; } } - close( CONFIG ); + close(CONFIG); - if ( !defined( $cfg{'network-script'} ) || - !defined( $cfg{'vif-script'} ) ) + if ( !defined( $cfg{'network-script'} ) + || !defined( $cfg{'vif-script'} ) ) { print <) ) + while ( defined( $line = ) ) { chomp $line; - if ($line =~ s/\\$//) + if ( $line =~ s/\\$// ) { $line .= ; redo unless eof(FILE); @@ -1255,7 +1260,7 @@ sub readConfigurationFile next if ( $line =~ /^([ \t]*)\#/ ); # Skip blank lines - next if ( length( $line ) < 1 ); + next if ( length($line) < 1 ); # Strip trailing comments. if ( $line =~ /(.*)\#(.*)/ ) @@ -1278,6 +1283,7 @@ sub readConfigurationFile # command expansion? if ( $val =~ /(.*)`([^`]+)`(.*)/ ) { + # store my $pre = $1; my $cmd = $2; @@ -1285,18 +1291,18 @@ sub readConfigurationFile # get output my $output = `$cmd`; - chomp( $output ); + chomp($output); # build up replacement. $val = $pre . $output . $post; } # Store value. - $CONFIG{ $key } = $val; + $CONFIG{$key} = $val; } } - close( FILE ); + close(FILE); } @@ -1322,96 +1328,97 @@ sub parseCommandLineArguments # file. # my %install; - $install{'evms'} = undef; - $install{'dir'} = undef; - $install{'lvm'} = undef; - $install{'image-dev'} = undef; + $install{'evms'} = undef; + $install{'dir'} = undef; + $install{'lvm'} = undef; + $install{'image-dev'} = undef; # # Parse options. # GetOptions( - # Mandatory - "dist=s", \$CONFIG{'dist'}, - # Size options. - "size=s", \$CONFIG{'size'}, - "swap=s", \$CONFIG{'swap'}, - "noswap", \$CONFIG{'noswap'}, - "image=s", \$CONFIG{'image'}, - "memory=s", \$CONFIG{'memory'}, + # Mandatory + "dist=s", \$CONFIG{'dist'}, - # Locations - "dir=s", \$install{'dir'}, - "evms=s", \$install{'evms'}, - "kernel=s", \$CONFIG{'kernel'}, - "initrd=s", \$CONFIG{'initrd'}, - "mirror=s", \$CONFIG{'mirror'}, - "modules=s", \$CONFIG{'modules'}, - "lvm=s", \$install{'lvm'}, - "image-dev=s", \$install{'image-dev'}, - "swap-dev=s", \$install{'swap-dev'}, + # Size options. + "size=s", \$CONFIG{'size'}, + "swap=s", \$CONFIG{'swap'}, + "noswap", \$CONFIG{'noswap'}, + "image=s", \$CONFIG{'image'}, + "memory=s", \$CONFIG{'memory'}, - # Networking options - "dhcp", \$CONFIG{'dhcp'}, - "gateway=s", \$CONFIG{'gateway'}, - "hostname=s", \$CONFIG{'hostname'}, - "ip=s@", \$CONFIG{'ip'}, - "mac=s", \$CONFIG{'mac'}, - "netmask=s", \$CONFIG{'netmask'}, - "broadcast=s", \$CONFIG{'broadcast'}, - "p2p=s", \$CONFIG{'p2p'}, + # Locations + "dir=s", \$install{'dir'}, + "evms=s", \$install{'evms'}, + "kernel=s", \$CONFIG{'kernel'}, + "initrd=s", \$CONFIG{'initrd'}, + "mirror=s", \$CONFIG{'mirror'}, + "modules=s", \$CONFIG{'modules'}, + "lvm=s", \$install{'lvm'}, + "image-dev=s", \$install{'image-dev'}, + "swap-dev=s", \$install{'swap-dev'}, - # Exclusive - # - # NOTE: We set the local variable here, not the global. - # - "install-method=s", \$CONFIG{'install-method'}, - "install-source=s", \$CONFIG{'install-source'}, + # Networking options + "dhcp", \$CONFIG{'dhcp'}, + "gateway=s", \$CONFIG{'gateway'}, + "hostname=s", \$CONFIG{'hostname'}, + "ip=s@", \$CONFIG{'ip'}, + "mac=s", \$CONFIG{'mac'}, + "netmask=s", \$CONFIG{'netmask'}, + "broadcast=s", \$CONFIG{'broadcast'}, + "p2p=s", \$CONFIG{'p2p'}, - # Misc. options - "accounts", \$CONFIG{'accounts'}, - "admins=s", \$CONFIG{'admins'}, - "arch=s", \$CONFIG{'arch'}, - "fs=s", \$CONFIG{'fs'}, - "boot", \$CONFIG{'boot'}, - "cache=s", \$CONFIG{'cache'}, - "config=s", \$CONFIG{'config'}, - "ide", \$CONFIG{'ide'}, - "install=i", \$CONFIG{'install'}, - "hooks=i", \$CONFIG{'hooks'}, - "passwd", \$CONFIG{'passwd'}, - "partitions=s", \$CONFIG{'partitions'}, - "role=s", \$CONFIG{'role'}, - "role-args=s", \$CONFIG{'role-args'}, - "roledir=s", \$CONFIG{'roledir'}, - "force", \$CONFIG{'force'}, - "keep", \$CONFIG{'keep'}, - "template=s", \$CONFIG{'template'}, - "output=s", \$CONFIG{'output'}, - "extension=s", \$CONFIG{'extension'}, + # Exclusive + # + # NOTE: We set the local variable here, not the global. + # + "install-method=s", \$CONFIG{'install-method'}, + "install-source=s", \$CONFIG{'install-source'}, - # Help options - "debug", \$CONFIG{'debug'}, - "help", \$HELP, - "manual", \$MANUAL, - "verbose", \$CONFIG{'verbose'}, - "version", \$VERSION - ); + # Misc. options + "accounts", \$CONFIG{'accounts'}, + "admins=s", \$CONFIG{'admins'}, + "arch=s", \$CONFIG{'arch'}, + "fs=s", \$CONFIG{'fs'}, + "boot", \$CONFIG{'boot'}, + "cache=s", \$CONFIG{'cache'}, + "config=s", \$CONFIG{'config'}, + "ide", \$CONFIG{'ide'}, + "install=i", \$CONFIG{'install'}, + "hooks=i", \$CONFIG{'hooks'}, + "passwd", \$CONFIG{'passwd'}, + "partitions=s", \$CONFIG{'partitions'}, + "role=s", \$CONFIG{'role'}, + "role-args=s", \$CONFIG{'role-args'}, + "roledir=s", \$CONFIG{'roledir'}, + "force", \$CONFIG{'force'}, + "keep", \$CONFIG{'keep'}, + "template=s", \$CONFIG{'template'}, + "output=s", \$CONFIG{'output'}, + "extension=s", \$CONFIG{'extension'}, + + # Help options + "debug", \$CONFIG{'debug'}, + "help", \$HELP, + "manual", \$MANUAL, + "verbose", \$CONFIG{'verbose'}, + "version", \$VERSION + ); pod2usage(1) if $HELP; - pod2usage(-verbose => 2 ) if $MANUAL; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - my $REVISION = '$Revision: 1.192 $'; + my $REVISION = '$Revision: 1.192 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { $REVISION = $1; } - logprint( "xen-create-image release $RELEASE - CVS: $REVISION\n" ); + logprint("xen-create-image release $RELEASE - CVS: $REVISION\n"); exit 0; } @@ -1450,13 +1457,13 @@ sub parseCommandLineArguments $CONFIG{'size'} = undef; $CONFIG{'swap'} = undef; - $CONFIG{'swap-dev'} = $install{'swap-dev'} if ( defined( $install{'swap-dev'} ) ); + $CONFIG{'swap-dev'} = $install{'swap-dev'} + if ( defined( $install{'swap-dev'} ) ); } } - =begin doc Make sure this script is being run by a user with UID 0. @@ -1469,7 +1476,7 @@ sub testRootUser { if ( $EFFECTIVE_USER_ID != 0 ) { - my $err =<{'size'} =~ /^[0-9.]+[GgMmKk]b?$/ ) ) + if ( !( $details->{'size'} =~ /^[0-9.]+[GgMmKk]b?$/ ) ) { - logprint( "The size $details->{'size'} of partition $name contains is not recognized.\n" ); + logprint( +"The size $details->{'size'} of partition $name contains is not recognized.\n" + ); exit 127; } if ( $details->{'type'} eq 'swap' ) { - push( @PARTITIONS, { 'name' => $name, - 'size' => $details->{'size'}, - 'type' => 'swap', - 'mountpoint' => '', - 'options' => '' } ); + push( + @PARTITIONS, + { + 'name' => $name, + 'size' => $details->{'size'}, + 'type' => 'swap', + 'mountpoint' => '', + 'options' => '' + } + ); } else { - if ( ! $CONFIG{ 'make_fs_' . $details->{'type'} } ) + if ( !$CONFIG{'make_fs_' . $details->{'type'}} ) { - logprint( "The type $details->{'type'} of partition $name is not recognized.\n" ); + logprint( +"The type $details->{'type'} of partition $name is not recognized.\n" ); exit 127; } - if ( ! ( $details->{'mountpoint'} =~ /^\/[^: \t\r\n]*$/ ) ) + if ( !( $details->{'mountpoint'} =~ /^\/[^: \t\r\n]*$/ ) ) { - logprint( "The mount point $details->{'mountpoint'} of partition $name is invalid.\n" ); + logprint( +"The mount point $details->{'mountpoint'} of partition $name is invalid.\n" ); exit 127; } - if ( ! ( $details->{'options'} =~ /^[^: \t\r\n]*$/ ) ) + if ( !( $details->{'options'} =~ /^[^: \t\r\n]*$/ ) ) { - logprint( "The mount options $details->{'options'} of partition $name are invalid.\n" ); + logprint( +"The mount options $details->{'options'} of partition $name are invalid.\n" ); exit 127; } - if ( ! $details->{'options'} ) + if ( !$details->{'options'} ) { $details->{'options'} = 'defaults'; } @@ -2048,21 +2097,22 @@ EOF $foundroot = 1; } - push( @PARTITIONS, - { - 'name' => $name, - 'size' => $details->{'size'}, - 'type' => $details->{'type'}, - 'mountpoint' => $details->{'mountpoint'}, - 'options' => $details->{'options'} - } + push( + @PARTITIONS, + { + 'name' => $name, + 'size' => $details->{'size'}, + 'type' => $details->{'type'}, + 'mountpoint' => $details->{'mountpoint'}, + 'options' => $details->{'options'} + } ); } } - if ( ! $foundroot ) + if ( !$foundroot ) { - logprint( "The root partition was not specified.\n" ); + logprint("The root partition was not specified.\n"); exit 127; } @@ -2077,7 +2127,6 @@ EOF - =begin doc Populates the partition information using the supplied configuration @@ -2094,24 +2143,29 @@ sub populatePartitionsData # # [swap] # - push( @PARTITIONS, { 'name' => 'swap', - 'size' => $CONFIG{'swap'}, - 'type' => 'swap', - 'mountpoint' => '', - 'options' => '' } ) - unless( $CONFIG{'noswap'} ); + push( + @PARTITIONS, + { + 'name' => 'swap', + 'size' => $CONFIG{'swap'}, + 'type' => 'swap', + 'mountpoint' => '', + 'options' => '' + } + ) unless ( $CONFIG{'noswap'} ); # # read the default filesystem options from the configuration file. # - my $options = $CONFIG{$CONFIG{'fs'} . "_options" } ||undef; + my $options = $CONFIG{$CONFIG{'fs'} . "_options"} || undef; # # If there weren't any options in the configuration file then # revert to our defaults. # - if (!defined($options)) + if ( !defined($options) ) { + # # XFS has different default options. # @@ -2123,11 +2177,16 @@ sub populatePartitionsData # # [root] # - push( @PARTITIONS, { 'name' => 'disk', - 'size' => $CONFIG{'size'}, - 'type' => $CONFIG{'fs'}, - 'mountpoint' => '/', - 'options' => $options } ); + push( + @PARTITIONS, + { + 'name' => 'disk', + 'size' => $CONFIG{'size'}, + 'type' => $CONFIG{'fs'}, + 'mountpoint' => '/', + 'options' => $options + } + ); } @@ -2147,15 +2206,16 @@ sub exportPartitionsToConfig $CONFIG{'NUMPARTITIONS'} = $#PARTITIONS + 1; my $i; - for ( $i = 0; $i < $CONFIG{'NUMPARTITIONS'}; $i++ ) + for ( $i = 0 ; $i < $CONFIG{'NUMPARTITIONS'} ; $i++ ) { - $CONFIG{'PARTITION' . ( $i + 1 )} = $PARTITIONS[$i]{'name'} . ':' . - $PARTITIONS[$i]{'size'} . ':' . - $PARTITIONS[$i]{'type'} . ':' . - $PARTITIONS[$i]{'mountpoint'} . ':' . - $PARTITIONS[$i]{'options'} . ':' . - $PARTITIONS[$i]{'imagetype'} . ':' . - $PARTITIONS[$i]{'image'}; + $CONFIG{'PARTITION' . ( $i + 1 )} = + $PARTITIONS[$i]{'name'} . ':' + . $PARTITIONS[$i]{'size'} . ':' + . $PARTITIONS[$i]{'type'} . ':' + . $PARTITIONS[$i]{'mountpoint'} . ':' + . $PARTITIONS[$i]{'options'} . ':' + . $PARTITIONS[$i]{'imagetype'} . ':' + . $PARTITIONS[$i]{'image'}; } } @@ -2171,61 +2231,67 @@ sub exportPartitionsToConfig sub showSummary { + # # Show the user what to expect. # - logprint( "\nGeneral Information\n" ); - logprint( "--------------------\n" ); - logprint( "Hostname : $CONFIG{'hostname'}\n" ); - logprint( "Distribution : $CONFIG{'dist'}\n" ); + logprint("\nGeneral Information\n"); + logprint("--------------------\n"); + logprint("Hostname : $CONFIG{'hostname'}\n"); + logprint("Distribution : $CONFIG{'dist'}\n"); if ( defined $CONFIG{'image-dev'} ) { - logprint( "Root Device : $CONFIG{'image-dev'}\n" ); + logprint("Root Device : $CONFIG{'image-dev'}\n"); } if ( defined $CONFIG{'swap-dev'} ) { - logprint( "Swap Device : $CONFIG{'swap-dev'}\n" ); + logprint("Swap Device : $CONFIG{'swap-dev'}\n"); } my $info; my $partcount = 0; - logprint( "Partitions : " ); - foreach my $partition ( @PARTITIONS ) + logprint("Partitions : "); + foreach my $partition (@PARTITIONS) { - $info = sprintf('%-15s %-5s (%s)', ($partition->{'type'} ne 'swap') ? $partition->{'mountpoint'} : 'swap', $partition->{'size'}, $partition->{'type'}); + $info = sprintf( '%-15s %-5s (%s)', + ( $partition->{'type'} ne 'swap' ) + ? $partition->{'mountpoint'} + : 'swap', + $partition->{'size'}, + $partition->{'type'} ); - if ($partcount++) + if ( $partcount++ ) { - logprint( " $info\n" ); + logprint(" $info\n"); } else { - logprint( "$info\n" ); + logprint("$info\n"); } } - logprint( "Image type : $CONFIG{'image'}\n" ); - logprint( "Memory size : $CONFIG{'memory'}\n" ); + logprint("Image type : $CONFIG{'image'}\n"); + logprint("Memory size : $CONFIG{'memory'}\n"); if ( defined( $CONFIG{'kernel'} ) && length( $CONFIG{'kernel'} ) ) { - logprint( "Kernel path : $CONFIG{'kernel'}\n" ); + logprint("Kernel path : $CONFIG{'kernel'}\n"); } if ( defined( $CONFIG{'modules'} ) && length( $CONFIG{'modules'} ) ) { - logprint( "Module path : $CONFIG{'modules'}\n" ); + logprint("Module path : $CONFIG{'modules'}\n"); } if ( defined( $CONFIG{'initrd'} ) && length( $CONFIG{'initrd'} ) ) { - logprint( "Initrd path : $CONFIG{'initrd'}\n" ); + logprint("Initrd path : $CONFIG{'initrd'}\n"); } - logprint( "\nNetworking Information\n" ); - logprint( "----------------------\n" ); + logprint("\nNetworking Information\n"); + logprint("----------------------\n"); # # Show each IP address added. @@ -2238,11 +2304,13 @@ sub showSummary if ( defined $ips ) { + # # Scary magic. # if ( !UNIVERSAL::isa( $ips, "ARRAY" ) ) { + # # If we're reading the value of "ip = xxx" from the configuration # file we'll have a single (scalar) value in $CONFIG{'ip'}. @@ -2259,7 +2327,7 @@ sub showSummary # # It works. Even if it's nasty, (or if it is a clever hack!) # - $ips = undef; + $ips = undef; push( @$ips, $CONFIG{'ip'} ); $CONFIG{'ip'} = $ips; } @@ -2268,15 +2336,16 @@ sub showSummary if ( defined $ips ) { + # # Print out each network address, and if there is a mac address # associated with it then use it too. # - foreach my $i ( @$ips ) + foreach my $i (@$ips) { my $m = undef; - if ( ( $count == 1 ) && ( defined( $mac ) ) ) + if ( ( $count == 1 ) && ( defined($mac) ) ) { $m = $mac; } @@ -2289,13 +2358,13 @@ sub showSummary # if ( $i =~ /auto/i ) { - $CONFIG{'verbose'} && - logprint( "Automatically determining an IP." ); + $CONFIG{'verbose'} + && logprint("Automatically determining an IP."); - $i = findIP( $i ); - if ( defined( $i ) ) + $i = findIP($i); + if ( defined($i) ) { - $CONFIG{'verbose'} && logprint( "Claimed $i\n" ); + $CONFIG{'verbose'} && logprint("Claimed $i\n"); } else { @@ -2312,14 +2381,14 @@ EOF # # Show the IP address. # - logprint( "IP Address $count : $i" ); + logprint("IP Address $count : $i"); # Option MAC address. - if ( defined( $m ) ) + if ( defined($m) ) { - logprint( " [MAC: $m]" ); + logprint(" [MAC: $m]"); } - logprint( "\n" ); + logprint("\n"); $count += 1; } @@ -2333,25 +2402,24 @@ EOF { if ( defined( $CONFIG{'mac'} ) ) { - logprint( "IP Address : DHCP [MAC: $CONFIG{'mac'}]\n" ); + logprint("IP Address : DHCP [MAC: $CONFIG{'mac'}]\n"); } else { - logprint( "IP Address : DHCP\n" ); + logprint("IP Address : DHCP\n"); } } - $CONFIG{'netmask'} && logprint( "Netmask : $CONFIG{'netmask'}\n" ); - $CONFIG{'broadcast'} && logprint( "Broadcast : $CONFIG{'broadcast'}\n" ); - $CONFIG{'gateway'} && logprint( "Gateway : $CONFIG{'gateway'}\n" ); - $CONFIG{'p2p'} && logprint( "Point to Point : $CONFIG{'p2p'}\n" ); + $CONFIG{'netmask'} && logprint("Netmask : $CONFIG{'netmask'}\n"); + $CONFIG{'broadcast'} && logprint("Broadcast : $CONFIG{'broadcast'}\n"); + $CONFIG{'gateway'} && logprint("Gateway : $CONFIG{'gateway'}\n"); + $CONFIG{'p2p'} && logprint("Point to Point : $CONFIG{'p2p'}\n"); print "\n"; } - =begin doc Test that the user has the "loop" module loaded and present, @@ -2369,11 +2437,13 @@ sub testLoopbackModule if ( $modules !~ m/loop/ ) { - logprint( "WARNING\n" ); - logprint( "-------\n" ); - logprint( "Loopback module not loaded and you're using loopback images\n" ); - logprint( "Run the following to load the module:\n\n" ); - logprint( "modprobe loop loop_max=255\n\n" ); + logprint("WARNING\n"); + logprint("-------\n"); + logprint( + "Loopback module not loaded and you're using loopback images\n" + ); + logprint("Run the following to load the module:\n\n"); + logprint("modprobe loop loop_max=255\n\n"); } } } @@ -2394,21 +2464,20 @@ sub testLoopbackModule sub createLoopbackImages { + # # Make sure we have the relevant output directory. # my $output = $CONFIG{'dir'} . "/domains/" . $CONFIG{'hostname'}; - if ( ! -d $output ) + if ( !-d $output ) { + # # Catch errors with eval. # - eval - { - mkpath( $output, 0, 0755 ); - }; - if ( $@ ) + eval { mkpath( $output, 0, 0755 ); }; + if ($@) { die "Cannot create directory tree $output - $@"; } @@ -2418,16 +2487,21 @@ sub createLoopbackImages # # Only proceed overwritting if we have --force specified. # - if ( ! $CONFIG{'force'} ) + if ( !$CONFIG{'force'} ) { - foreach my $partition ( @PARTITIONS ) + foreach my $partition (@PARTITIONS) { - my $disk = $CONFIG{'dir'} . '/domains/' . $CONFIG{'hostname'} . '/' . $partition->{'name'} . '.img'; + my $disk = + $CONFIG{'dir'} + . '/domains/' + . $CONFIG{'hostname'} . '/' + . $partition->{'name'} . '.img'; if ( -e $disk ) { - logprint( "The partition image already exists. Aborting.\n" ); - logprint( "Specify '--force' to overwrite, or remove the following file\n" ); + logprint("The partition image already exists. Aborting.\n"); + logprint( +"Specify '--force' to overwrite, or remove the following file\n" ); logprint( $disk . "\n" ); exit 127; } @@ -2435,9 +2509,13 @@ sub createLoopbackImages } - foreach my $partition ( @PARTITIONS ) + foreach my $partition (@PARTITIONS) { - my $disk = $CONFIG{'dir'} . '/domains/' . $CONFIG{'hostname'} . '/' . $partition->{'name'} . '.img'; + my $disk = + $CONFIG{'dir'} + . '/domains/' + . $CONFIG{'hostname'} . '/' + . $partition->{'name'} . '.img'; # # Save the image path to the partitions array @@ -2466,26 +2544,26 @@ sub createLoopbackImages # # Use dd to create the partition image. # - logprint( "\nCreating partition image: $disk\n" ); + logprint("\nCreating partition image: $disk\n"); my $image_cmd; if ( $CONFIG{'image'} eq "sparse" ) { - $CONFIG{'verbose'} && logprint( "Creating sparse image\n" ); + $CONFIG{'verbose'} && logprint("Creating sparse image\n"); $image_cmd = "dd if=/dev/zero of=$disk bs=$size count=0 seek=1024"; } else { - $CONFIG{'verbose'} && logprint( "Creating full-sized image\n" ); + $CONFIG{'verbose'} && logprint("Creating full-sized image\n"); $image_cmd = "dd if=/dev/zero of=$disk bs=$size count=1024"; } - runCommand( $image_cmd ); - logprint( "Done\n" ); + runCommand($image_cmd); + logprint("Done\n"); - if ( ! -e $disk ) + if ( !-e $disk ) { - logprint( "The partition image creation failed to create $disk.\n" ); - logprint( "aborting\n" ); + logprint("The partition image creation failed to create $disk.\n"); + logprint("aborting\n"); exit 127; } @@ -2494,7 +2572,7 @@ sub createLoopbackImages # if ( $partition->{'type'} eq 'swap' ) { - createSwap( $disk ); + createSwap($disk); } else { @@ -2528,15 +2606,28 @@ sub usePhysicalDevice { $swap_img = $CONFIG{'swap-dev'}; - if (! -e $swap_img ) + if ( !-e $swap_img ) { - logprint( "The physical device or logical volume for swap-dev $swap_img doesn't exist. Aborting.\n" ); - logprint( "NOTE: Please provide full path to your physical device or logical volume.\n" ); + logprint( +"The physical device or logical volume for swap-dev $swap_img doesn't exist. Aborting.\n" + ); + logprint( +"NOTE: Please provide full path to your physical device or logical volume.\n" ); exit 127; } - push( @PARTITIONS, { 'name' => 'swap', 'size' => '', 'type' => 'swap', 'mountpoint' => '', 'options' => '', 'imagetype' => 'phy:', 'image' => $swap_img } ) - unless( $CONFIG{'noswap'} ); + push( + @PARTITIONS, + { + 'name' => 'swap', + 'size' => '', + 'type' => 'swap', + 'mountpoint' => '', + 'options' => '', + 'imagetype' => 'phy:', + 'image' => $swap_img + } + ) unless ( $CONFIG{'noswap'} ); } my $options = 'errors=remount-ro'; @@ -2549,16 +2640,27 @@ sub usePhysicalDevice { $phys_img = $CONFIG{'image-dev'}; - push( @PARTITIONS, { 'name' => 'disk', 'size' => '', 'type' => $CONFIG{'fs'}, 'mountpoint' => '/', 'options' => $options, 'imagetype' => 'phy:', 'image' => $phys_img } ); + push( + @PARTITIONS, + { + 'name' => 'disk', + 'size' => '', + 'type' => $CONFIG{'fs'}, + 'mountpoint' => '/', + 'options' => $options, + 'imagetype' => 'phy:', + 'image' => $phys_img + } + ); } else { - logprint( "No image-dev parameter given. Aborting.\n" ); + logprint("No image-dev parameter given. Aborting.\n"); exit 127; } createFilesystem( $phys_img, $CONFIG{'fs'} ); - createSwap( $swap_img ) unless ( $CONFIG{'noswap'} ); + createSwap($swap_img) unless ( $CONFIG{'noswap'} ); } @@ -2574,35 +2676,38 @@ sub usePhysicalDevice sub createLVMBits { + # # Check whether the disk volume exists already, and if so abort # unless '--force' is specified. # - foreach my $partition ( @PARTITIONS ) + foreach my $partition (@PARTITIONS) { - my $disk = $CONFIG{'hostname'} . '-' . $partition->{'name'}; + my $disk = $CONFIG{'hostname'} . '-' . $partition->{'name'}; my $lvm_disk = "/dev/$CONFIG{'lvm'}/$disk"; if ( -e $lvm_disk ) { + # Delete if forcing if ( $CONFIG{'force'} ) { - logprint( "Removing $lvm_disk - since we're forcing the install\n" ); - runCommand( "lvremove --force $lvm_disk" ); + logprint( + "Removing $lvm_disk - since we're forcing the install\n"); + runCommand("lvremove --force $lvm_disk"); } else { - logprint( "The LVM disk image already exists. Aborting.\n" ); - logprint( "Specify '--force' to delete and recreate\n" ); + logprint("The LVM disk image already exists. Aborting.\n"); + logprint("Specify '--force' to delete and recreate\n"); exit 127; } } } - foreach my $partition ( @PARTITIONS ) + foreach my $partition (@PARTITIONS) { - my $disk = $CONFIG{'hostname'} . '-' . $partition->{'name'}; + my $disk = $CONFIG{'hostname'} . '-' . $partition->{'name'}; my $lvm_disk = "/dev/$CONFIG{'lvm'}/$disk"; # @@ -2614,20 +2719,23 @@ sub createLVMBits # # The commands to create the volume. # - my $disk_cmd = "lvcreate $CONFIG{'lvm'} -L $partition->{'size'} -n $disk"; + my $disk_cmd = + "lvcreate $CONFIG{'lvm'} -L $partition->{'size'} -n $disk"; # # Create the volume # - runCommand( $disk_cmd ); + runCommand($disk_cmd); # # Make sure that worked. # - if ( ! -e $lvm_disk ) + if ( !-e $lvm_disk ) { - logprint( "The LVM partition image creation failed to create $lvm_disk.\n" ); - logprint( "aborting\n" ); + logprint( + "The LVM partition image creation failed to create $lvm_disk.\n" + ); + logprint("aborting\n"); exit 127; } @@ -2636,7 +2744,7 @@ sub createLVMBits # if ( $partition->{'type'} eq 'swap' ) { - createSwap( $lvm_disk ); + createSwap($lvm_disk); } else { @@ -2660,28 +2768,34 @@ sub createLVMBits sub createEVMSBits { + # # Check whether the disk volume exists already, and if so abort # unless '--force' is specified. This is two steps with evms, # because two things need to be checked, the volume and the object. # - foreach my $partition ( @PARTITIONS ) + foreach my $partition (@PARTITIONS) { - # Check whether the EVMS volume already exists, abort unless '--force' is specified. - my $evms_volume_disk = "/dev/evms/$CONFIG{'hostname'}-$partition->{'name'}"; + +# Check whether the EVMS volume already exists, abort unless '--force' is specified. + my $evms_volume_disk = + "/dev/evms/$CONFIG{'hostname'}-$partition->{'name'}"; if ( -e $evms_volume_disk ) { + # Delete if forcing if ( $CONFIG{'force'} ) { - logprint( "Removing $evms_volume_disk - since we're forcing the install\n" ); - runCommand( "echo Delete : $evms_volume_disk | evms" ); + logprint( +"Removing $evms_volume_disk - since we're forcing the install\n" ); + runCommand("echo Delete : $evms_volume_disk | evms"); } else { - logprint( "The EVMS volume $evms_volume_disk already exists. Aborting.\n" ); - logprint( "Specify '--force' to delete and recreate\n" ); + logprint( +"The EVMS volume $evms_volume_disk already exists. Aborting.\n" ); + logprint("Specify '--force' to delete and recreate\n"); exit 127; } } @@ -2692,27 +2806,31 @@ sub createEVMSBits # # Note: $evms_object_disk is not specified directly as a device # - my $evms_object_disk = "$CONFIG{'evms'}/$CONFIG{'hostname'}-$partition->{'name'}"; + my $evms_object_disk = + "$CONFIG{'evms'}/$CONFIG{'hostname'}-$partition->{'name'}"; if ( -e $evms_object_disk ) { + # Delete if forcing if ( $CONFIG{'force'} ) { - logprint( "Removing $evms_object_disk - since we're forcing the install\n" ); - runCommand( "echo Delete : $evms_object_disk | evms" ); + logprint( +"Removing $evms_object_disk - since we're forcing the install\n" ); + runCommand("echo Delete : $evms_object_disk | evms"); } else { - logprint( "The EVMS object $evms_object_disk already exists. Aborting.\n" ); - logprint( "Specify '--force' to delete and recreate\n" ); + logprint( +"The EVMS object $evms_object_disk already exists. Aborting.\n" ); + logprint("Specify '--force' to delete and recreate\n"); exit 127; } } } - foreach my $partition ( @PARTITIONS ) + foreach my $partition (@PARTITIONS) { - my $disk = $CONFIG{'hostname'} . '-' . $partition->{'name'}; + my $disk = $CONFIG{'hostname'} . '-' . $partition->{'name'}; my $evms_disk = "/dev/evms/$disk"; # @@ -2744,25 +2862,27 @@ sub createEVMSBits # # create the object # - my $disk_cmd_object = "echo allocate : $CONFIG{'evms'}/Freespace, size=$CONFIG{'size'}, name=$disk | evms"; + my $disk_cmd_object = +"echo allocate : $CONFIG{'evms'}/Freespace, size=$CONFIG{'size'}, name=$disk | evms"; # # these will be piped to evms, but gotta check it first # - my $disk_cmd_volume = "echo create : Volume, $CONFIG{'evms'}/$disk, name=$disk | evms"; + my $disk_cmd_volume = + "echo create : Volume, $CONFIG{'evms'}/$disk, name=$disk | evms"; # # Create the volumes # - runCommand( $disk_cmd_object ); - runCommand( $disk_cmd_volume ); + runCommand($disk_cmd_object); + runCommand($disk_cmd_volume); # # Initialise the partition with the relevant filesystem. # if ( $partition->{'type'} eq 'swap' ) { - createSwap( $disk_cmd_volume ); + createSwap($disk_cmd_volume); } else { @@ -2784,13 +2904,13 @@ sub createEVMSBits sub createFilesystem { - my( $image, $fs ) = ( @_ ); + my ( $image, $fs ) = (@_); # # We have the filesystem the user wanted, make sure that the # binary exists. # - my $command = $CONFIG{ "make_fs_" . $fs }; + my $command = $CONFIG{"make_fs_" . $fs}; # # Split the command into "binary" + "args". Make sure that @@ -2798,30 +2918,32 @@ sub createFilesystem # if ( $command =~ /([^ ]+) (.*)$/ ) { - my $binary = $1; - my $args = $2; + my $binary = $1; + my $args = $2; - if ( ! defined( findBinary( $binary ) ) ) - { - logprint( "The binary '$binary' required to create the filesystem $fs is missing\n" ); - exit 127; - } + if ( !defined( findBinary($binary) ) ) + { + logprint( +"The binary '$binary' required to create the filesystem $fs is missing\n" ); + exit 127; + } } else { - logprint( "The filesystem creation hash is bogus for filesystem : $fs\n" ); - exit 127; + logprint( + "The filesystem creation hash is bogus for filesystem : $fs\n"); + exit 127; } # # OK we have the command and the filesystem. Create it. # - logprint( "\nCreating $fs filesystem on $image\n" ); + logprint("\nCreating $fs filesystem on $image\n"); $command .= $image; - runCommand( $command ); - logprint( "Done\n" ); + runCommand($command); + logprint("Done\n"); } @@ -2836,12 +2958,12 @@ sub createFilesystem sub createSwap { - my ( $path ) = ( @_ ); + my ($path) = (@_); - logprint( "\nCreating swap on $path\n" ); + logprint("\nCreating swap on $path\n"); - runCommand( "mkswap $path" ); - logprint( "Done\n" ); + runCommand("mkswap $path"); + logprint("Done\n"); } @@ -2857,12 +2979,13 @@ sub createSwap sub mountImage { + # # Create a temporary mount-point to use for the image/volume. # $MOUNT_POINT = tempdir( CLEANUP => 1 ); - foreach my $partition ( @PARTITIONS ) + foreach my $partition (@PARTITIONS) { if ( $partition->{'type'} ne 'swap' ) { @@ -2875,7 +2998,7 @@ sub mountImage # Lookup the correct arguments to pass to mount. # my $mount_cmd; - my $mount_type = $CONFIG{'mount_fs_' . $partition->{'type'} }; + my $mount_type = $CONFIG{'mount_fs_' . $partition->{'type'}}; # # LVM partition @@ -2886,7 +3009,7 @@ sub mountImage } elsif ( $CONFIG{'evms'} ) { - $mount_cmd = "mount $mount_type $image $mountpoint"; + $mount_cmd = "mount $mount_type $image $mountpoint"; } elsif ( $CONFIG{'image-dev'} ) { @@ -2896,7 +3019,7 @@ sub mountImage { $mount_cmd = "mount $mount_type -o loop $image $mountpoint"; } - runCommand( $mount_cmd ); + runCommand($mount_cmd); } } @@ -2916,6 +3039,7 @@ sub mountImage sub installSystem { + # # We might have a per-distro mirror. my $distMirror = "mirror_" . $CONFIG{'dist'}; @@ -2928,12 +3052,14 @@ sub installSystem # # Basic command # - my $cmd = "xt-install-image --hostname=$CONFIG{'hostname'} --location=$MOUNT_POINT --dist=$CONFIG{'dist'} --install-method=$CONFIG{'install-method'}"; + my $cmd = +"xt-install-image --hostname=$CONFIG{'hostname'} --location=$MOUNT_POINT --dist=$CONFIG{'dist'} --install-method=$CONFIG{'install-method'}"; # # Add on the install source if required. # - $cmd .= " --install-source=$CONFIG{'install-source'}" if ( defined( $CONFIG{'install-source'} ) ); + $cmd .= " --install-source=$CONFIG{'install-source'}" + if ( defined( $CONFIG{'install-source'} ) ); # # Do we have a per-image configuration file? @@ -2971,15 +3097,24 @@ sub installSystem # # Show the user what they are installing # - logprint( "Installation method: $CONFIG{'install-method'}\n" ); - logprint( "(Source: $CONFIG{'install-source'})\n" ) if defined( $CONFIG{'install-source'} ); + logprint("Installation method: $CONFIG{'install-method'}\n"); + + # + # And where from, if relevant. + # + if ( ( lc( $CONFIG{'install-method'} ) eq "copy" ) + || ( lc( $CONFIG{'install-method'} ) eq "image-server" ) + || ( lc( $CONFIG{'install-method'} ) eq "tar" ) ) + { + logprint("(Source: $CONFIG{'install-source'})\n"); + } # # Run the command. # - runCommand( $cmd ); - logprint( "Done\n" ); + runCommand($cmd); + logprint("Done\n"); } @@ -2999,6 +3134,7 @@ sub installSystem sub exportEnvironment { + # # Per-distribution mirror? # @@ -3037,14 +3173,15 @@ sub exportEnvironment sub runCustomisationHooks { + # # Before running any scripts we'll mount /proc in the guest. # # 1. Make sure there is a directory. - mkdir( $MOUNT_POINT . "/proc", 0755 ) if ( ! -d $MOUNT_POINT . "/proc" ); + mkdir( $MOUNT_POINT . "/proc", 0755 ) if ( !-d $MOUNT_POINT . "/proc" ); # 2. Mount - runCommand( "mount -o bind /proc $MOUNT_POINT/proc" ); + runCommand("mount -o bind /proc $MOUNT_POINT/proc"); # # Now update the environment for each defined IP address. @@ -3059,13 +3196,13 @@ sub runCustomisationHooks my $ips = $CONFIG{'ip'}; my $count = 1; - foreach my $i ( @$ips ) + foreach my $i (@$ips) { - $ENV{'ip' . $count } = $i; + $ENV{'ip' . $count} = $i; $count += 1; } - $ENV{'ip_count'} = ($count - 1); + $ENV{'ip_count'} = ( $count - 1 ); # @@ -3073,8 +3210,8 @@ sub runCustomisationHooks # if ( $CONFIG{'verbose'} ) { - logprint( "Customization Script Environment:\n" ); - logprint( "---------------------------------\n" ); + logprint("Customization Script Environment:\n"); + logprint("---------------------------------\n"); foreach my $key ( sort keys %ENV ) { logprint( "\t'" . $key . "' = '" . $ENV{$key} . "'\n" ); @@ -3085,25 +3222,25 @@ sub runCustomisationHooks # # Actually run the appropriate hooks # - my $customize = "xt-customize-image --dist=$CONFIG{'dist'} --location=$MOUNT_POINT"; + my $customize = + "xt-customize-image --dist=$CONFIG{'dist'} --location=$MOUNT_POINT"; if ( $CONFIG{'verbose'} ) { $customize .= " --verbose"; } - logprint( "\nRunning hooks\n" ); - runCommand( $customize ); - logprint( "Done\n" ); + logprint("\nRunning hooks\n"); + runCommand($customize); + logprint("Done\n"); # # Unmount /proc in the guest install. # - runCommand( "umount $MOUNT_POINT/proc" ); + runCommand("umount $MOUNT_POINT/proc"); } - =begin doc Find a useable IP address from the file /etc/xen-tools/ips.txt. @@ -3114,30 +3251,33 @@ sub runCustomisationHooks sub findIP { + # Abort if we don't have the IP file. - return undef if ( ! -e $CONFIG{'ipfile'} ); + return undef if ( !-e $CONFIG{'ipfile'} ); # # Open and read the file. # - open( RANGE, "<", $CONFIG{'ipfile'} ) or die "Failed to read $CONFIG{'ipfile'} - $!"; + open( RANGE, "<", $CONFIG{'ipfile'} ) + or die "Failed to read $CONFIG{'ipfile'} - $!"; my @lines = ; my @updated; - close( RANGE ); + close(RANGE); # # Find an unclaimed line. # my $ip = undef; - foreach my $line ( @lines ) + foreach my $line (@lines) { + # skip empty lines. - next if ( !defined( $line ) ); - next if ( !length( $line ) ); - chomp( $line ); + next if ( !defined($line) ); + next if ( !length($line) ); + chomp($line); # find an IP. - if ( ( !defined( $ip ) ) && ( $line =~ /^([0-9\.]+)$/ ) ) + if ( ( !defined($ip) ) && ( $line =~ /^([0-9\.]+)$/ ) ) { $ip = $line; $line = $ip . ": used"; @@ -3149,18 +3289,19 @@ sub findIP # # Now write out the new entries. # - open( RANGE, ">", $CONFIG{'ipfile'} ) or die "Failed to write to $CONFIG{'ipfile'} - $!"; + open( RANGE, ">", $CONFIG{'ipfile'} ) + or die "Failed to write to $CONFIG{'ipfile'} - $!"; print RANGE join( "\n", @updated ); - close( RANGE ); + close(RANGE); # # Sanity check - handle the old case where the format of the file # was different. # - if ( defined( $ip ) ) + if ( defined($ip) ) { my @tmp = split( /\./, $ip ); - if ( scalar( @tmp ) < 3 ) + if ( scalar(@tmp) < 3 ) { print <>", "/var/log/xen-tools/$CONFIG{'hostname'}.log" ) or return; print LOGFILE $text; - close( LOGFILE ); + close(LOGFILE); } } @@ -3413,13 +3557,14 @@ sub logprint sub findBinary { - my( $bin ) = (@_); + my ($bin) = (@_); # strip any path which might be present. - $bin = $2 if ( $bin =~ /(.*)[\/\\](.*)/ ); + $bin = $2 if ( $bin =~ /(.*)[\/\\](.*)/ ); foreach my $entry ( split( /:/, $ENV{'PATH'} ) ) { + # guess of location. my $guess = $entry . "/" . $bin; @@ -3446,12 +3591,12 @@ sub findBinary sub runCommand { - my ( $cmd ) = (@_ ); + my ($cmd) = (@_); # # Set a local if we don't have one. # - $ENV{'LC_ALL'} = "C" unless( $ENV{'LC_ALL'} ); + $ENV{'LC_ALL'} = "C" unless ( $ENV{'LC_ALL'} ); # # Header. @@ -3473,8 +3618,8 @@ sub runCommand if ( $? != 0 ) { - logprint( "Running command '$cmd' failed.\n" ); - logprint( "Aborting\n" ); + logprint("Running command '$cmd' failed.\n"); + logprint("Aborting\n"); $FAIL = 1; exit 127; } @@ -3483,7 +3628,6 @@ sub runCommand - =begin doc Unmount any mount-points which are below the given path. @@ -3497,7 +3641,7 @@ sub runCommand sub unMountImage { - my ( $point ) = ( @_ ); + my ($point) = (@_); # # Open /proc/mount and get a list of currently mounted paths @@ -3507,8 +3651,9 @@ sub unMountImage open( MOUNTED, "<", "/proc/mounts" ) or die "Failed to open mount list"; - foreach my $line ( ) + foreach my $line () { + # # Split into the device and mountpoint. # @@ -3519,7 +3664,7 @@ sub unMountImage push @points, $path; } } - close( MOUNTED ); + close(MOUNTED); # # Now we have a list of mounts. We need to move the @@ -3530,10 +3675,10 @@ sub unMountImage @points = sort @points; @points = reverse @points; - foreach my $path ( @points ) + foreach my $path (@points) { $CONFIG{'verbose'} && print "Unmounting : $path\n"; - runCommand( "umount $path" ); + runCommand("umount $path"); } $MOUNT_POINT = undef; @@ -3551,12 +3696,13 @@ sub unMountImage sub END { + # # Unmount the image if it is still mounted. # - if ( defined( $MOUNT_POINT ) ) + if ( defined($MOUNT_POINT) ) { - unMountImage( $MOUNT_POINT ); + unMountImage($MOUNT_POINT); } # @@ -3566,9 +3712,9 @@ sub END # message is displayed - since this avoids it from being displayed # twice when --boot is used. # - if ( ( defined( $CONFIG{'hostname'} ) ) && - ( -e "/var/log/xen-tools/$CONFIG{'hostname'}.log" ) && - ( ! $CONFIG{'pid'} ) ) + if ( ( defined( $CONFIG{'hostname'} ) ) + && ( -e "/var/log/xen-tools/$CONFIG{'hostname'}.log" ) + && ( !$CONFIG{'pid'} ) ) { print "\n\nLogfile produced at:\n"; print "\t /var/log/xen-tools/$CONFIG{'hostname'}.log\n"; @@ -3578,13 +3724,15 @@ sub END # Did we fail? If so then we should remove the broken installation, # unless "--keep" was specified. # - if ( $FAIL && ( ! $CONFIG{'keep'} ) ) + if ( $FAIL && ( !$CONFIG{'keep'} ) ) { + # # Run the command # - $CONFIG{'verbose'} && logprint( "Removing failed install: $CONFIG{'hostname'}\n" ); + $CONFIG{'verbose'} + && logprint("Removing failed install: $CONFIG{'hostname'}\n"); - system( "xen-delete-image --hostname=$CONFIG{'hostname'}" ); + system("xen-delete-image --hostname=$CONFIG{'hostname'}"); } } diff --git a/bin/xen-create-nfs b/bin/xen-create-nfs index 94ed22f..bfcf281 100755 --- a/bin/xen-create-nfs +++ b/bin/xen-create-nfs @@ -140,7 +140,7 @@ $CONFIG{'xen_tools_version'} = $RELEASE; # # Read the global configuration file. # -readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); +readConfigurationFile("/etc/xen-tools/xen-tools.conf"); # @@ -161,7 +161,7 @@ testArguments(); if ( -e "/etc/xen/$CONFIG{'hostname'}.cfg" ) { die "Configuration file for $CONFIG{'hostname'} already exists" - unless( $CONFIG{'force'} ); + unless ( $CONFIG{'force'} ); } # @@ -197,20 +197,20 @@ exit; sub readConfigurationFile { - my ($file) = ( @_ ); + my ($file) = (@_); # Don't read the file if it doesn't exist. - return if ( ! -e $file ); + return if ( !-e $file ); my $line = ""; open( FILE, "<", $file ) or die "Cannot read file '$file' - $!"; - while (defined($line = ) ) + while ( defined( $line = ) ) { chomp $line; - if ($line =~ s/\\$//) + if ( $line =~ s/\\$// ) { $line .= ; redo unless eof(FILE); @@ -220,7 +220,7 @@ sub readConfigurationFile next if ( $line =~ /^([ \t]*)\#/ ); # Skip blank lines - next if ( length( $line ) < 1 ); + next if ( length($line) < 1 ); # Strip trailing comments. if ( $line =~ /(.*)\#(.*)/ ) @@ -243,6 +243,7 @@ sub readConfigurationFile # command expansion? if ( $val =~ /(.*)`([^`]+)`(.*)/ ) { + # store my $pre = $1; my $cmd = $2; @@ -250,18 +251,18 @@ sub readConfigurationFile # get output my $output = `$cmd`; - chomp( $output ); + chomp($output); # build up replacement. $val = $pre . $output . $post; } # Store value. - $CONFIG{ $key } = $val; + $CONFIG{$key} = $val; } } - close( FILE ); + close(FILE); } @@ -286,48 +287,48 @@ sub parseCommandLineArguments # GetOptions( - # Networking options - "dhcp", \$CONFIG{'dhcp'}, - "gateway=s", \$CONFIG{'gateway'}, - "broadcast=s", \$CONFIG{'broadcast'}, - "ip=s", \$CONFIG{'ip'}, - "netmask=s", \$CONFIG{'netmask'}, - "hostname=s", \$CONFIG{'hostname'}, - "memory=s", \$CONFIG{'memory'}, - "mac=s", \$CONFIG{'mac'}, + # Networking options + "dhcp", \$CONFIG{'dhcp'}, + "gateway=s", \$CONFIG{'gateway'}, + "broadcast=s", \$CONFIG{'broadcast'}, + "ip=s", \$CONFIG{'ip'}, + "netmask=s", \$CONFIG{'netmask'}, + "hostname=s", \$CONFIG{'hostname'}, + "memory=s", \$CONFIG{'memory'}, + "mac=s", \$CONFIG{'mac'}, - # NFS options. - "nfs_server=s", \$CONFIG{'nfs_server'}, - "nfs_root=s", \$CONFIG{'nfs_root'}, + # NFS options. + "nfs_server=s", \$CONFIG{'nfs_server'}, + "nfs_root=s", \$CONFIG{'nfs_root'}, - # Misc. options - "admins=s", \$CONFIG{'admins'}, - "kernel=s", \$CONFIG{'kernel'}, - "initrd=s", \$CONFIG{'initrd'}, - "force", \$CONFIG{'force'}, - "template=s", \$CONFIG{'template'}, + # Misc. options + "admins=s", \$CONFIG{'admins'}, + "kernel=s", \$CONFIG{'kernel'}, + "initrd=s", \$CONFIG{'initrd'}, + "force", \$CONFIG{'force'}, + "template=s", \$CONFIG{'template'}, - # Help options - "help", \$HELP, - "manual", \$MANUAL, - "verbose", \$CONFIG{'verbose'}, - "version", \$VERSION + # Help options + "help", \$HELP, + "manual", \$MANUAL, + "verbose", \$CONFIG{'verbose'}, + "version", \$VERSION - ); + ); pod2usage(1) if $HELP; - pod2usage(-verbose => 2 ) if $MANUAL; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - my $REVISION = '$Revision: 1.13 $'; + my $REVISION = '$Revision: 1.13 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { $REVISION = $1; } - logprint( "xen-create-nfs release $RELEASE - CVS: $REVISION\n" ); + logprint("xen-create-nfs release $RELEASE - CVS: $REVISION\n"); exit; } } @@ -344,10 +345,11 @@ sub parseCommandLineArguments sub testArguments { + # # Hostname is mandatory # - die "No hostname" unless( $CONFIG{'hostname'} ); + die "No hostname" unless ( $CONFIG{'hostname'} ); my @network = qw/ ip gateway netmask /; @@ -356,24 +358,24 @@ sub testArguments # if ( $CONFIG{'dhcp'} ) { - foreach my $f ( @network ) + foreach my $f (@network) { - delete( $CONFIG{ $f } ); + delete( $CONFIG{$f} ); } } else { - foreach my $f ( @network ) + foreach my $f (@network) { - die "Missing --$f" unless( $CONFIG{$f} ); + die "Missing --$f" unless ( $CONFIG{$f} ); } } # # We need an NFS server + root # - die "Missing NFS server." unless( $CONFIG{'nfs_server'} ); - die "Missing NFS root." unless( $CONFIG{'nfs_root'} ); + die "Missing NFS server." unless ( $CONFIG{'nfs_server'} ); + die "Missing NFS root." unless ( $CONFIG{'nfs_root'} ); # All OK. @@ -381,7 +383,6 @@ sub testArguments - =begin doc This routine is designed to ensure that any users specified with @@ -393,6 +394,7 @@ sub testArguments sub setupAdminUsers { + # # If we're not root we can't modify users. # @@ -401,16 +403,17 @@ sub setupAdminUsers # # If we don't have a sudoers file then we'll also ignore this. # - return if ( ! -e "/etc/sudoers" ); + return if ( !-e "/etc/sudoers" ); # # Find the path to the xen-login-shell # my $shell = undef; $shell = "/usr/bin/xen-login-shell" if ( -x "/usr/bin/xen-login-shell" ); - $shell = "/usr/local/bin/xen-login-shell" if ( -x "/usr/bin/local/xen-login-shell" ); + $shell = "/usr/local/bin/xen-login-shell" + if ( -x "/usr/bin/local/xen-login-shell" ); - return if ( !defined( $shell ) ); + return if ( !defined($shell) ); # @@ -419,6 +422,7 @@ sub setupAdminUsers # foreach my $user ( split( /,/, $ENV{'admins'} ) ) { + # Strip leading and trailing whitespace. $user =~ s/^\s+//; $user =~ s/\s+$//; @@ -429,12 +433,14 @@ sub setupAdminUsers # Does the user exist? if ( getpwnam($user) ) { + # Change shell. $CONFIG{'verbose'} && print "Changing shell for $user: $shell\n"; system( "chsh", "-s", $shell, $user ); } else { + # Add a new user. $CONFIG{'verbose'} && print "Adding new user: $user\n"; system( "useradd", "-s", $shell, $user ); @@ -443,9 +449,11 @@ sub setupAdminUsers # # Add the entry to /etc/sudoers. # - open( SUDOERS, ">>", "/etc/sudoers" ) or warn "Failed to add user to sudoers file : $user - $!"; - print SUDOERS "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n"; - close( SUDOERS ); + open( SUDOERS, ">>", "/etc/sudoers" ) + or warn "Failed to add user to sudoers file : $user - $!"; + print SUDOERS + "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n"; + close(SUDOERS); } } @@ -461,7 +469,8 @@ sub setupAdminUsers sub createNewConfigurationFile { - die "Template file missing: $CONFIG{'template'}" unless( -e $CONFIG{'template'} ); + die "Template file missing: $CONFIG{'template'}" + unless ( -e $CONFIG{'template'} ); # # Load the template. @@ -469,7 +478,7 @@ sub createNewConfigurationFile my $template = new Text::Template( TYPE => 'FILE', SOURCE => $CONFIG{'template'} ); - my $result = $template->fill_in( HASH => \%CONFIG ); + my $result = $template->fill_in( HASH => \%CONFIG ); # # The file we'll write to. @@ -481,5 +490,5 @@ sub createNewConfigurationFile # open( FILE, ">", $file ) or die "Failed to write to $file - $!"; print FILE $result; - close( FILE ); + close(FILE); } diff --git a/bin/xen-delete-image b/bin/xen-delete-image index fd8809b..5bc39a6 100755 --- a/bin/xen-delete-image +++ b/bin/xen-delete-image @@ -173,13 +173,12 @@ my $RELEASE = '3.9'; - # # Read the global configuration file if it exists. # if ( -e "/etc/xen-tools/xen-tools.conf" ) { - readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); + readConfigurationFile("/etc/xen-tools/xen-tools.conf"); } @@ -199,7 +198,7 @@ checkArguments(); # # Abort if non-root user. # -if ( (!$CONFIG{'test'}) && ( $EFFECTIVE_USER_ID != 0 ) ) +if ( ( !$CONFIG{'test'} ) && ( $EFFECTIVE_USER_ID != 0 ) ) { print <) ) + while ( defined( $line = ) ) { chomp $line; - if ($line =~ s/\\$//) + if ( $line =~ s/\\$// ) { $line .= ; redo unless eof(FILE); @@ -282,7 +280,7 @@ sub readConfigurationFile next if ( $line =~ /^([ \t]*)\#/ ); # Skip blank lines - next if ( length( $line ) < 1 ); + next if ( length($line) < 1 ); # Strip trailing comments. if ( $line =~ /(.*)\#(.*)/ ) @@ -305,6 +303,7 @@ sub readConfigurationFile # command expansion? if ( $val =~ /(.*)`([^`]+)`(.*)/ ) { + # store my $pre = $1; my $cmd = $2; @@ -312,23 +311,22 @@ sub readConfigurationFile # get output my $output = `$cmd`; - chomp( $output ); + chomp($output); # build up replacement. $val = $pre . $output . $post; } # Store value. - $CONFIG{ $key } = $val; + $CONFIG{$key} = $val; } } - close( FILE ); + close(FILE); } - =begin doc Parse the arguments specified upon the command line. @@ -346,32 +344,32 @@ sub parseCommandLineArguments # Parse options. # GetOptions( - "dir=s", \$CONFIG{'dir'}, - "lvm=s", \$CONFIG{'lvm'}, - "evms=s", \$CONFIG{'evms'}, - "hostname=s@", \$CONFIG{'hostname'}, - "test", \$CONFIG{'test'}, - "verbose", \$CONFIG{'verbose'}, - "help", \$HELP, - "manual", \$MANUAL, - "version", \$VERSION - ); + "dir=s", \$CONFIG{'dir'}, + "lvm=s", \$CONFIG{'lvm'}, + "evms=s", \$CONFIG{'evms'}, + "hostname=s@", \$CONFIG{'hostname'}, + "test", \$CONFIG{'test'}, + "verbose", \$CONFIG{'verbose'}, + "help", \$HELP, + "manual", \$MANUAL, + "version", \$VERSION + ); pod2usage(1) if $HELP; - pod2usage(-verbose => 2 ) if $MANUAL; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - my $REVISION = '$Revision: 1.41 $'; + my $REVISION = '$Revision: 1.41 $'; - if ( $REVISION =~ /1.([0-9.]+) / ) - { - $REVISION = $1; - } + if ( $REVISION =~ /1.([0-9.]+) / ) + { + $REVISION = $1; + } - print "xen-delete-image release $RELEASE - CVS: $REVISION\n"; - exit; + print "xen-delete-image release $RELEASE - CVS: $REVISION\n"; + exit; } } @@ -388,6 +386,7 @@ sub parseCommandLineArguments sub checkArguments { + # # When testing we only care about loopback images, not disk images. # @@ -401,7 +400,7 @@ sub checkArguments # Make sure we got one and only one installation method. # my $count = 0; - foreach my $type ( qw/dir lvm evms/ ) + foreach my $type (qw/dir lvm evms/) { $count += 1 if defined( $CONFIG{$type} ); } @@ -412,17 +411,16 @@ sub checkArguments # if ( $count != 1 ) { - print "Please select one and only one of the installation methods:\n"; - print " --dir\n"; - print " --evms\n"; - print " --lvm\n"; - exit; + print "Please select one and only one of the installation methods:\n"; + print " --dir\n"; + print " --evms\n"; + print " --lvm\n"; + exit; } } - =begin doc Test to see if the given instance is running. @@ -433,20 +431,20 @@ sub checkArguments sub xenRunning { - my( $hostname ) = (@_ ); + my ($hostname) = (@_); my $running = 0; - open( CMD, "xm list $hostname 2>/dev/null |") + open( CMD, "xm list $hostname 2>/dev/null |" ) or die "Failed to run 'xm list $hostname'"; - while( ) + while () { my $line = $_; - $running = 1 if ( $line =~ /\Q$hostname\E/ ) + $running = 1 if ( $line =~ /\Q$hostname\E/ ); } - close( CMD ); + close(CMD); - return( $running ); + return ($running); } @@ -461,7 +459,7 @@ sub xenRunning sub deleteXenImage { - my ($hostname) = ( @_ ); + my ($hostname) = (@_); # # Collect the names of files to delete. @@ -487,12 +485,12 @@ sub deleteXenImage # # If we're working on disk images remove them. # - foreach my $file ( @delete ) + foreach my $file (@delete) { if ( -e $file ) { print "Deleting: $file\n"; - unlink( $file ); + unlink($file); } else { @@ -503,69 +501,71 @@ sub deleteXenImage if ( defined( $CONFIG{'dir'} ) ) { - my $prefix = $CONFIG{'dir'} . "/domains/"; + my $prefix = $CONFIG{'dir'} . "/domains/"; - # - # Now remove the directory. - # - if ( -d $prefix . $hostname ) - { - print "Removing: " . $prefix . $hostname . "\n"; - rmdir ( $prefix . $hostname ); - } + # + # Now remove the directory. + # + if ( -d $prefix . $hostname ) + { + print "Removing: " . $prefix . $hostname . "\n"; + rmdir( $prefix . $hostname ); + } } elsif ( defined( $CONFIG{'lvm'} ) ) { - # - # LVM volumes - # - # - # TODO: Check we're not mounted. - # - if ( -e "/dev/$CONFIG{'lvm'}/$hostname-swap" ) - { - print "Removing swap volume\n"; - runCommand( "lvremove /dev/$CONFIG{'lvm'}/$hostname-swap --force" ); - } + # + # LVM volumes + # + # + # TODO: Check we're not mounted. + # - if ( -e "/dev/$CONFIG{'lvm'}/$hostname-disk" ) - { - print "Removing LVM disk volume\n"; - runCommand( "lvremove /dev/$CONFIG{'lvm'}/$hostname-disk --force" ); - } + if ( -e "/dev/$CONFIG{'lvm'}/$hostname-swap" ) + { + print "Removing swap volume\n"; + runCommand("lvremove /dev/$CONFIG{'lvm'}/$hostname-swap --force"); + } + + if ( -e "/dev/$CONFIG{'lvm'}/$hostname-disk" ) + { + print "Removing LVM disk volume\n"; + runCommand("lvremove /dev/$CONFIG{'lvm'}/$hostname-disk --force"); + } } elsif ( defined( $CONFIG{'evms'} ) ) { - # - # EVMS volumes - # - # - # TODO: Check we're not mounted. - # - if ( -e "/dev/evms/$hostname-swap" ) - { - print "Removing EVMS swap volume\n"; - runCommand( "echo Delete : /dev/evms/$hostname-swap | evms" ); - runCommand( "echo Delete : $CONFIG{'evms'}/$hostname-swap | evms" ); - } + # + # EVMS volumes + # + # + # TODO: Check we're not mounted. + # - if ( -e "/dev/evms/$hostname-disk" ) - { - print "Removing EVMS disk volume\n"; - runCommand( "echo Delete : /dev/evms/$hostname-disk | evms" ); - runCommand( "echo Delete : $CONFIG{'evms'}/$hostname-disk | evms" ); - } + if ( -e "/dev/evms/$hostname-swap" ) + { + print "Removing EVMS swap volume\n"; + runCommand("echo Delete : /dev/evms/$hostname-swap | evms"); + runCommand("echo Delete : $CONFIG{'evms'}/$hostname-swap | evms"); + } + + if ( -e "/dev/evms/$hostname-disk" ) + { + print "Removing EVMS disk volume\n"; + runCommand("echo Delete : /dev/evms/$hostname-disk | evms"); + runCommand("echo Delete : $CONFIG{'evms'}/$hostname-disk | evms"); + } } else { - print "Error: No installation type specified\n"; - print "Can't happen!\n"; - print "Hostname : $hostname\n"; - exit 127; + print "Error: No installation type specified\n"; + print "Can't happen!\n"; + print "Hostname : $hostname\n"; + exit 127; } } @@ -584,7 +584,7 @@ sub deleteXenImage sub runCommand { - my ( $cmd ) = (@_ ); + my ($cmd) = (@_); # # Header. @@ -596,14 +596,15 @@ sub runCommand # if ( $CONFIG{'verbose'} ) { - # - # Copy stderr to stdout, so we can see it. - # - $cmd .= " 2>&1"; + + # + # Copy stderr to stdout, so we can see it. + # + $cmd .= " 2>&1"; } else { - $cmd .= " >/dev/null 2>/dev/null" ; + $cmd .= " >/dev/null 2>/dev/null"; } @@ -614,9 +615,9 @@ sub runCommand if ( $? != 0 ) { - print "Running command '$cmd' failed.\n"; - print "Aborting\n"; - exit; + print "Running command '$cmd' failed.\n"; + print "Aborting\n"; + exit; } @@ -628,5 +629,5 @@ sub runCommand $CONFIG{'verbose'} && print $output . "\n"; $CONFIG{'verbose'} && print "Finished : $cmd\n"; - return( $output ); + return ($output); } diff --git a/bin/xen-list-images b/bin/xen-list-images index a541732..c3bc1ad 100755 --- a/bin/xen-list-images +++ b/bin/xen-list-images @@ -109,7 +109,7 @@ my $RELEASE = '3.9'; # # Read the global configuration file if it exists. # -readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); +readConfigurationFile("/etc/xen-tools/xen-tools.conf"); # @@ -129,11 +129,11 @@ my @instances = findXenInstances(); # Now process each instance. # my $count = 0; -foreach my $instance ( @instances ) +foreach my $instance (@instances) { - if ( $count ) { print "\n"; } + if ($count) { print "\n"; } - displayInstance( $instance ); + displayInstance($instance); $count += 1; } @@ -155,18 +155,18 @@ exit; sub readConfigurationFile { - my ($file) = ( @_ ); + my ($file) = (@_); # Don't read the file if it doesn't exist. - return if ( ! -e $file ); + return if ( !-e $file ); open( FILE, "<", $file ) or die "Cannot read file '$file' - $!"; - while (defined(my $line = ) ) + while ( defined( my $line = ) ) { chomp $line; - if ($line =~ s/\\$//) + if ( $line =~ s/\\$// ) { $line .= ; redo unless eof(FILE); @@ -176,7 +176,7 @@ sub readConfigurationFile next if ( $line =~ /^([ \t]*)\#/ ); # Skip blank lines - next if ( length( $line ) < 1 ); + next if ( length($line) < 1 ); # Strip trailing comments. if ( $line =~ /(.*)\#(.*)/ ) @@ -199,6 +199,7 @@ sub readConfigurationFile # command expansion? if ( $val =~ /(.*)`([^`]+)`(.*)/ ) { + # store my $pre = $1; my $cmd = $2; @@ -206,22 +207,21 @@ sub readConfigurationFile # get output my $output = `$cmd`; - chomp( $output ); + chomp($output); # build up replacement. $val = $pre . $output . $post; } # Store value. - $CONFIG{ $key } = $val; + $CONFIG{$key} = $val; } } - close( FILE ); + close(FILE); } - =begin doc Parse the arguments specified upon the command line. @@ -234,24 +234,20 @@ sub parseCommandLineArguments { my $HELP = 0; my $MANUAL = 0; - my $VERSION = 0; + my $VERSION = 0; # Parse options. # - GetOptions( - "test=s", \$CONFIG{'prefix'}, - "help", \$HELP, - "manual", \$MANUAL, - "version", \$VERSION - ); + GetOptions( "test=s", \$CONFIG{'prefix'}, "help", \$HELP, "manual", + \$MANUAL, "version", \$VERSION ); pod2usage(1) if $HELP; - pod2usage(-verbose => 2 ) if $MANUAL; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - my $REVISION = '$Revision: 1.30 $'; + my $REVISION = '$Revision: 1.30 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { $REVISION = $1; @@ -282,7 +278,7 @@ sub findXenInstances push @found, $file if ( -e $file ); } - return( @found ); + return (@found); } @@ -298,14 +294,14 @@ sub findXenInstances sub displayInstance { - my ( $file ) = ( @_ ); + my ($file) = (@_); # # Read each line. # open( FILY, "<", $file ); my @LINES = ; - close( FILY ); + close(FILY); # # Is it dynamic? @@ -316,7 +312,7 @@ sub displayInstance my $name = ''; my $mem = 0; - foreach my $line ( @LINES ) + foreach my $line (@LINES) { if ( $line =~ /^\s*dhcp\s*=\s*"dhcp\"/i ) { @@ -342,7 +338,7 @@ sub displayInstance print "Name: $name\n"; print "Memory: $mem\n"; - print "IP: " . $ip . $mac . "\n" if length( $ip ); + print "IP: " . $ip . $mac . "\n" if length($ip); print "DHCP" . $mac . "\n" if $dhcp; } diff --git a/bin/xen-resize-guest b/bin/xen-resize-guest index 1fecafb..f4809d2 100755 --- a/bin/xen-resize-guest +++ b/bin/xen-resize-guest @@ -107,8 +107,6 @@ use Text::Template; - - # # Configuration values read from the command line, or configuration file. # @@ -125,7 +123,7 @@ my $RELEASE = '3.9'; # # Read the global configuration file. # -readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); +readConfigurationFile("/etc/xen-tools/xen-tools.conf"); # @@ -147,11 +145,12 @@ my $path = undef; if ( $CONFIG{'dir'} ) { + # # Make sure we can find the disk # $path = $CONFIG{'dir'} . "/domains/" . $CONFIG{'hostname'} . "/disk.img"; - if ( ! -e $path ) + if ( !-e $path ) { print <) ) + while ( defined( $line = ) ) { chomp $line; - if ($line =~ s/\\$//) + if ( $line =~ s/\\$// ) { $line .= ; redo unless eof(FILE); @@ -317,7 +317,7 @@ sub readConfigurationFile next if ( $line =~ /^([ \t]*)\#/ ); # Skip blank lines - next if ( length( $line ) < 1 ); + next if ( length($line) < 1 ); # Strip trailing comments. if ( $line =~ /(.*)\#(.*)/ ) @@ -340,6 +340,7 @@ sub readConfigurationFile # command expansion? if ( $val =~ /(.*)`([^`]+)`(.*)/ ) { + # store my $pre = $1; my $cmd = $2; @@ -347,18 +348,18 @@ sub readConfigurationFile # get output my $output = `$cmd`; - chomp( $output ); + chomp($output); # build up replacement. $val = $pre . $output . $post; } # Store value. - $CONFIG{ $key } = $val; + $CONFIG{$key} = $val; } } - close( FILE ); + close(FILE); } @@ -387,27 +388,27 @@ sub parseCommandLineArguments # GetOptions( - # Misc. options - "add=s", \$CONFIG{'add'}, - "dir=s", \$install{'dir'}, - "lvm=s", \$install{'lvm'}, - "hostname=s", \$CONFIG{'hostname'}, - "force", \$CONFIG{'force'}, + # Misc. options + "add=s", \$CONFIG{'add'}, + "dir=s", \$install{'dir'}, + "lvm=s", \$install{'lvm'}, + "hostname=s", \$CONFIG{'hostname'}, + "force", \$CONFIG{'force'}, - # Help options - "help", \$HELP, - "manual", \$MANUAL, - "verbose", \$CONFIG{'verbose'}, - "version", \$VERSION - ); + # Help options + "help", \$HELP, + "manual", \$MANUAL, + "verbose", \$CONFIG{'verbose'}, + "version", \$VERSION + ); pod2usage(1) if $HELP; - pod2usage(-verbose => 2 ) if $MANUAL; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - print( "xen-resize-guest release $RELEASE\n" ); + print("xen-resize-guest release $RELEASE\n"); exit 1; } @@ -442,6 +443,7 @@ sub parseCommandLineArguments sub testArguments { + # # Make sure we received a hostname. # @@ -486,8 +488,8 @@ EOF # We should either have LVM *or* directory - not neither or both. # my $options = 0; - $options += 1if ( defined($CONFIG{'lvm'}) && length( $CONFIG{'lvm'} ) ); - $options += 1if ( defined($CONFIG{'dir'}) && length( $CONFIG{'dir'} ) ); + $options += 1 if ( defined( $CONFIG{'lvm'} ) && length( $CONFIG{'lvm'} ) ); + $options += 1 if ( defined( $CONFIG{'dir'} ) && length( $CONFIG{'dir'} ) ); # # Report @@ -528,18 +530,18 @@ EOF sub xenRunning { - my( $hostname ) = (@_ ); + my ($hostname) = (@_); my $running = 0; - open( CMD, "xm list $hostname 2>/dev/null |") + open( CMD, "xm list $hostname 2>/dev/null |" ) or die "Failed to run 'xm list $hostname'"; - while( ) + while () { my $line = $_; - $running = 1 if ( $line =~ /\Q$hostname\E/ ) + $running = 1 if ( $line =~ /\Q$hostname\E/ ); } - close( CMD ); + close(CMD); - return( $running ); + return ($running); } diff --git a/bin/xen-update-image b/bin/xen-update-image index 8a1c613..817c2bc 100755 --- a/bin/xen-update-image +++ b/bin/xen-update-image @@ -128,7 +128,7 @@ my $RELEASE = '3.9'; # if ( -e "/etc/xen-tools/xen-tools.conf" ) { - readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); + readConfigurationFile("/etc/xen-tools/xen-tools.conf"); } @@ -166,11 +166,11 @@ E_O_ROOT # # Loop over the supplied arguments, and attempt to update each image. # -while( my $name = shift ) +while ( my $name = shift ) { - if ( !xenRunning( $name ) ) + if ( !xenRunning($name) ) { - updateXenImage( $name ); + updateXenImage($name); } else { @@ -196,7 +196,7 @@ exit; sub updateXenImage { - my ( $name ) = ( @_ ); + my ($name) = (@_); # # Create a temporary directory, and prepare to mount the @@ -212,10 +212,11 @@ sub updateXenImage # if ( $CONFIG{'dir'} ) { - # The loopback image. - $img = $CONFIG{'dir'} . "/domains/" . $name . "/disk.img"; - if ( ! -e $img ) + # The loopback image. + $img = $CONFIG{'dir'} . "/domains/" . $name . "/disk.img"; + + if ( !-e $img ) { print "Disk image '$img' for host '$name' not found\n"; return; @@ -225,11 +226,12 @@ sub updateXenImage } elsif ( $CONFIG{'lvm'} ) { + # The LVM volume $img = "/dev/" . $CONFIG{'lvm'} . "/$name-disk"; # make sure it exists. - if ( ! -e $img ) + if ( !-e $img ) { print "Logical volume '$img' for host '$name' not found\n"; return; @@ -239,23 +241,24 @@ sub updateXenImage } elsif ( $CONFIG{'evms'} ) { - # The EVMS volume -- note, unlike LVM, you don't need the $CONFIG{'evms'} - # to see it and mount the volume. $CONFIG{'evms'} is only used for manipulating - # the underlying object. Still, I don't want to mess with the parse code and - # make it confusing - otherwise --evms takes an argument everywhere but here, - # which will confuse users. The better solution is to make it so that --evms can - # take a following container, but doesn't require it. For the moment, it is - # better to leave it as it is, take a container, and then ignore it. - # The best way to do it is to just read it out of the configuration file, - # tell the user what you got and where you got it from, and not bother the user - # with picking --dir or --lvm or --evms at all, but infer it from the config - # file's disk = parameter. xen-delete-image might work the same way, but - # it could be *slightly* more dangerous in the context of deleting. +# The EVMS volume -- note, unlike LVM, you don't need the $CONFIG{'evms'} +# to see it and mount the volume. $CONFIG{'evms'} is only used for manipulating +# the underlying object. Still, I don't want to mess with the parse code and +# make it confusing - otherwise --evms takes an argument everywhere but here, +# which will confuse users. The better solution is to make it so that --evms can +# take a following container, but doesn't require it. For the moment, it is +# better to leave it as it is, take a container, and then ignore it. + + # The best way to do it is to just read it out of the configuration file, + # tell the user what you got and where you got it from, and not bother the user + # with picking --dir or --lvm or --evms at all, but infer it from the config + # file's disk = parameter. xen-delete-image might work the same way, but + # it could be *slightly* more dangerous in the context of deleting. $img = "/dev/evms/$name-disk"; # make sure it exists. - if ( ! -e $img ) + if ( !-e $img ) { print "EVMS volume '$img' for host '$name' not found\n"; return; @@ -276,23 +279,26 @@ sub updateXenImage # # Make sure this is a Debian image. # - if ( ( -e $tmp . "/usr/bin/apt-get" ) && - ( -x $tmp . "/usr/bin/apt-get" ) ) + if ( ( -e $tmp . "/usr/bin/apt-get" ) + && ( -x $tmp . "/usr/bin/apt-get" ) ) { - # - # Now run the update command. - # - system( "chroot $tmp /usr/bin/apt-get update" ); + + # + # Now run the update command. + # + system("chroot $tmp /usr/bin/apt-get update"); - # - # Now upgrade - # - system( "DEBIAN_FRONTEND=noninteractive chroot $tmp /usr/bin/apt-get upgrade --yes --force-yes" ); + # + # Now upgrade + # + system( +"DEBIAN_FRONTEND=noninteractive chroot $tmp /usr/bin/apt-get upgrade --yes --force-yes" + ); } else { - print "Xen image $name is not a Debian GNU/Linux image. Skipping\n"; + print "Xen image $name is not a Debian GNU/Linux image. Skipping\n"; } @@ -306,8 +312,6 @@ sub updateXenImage - - =begin doc Test to see if the given instance is running. @@ -318,25 +322,24 @@ sub updateXenImage sub xenRunning { - my( $hostname ) = (@_ ); + my ($hostname) = (@_); my $running = 0; - open( CMD, "xm list 2>/dev/null |") + open( CMD, "xm list 2>/dev/null |" ) or die "Failed to run 'xm list $hostname'"; - while( ) + while () { my $line = $_; - $running = 1 if ( $line =~ /\Q$hostname\E/ ) + $running = 1 if ( $line =~ /\Q$hostname\E/ ); } - close( CMD ); + close(CMD); - return( $running ); + return ($running); } - =begin doc Read the configuration file specified. @@ -347,16 +350,16 @@ sub xenRunning sub readConfigurationFile { - my ($file) = ( @_ ); + my ($file) = (@_); open( FILE, "<", $file ) or die "Cannot read file '$file' - $!"; - my $line = ""; + my $line = ""; - while (defined($line = ) ) + while ( defined( $line = ) ) { chomp $line; - if ($line =~ s/\\$//) + if ( $line =~ s/\\$// ) { $line .= ; redo unless eof(FILE); @@ -366,7 +369,7 @@ sub readConfigurationFile next if ( $line =~ /^([ \t]*)\#/ ); # Skip blank lines - next if ( length( $line ) < 1 ); + next if ( length($line) < 1 ); # Strip trailing comments. if ( $line =~ /(.*)\#(.*)/ ) @@ -389,6 +392,7 @@ sub readConfigurationFile # command expansion? if ( $val =~ /(.*)`([^`]+)`(.*)/ ) { + # store my $pre = $1; my $cmd = $2; @@ -396,23 +400,22 @@ sub readConfigurationFile # get output my $output = `$cmd`; - chomp( $output ); + chomp($output); # build up replacement. $val = $pre . $output . $post; } # Store value. - $CONFIG{ $key } = $val; + $CONFIG{$key} = $val; } } - close( FILE ); + close(FILE); } - =begin doc Parse the arguments specified upon the command line. @@ -430,20 +433,17 @@ sub parseCommandLineArguments # Parse options. # GetOptions( - "dir=s", \$CONFIG{'dir'}, - "lvm=s", \$CONFIG{'lvm'}, - "evms=s", \$CONFIG{'evms'}, - "help", \$HELP, - "manual", \$MANUAL, - "version", \$VERSION - ); + "dir=s", \$CONFIG{'dir'}, "lvm=s", \$CONFIG{'lvm'}, + "evms=s", \$CONFIG{'evms'}, "help", \$HELP, + "manual", \$MANUAL, "version", \$VERSION + ); pod2usage(1) if $HELP; - pod2usage(-verbose => 2 ) if $MANUAL; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - my $REVISION = '$Revision: 1.29 $'; + my $REVISION = '$Revision: 1.29 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { @@ -468,11 +468,12 @@ sub parseCommandLineArguments sub checkArguments { + # # Make sure we got one and only one installation method. # my $count = 0; - foreach my $type ( qw/dir lvm evms/ ) + foreach my $type (qw/dir lvm evms/) { $count += 1 if defined( $CONFIG{$type} ); } @@ -483,10 +484,10 @@ sub checkArguments # if ( $count != 1 ) { - print "Please select one and only one of the installation methods:\n"; - print " --dir\n"; - print " --evms\n"; - print " --lvm\n"; - exit; + print "Please select one and only one of the installation methods:\n"; + print " --dir\n"; + print " --evms\n"; + print " --lvm\n"; + exit; } } diff --git a/bin/xt-create-xen-config b/bin/xt-create-xen-config index f45b384..322a70c 100755 --- a/bin/xt-create-xen-config +++ b/bin/xt-create-xen-config @@ -160,7 +160,6 @@ my $RELEASE = '3.9'; - # # Parse the command line arguments. # @@ -189,9 +188,6 @@ createXenConfig(); - - - # # Exit cleanly - any errors which have already occurred will result # in "exit 1". @@ -200,9 +196,6 @@ exit 0; - - - =begin doc Parse the command line arguments this script was given. @@ -221,23 +214,23 @@ sub parseCommandLineArguments # Parse options. # GetOptions( - "admins=s", \$ENV{'admins'}, - "output=s", \$CONFIG{'output'}, - "extension=s",\$CONFIG{'extension'}, - "template=s", \$CONFIG{'template'}, - "verbose", \$CONFIG{'verbose'}, - "help", \$HELP, - "manual", \$MANUAL, - "version", \$VERSION - ); + "admins=s", \$ENV{'admins'}, + "output=s", \$CONFIG{'output'}, + "extension=s", \$CONFIG{'extension'}, + "template=s", \$CONFIG{'template'}, + "verbose", \$CONFIG{'verbose'}, + "help", \$HELP, + "manual", \$MANUAL, + "version", \$VERSION + ); pod2usage(1) if $HELP; - pod2usage(-verbose => 2 ) if $MANUAL; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - my $REVISION = '$Revision: 1.47 $'; + my $REVISION = '$Revision: 1.47 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { $REVISION = $1; @@ -260,10 +253,11 @@ sub parseCommandLineArguments sub checkArguments { + # # We require an output location. # - if ( ! defined( $CONFIG{'output'} ) ) + if ( !defined( $CONFIG{'output'} ) ) { print "The '--output' argument is mandatory\n"; exit 1; @@ -272,9 +266,10 @@ sub checkArguments # # The output location should be a directory which exists. # - if ( ! -d $CONFIG{'output'} ) + if ( !-d $CONFIG{'output'} ) { - print "The output directory we've been given, $CONFIG{'output'}, doesnt exist\n"; + print +"The output directory we've been given, $CONFIG{'output'}, doesnt exist\n"; print "Aborting\n"; exit 1; } @@ -284,9 +279,10 @@ sub checkArguments # if ( defined( $CONFIG{'template'} ) ) { - if ( ! -e $CONFIG{'template'} ) + if ( !-e $CONFIG{'template'} ) { - print "The specified template file, $CONFIG{'template'} does not exist.\n"; + print +"The specified template file, $CONFIG{'template'} does not exist.\n"; exit 1; } } @@ -310,19 +306,20 @@ sub importPartitionsFromEnvironment { @PARTITIONS = (); - for (my $i=1; $i <= $ENV{'NUMPARTITIONS'}; $i++) + for ( my $i = 1 ; $i <= $ENV{'NUMPARTITIONS'} ; $i++ ) { - my @parts = split(/:/, $ENV{'PARTITION' . $i}, 7); - push( @PARTITIONS, - { - 'name' => $parts[0], - 'size' => $parts[1], - 'type' => $parts[2], - 'mountpoint' => $parts[3], - 'options' => $parts[4], - 'imagetype' => $parts[5], - 'image' => $parts[6] - } + my @parts = split( /:/, $ENV{'PARTITION' . $i}, 7 ); + push( + @PARTITIONS, + { + 'name' => $parts[0], + 'size' => $parts[1], + 'type' => $parts[2], + 'mountpoint' => $parts[3], + 'options' => $parts[4], + 'imagetype' => $parts[5], + 'image' => $parts[6] + } ); } } @@ -341,6 +338,7 @@ sub importPartitionsFromEnvironment sub createXenConfig { + # # The output file we're going to process. # @@ -416,7 +414,7 @@ sub createXenConfig } else { - $ENV{'swap_vbd'} = undef; + $ENV{'swap_vbd'} = undef; } } else @@ -438,7 +436,7 @@ sub createXenConfig # made available to our template file. # my %vars; - foreach my $key (sort keys %ENV ) + foreach my $key ( sort keys %ENV ) { $vars{$key} = $ENV{$key}; } @@ -457,9 +455,9 @@ sub createXenConfig # # Write the output of processing the template file, if it succeeds. # - if (defined $result) + if ( defined $result ) { - print FILE $result ; + print FILE $result; } else { @@ -469,13 +467,12 @@ sub createXenConfig # # Close the output file. # - close( FILE ); + close(FILE); } - =begin doc This routine is designed to ensure that any users specified with @@ -487,6 +484,7 @@ sub createXenConfig sub setupAdminUsers { + # # If we're not root we can't modify users. # @@ -495,16 +493,17 @@ sub setupAdminUsers # # If we don't have a sudoers file then we'll also ignore this. # - return if ( ! -e "/etc/sudoers" ); + return if ( !-e "/etc/sudoers" ); # # Find the path to the xen-login-shell # my $shell = undef; $shell = "/usr/bin/xen-login-shell" if ( -x "/usr/bin/xen-login-shell" ); - $shell = "/usr/local/bin/xen-login-shell" if ( -x "/usr/bin/local/xen-login-shell" ); + $shell = "/usr/local/bin/xen-login-shell" + if ( -x "/usr/bin/local/xen-login-shell" ); - return if ( !defined( $shell ) ); + return if ( !defined($shell) ); # @@ -513,6 +512,7 @@ sub setupAdminUsers # foreach my $user ( split( /,/, $ENV{'admins'} ) ) { + # Strip leading and trailing whitespace. $user =~ s/^\s+//; $user =~ s/\s+$//; @@ -523,12 +523,14 @@ sub setupAdminUsers # Does the user exist? if ( getpwnam($user) ) { + # Change shell. $CONFIG{'verbose'} && print "Changing shell for $user: $shell\n"; system( "chsh", "-s", $shell, $user ); } else { + # Add a new user. $CONFIG{'verbose'} && print "Adding new user: $user\n"; system( "useradd", "-s", $shell, $user ); @@ -537,9 +539,11 @@ sub setupAdminUsers # # Add the entry to /etc/sudoers. # - open( SUDOERS, ">>", "/etc/sudoers" ) or warn "Failed to add user to sudoers file : $user - $!"; - print SUDOERS "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n"; - close( SUDOERS ); + open( SUDOERS, ">>", "/etc/sudoers" ) + or warn "Failed to add user to sudoers file : $user - $!"; + print SUDOERS + "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n"; + close(SUDOERS); } } diff --git a/bin/xt-customize-image b/bin/xt-customize-image index 00f871c..fba12c8 100755 --- a/bin/xt-customize-image +++ b/bin/xt-customize-image @@ -101,7 +101,6 @@ my $RELEASE = '3.9'; - # # Parse the command line arguments. # @@ -128,9 +127,6 @@ exit 0; - - - =begin doc Parse the command line arguments this script was given. @@ -149,28 +145,28 @@ sub parseCommandLineArguments # Parse options. # GetOptions( - "location=s", \$CONFIG{'location'}, - "dist=s", \$CONFIG{'dist'}, - "verbose", \$CONFIG{'verbose'}, - "help", \$HELP, - "manual", \$MANUAL, - "version", \$VERSION - ); + "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; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - my $REVISION = '$Revision: 1.33 $'; - if ( $REVISION =~ /1.([0-9.]+) / ) - { - $REVISION = $1; - } + my $REVISION = '$Revision: 1.33 $'; + if ( $REVISION =~ /1.([0-9.]+) / ) + { + $REVISION = $1; + } - print "xt-customize-image release $RELEASE - CVS: $REVISION\n"; - exit; + print "xt-customize-image release $RELEASE - CVS: $REVISION\n"; + exit; } } @@ -186,10 +182,11 @@ sub parseCommandLineArguments sub checkArguments { + # # We require a location. # - if ( ! defined( $CONFIG{'location'} ) ) + if ( !defined( $CONFIG{'location'} ) ) { print "The '--location' argument is mandatory\n"; exit 1; @@ -199,7 +196,7 @@ sub checkArguments # # Test that the location we've been given exists # - if ( ! -d $CONFIG{'location'} ) + if ( !-d $CONFIG{'location'} ) { print "The installation directory we've been given doesn't exist\n"; print "We tried to use : $CONFIG{'location'}\n"; @@ -210,7 +207,7 @@ sub checkArguments # # We require a distribution name. # - if ( ! defined( $CONFIG{'dist'} ) ) + if ( !defined( $CONFIG{'dist'} ) ) { print "The '--dist' argument is mandatory\n"; exit 1; @@ -224,9 +221,9 @@ sub checkArguments # If there are no scripts then we clearly cannot # customise it! # - my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d"; + my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d"; - if ( ! -d $dir ) + if ( !-d $dir ) { print < - { - sub => \&do_copy, - needBinary => "/bin/cp", - needDirectory => 1, - }, - "debootstrap" => - { - sub => \&do_debootstrap, - needBinary => "/usr/sbin/debootstrap", - }, - "image-server" => - { - sub => \&do_image_server, - needURL => 1, - }, - "rinse" => - { - sub => \&do_rinse, - needBinary => "/usr/bin/rinse", - }, - "rpmstrap" => - { - sub => \&do_rpmstrap, - needBinary => "/usr/bin/rpmstrap", - }, - "tar" => - { - sub => \&do_tar, - needBinary => "/bin/tar", - needFile => 1, - } +my %dispatch = ( + "copy" => { + sub => \&do_copy, + needBinary => "/bin/cp", + needDirectory => 1, + }, + "debootstrap" => { + sub => \&do_debootstrap, + needBinary => "/usr/sbin/debootstrap", + }, + "image-server" => { + sub => \&do_image_server, + needURL => 1, + }, + "rinse" => { + sub => \&do_rinse, + needBinary => "/usr/bin/rinse", + }, + "rpmstrap" => { + sub => \&do_rpmstrap, + needBinary => "/usr/bin/rpmstrap", + }, + "tar" => { + sub => \&do_tar, + needBinary => "/bin/tar", + needFile => 1, + } ); - - # # Read the global configuration file. # -readConfigurationFile( "/etc/xen-tools/xen-tools.conf" ); +readConfigurationFile("/etc/xen-tools/xen-tools.conf"); # @@ -193,7 +184,7 @@ if ( $CONFIG{'config'} ) } # Read the file, if it exists. - readConfigurationFile( $path ) if ( -e $path ); + readConfigurationFile($path) if ( -e $path ); } @@ -206,59 +197,65 @@ checkArguments(); # # Now lookup our installation type and dispatch control to it. # -if ( defined( $CONFIG{'install-method'} ) && - length( $CONFIG{'install-method'} ) ) +if ( defined( $CONFIG{'install-method'} ) + && length( $CONFIG{'install-method'} ) ) { # # Get the entry from the dispatch table. # - my $installer = $dispatch{ lc($CONFIG{'install-method'}) }; + my $installer = $dispatch{lc( $CONFIG{'install-method'} )}; - if ( defined( $installer ) ) + if ( defined($installer) ) { + # # If we found it. # # Do we need to test for a binary. - if ( ( $installer->{'needBinary'} ) && - ( ! -x $installer->{'needBinary'} ) ) + if ( ( $installer->{'needBinary'} ) + && ( !-x $installer->{'needBinary'} ) ) { - print "The following required binary for the installation was not found\n"; + print +"The following required binary for the installation was not found\n"; print "\t" . $installer->{'needBinary'} . "\n"; exit 1; } # Do we need a directory specified as the installation source? - if ( ( $installer->{'needDirectory'} ) && - ( ! $CONFIG{'install-source'} || ! -d $CONFIG{'install-source'} ) ) + if ( ( $installer->{'needDirectory'} ) + && ( !$CONFIG{'install-source'} || !-d $CONFIG{'install-source'} ) ) { print "Please specify the source directory with --install-source\n"; if ( $CONFIG{'install-source'} ) { - print "The specified directory $CONFIG{'install-source'} does not exist.\n"; + print +"The specified directory $CONFIG{'install-source'} does not exist.\n"; } exit 1; } # Do we need a file specified as the installation source? - if ( ( $installer->{'needFile'} ) && - ( ! $CONFIG{'install-source'} || ! -e $CONFIG{'install-source'} ) ) + if ( ( $installer->{'needFile'} ) + && ( !$CONFIG{'install-source'} || !-e $CONFIG{'install-source'} ) ) { print "Please specify the source file with --install-source\n"; if ( $CONFIG{'install-source'} ) { - print "The specified file $CONFIG{'install-source'} does not exist.\n"; + print +"The specified file $CONFIG{'install-source'} does not exist.\n"; } exit 1; } # Do we need an URL specified as the installation source? - if ( ( $installer->{'needURL'} ) && - ( ! $CONFIG{'install-source'} || - ( $CONFIG{'install-source'} !~ /^http/i ) ) ) + if ( + ( $installer->{'needURL'} ) + && ( !$CONFIG{'install-source'} + || ( $CONFIG{'install-source'} !~ /^http/i ) ) + ) { print "Please specify the image server URL with --install-source\n"; exit 1; @@ -276,9 +273,9 @@ if ( defined( $CONFIG{'install-method'} ) && # # Test that we have some "standard" files present. # - foreach my $file ( qw( /bin/ls /bin/cp ) ) + foreach my $file (qw( /bin/ls /bin/cp )) { - if ( ! -x $CONFIG{'location'} . $file ) + if ( !-x $CONFIG{'location'} . $file ) { print "The installation of the new system has failed.\n"; print "\n"; @@ -306,10 +303,6 @@ else - - - - =begin doc Read the specified configuration file, and update our global configuration @@ -321,20 +314,20 @@ else sub readConfigurationFile { - my ($file) = ( @_ ); + my ($file) = (@_); # Don't read the file if it doesn't exist. - return if ( ! -e $file ); + return if ( !-e $file ); my $line = ""; open( FILE, "<", $file ) or die "Cannot read file '$file' - $!"; - while (defined($line = ) ) + while ( defined( $line = ) ) { chomp $line; - if ($line =~ s/\\$//) + if ( $line =~ s/\\$// ) { $line .= ; redo unless eof(FILE); @@ -344,7 +337,7 @@ sub readConfigurationFile next if ( $line =~ /^([ \t]*)\#/ ); # Skip blank lines - next if ( length( $line ) < 1 ); + next if ( length($line) < 1 ); # Strip trailing comments. if ( $line =~ /(.*)\#(.*)/ ) @@ -367,6 +360,7 @@ sub readConfigurationFile # command expansion? if ( $val =~ /(.*)`([^`]+)`(.*)/ ) { + # store my $pre = $1; my $cmd = $2; @@ -374,18 +368,18 @@ sub readConfigurationFile # get output my $output = `$cmd`; - chomp( $output ); + chomp($output); # build up replacement. $val = $pre . $output . $post; } # Store value. - $CONFIG{ $key } = $val; + $CONFIG{$key} = $val; } } - close( FILE ); + close(FILE); } @@ -408,35 +402,36 @@ sub parseCommandLineArguments # Parse options. # GetOptions( - # Mandatory - "location=s", \$CONFIG{'location'}, - "dist=s", \$CONFIG{'dist'}, - "hostname=s", \$CONFIG{'hostname'}, - # Installation method - "install-method=s", \$CONFIG{'install-method'}, - "install-source=s", \$CONFIG{'install-source'}, + # Mandatory + "location=s", \$CONFIG{'location'}, + "dist=s", \$CONFIG{'dist'}, + "hostname=s", \$CONFIG{'hostname'}, - # Misc - "arch=s", \$CONFIG{'arch'}, - "cache=s", \$CONFIG{'cache'}, - "config=s", \$CONFIG{'config'}, - "mirror=s", \$CONFIG{'mirror'}, + # Installation method + "install-method=s", \$CONFIG{'install-method'}, + "install-source=s", \$CONFIG{'install-source'}, - # Help. - "verbose", \$CONFIG{'verbose'}, - "help", \$HELP, - "manual", \$MANUAL, - "version", \$VERSION - ); + # Misc + "arch=s", \$CONFIG{'arch'}, + "cache=s", \$CONFIG{'cache'}, + "config=s", \$CONFIG{'config'}, + "mirror=s", \$CONFIG{'mirror'}, + + # Help. + "verbose", \$CONFIG{'verbose'}, + "help", \$HELP, + "manual", \$MANUAL, + "version", \$VERSION + ); pod2usage(1) if $HELP; - pod2usage(-verbose => 2 ) if $MANUAL; + pod2usage( -verbose => 2 ) if $MANUAL; - if ( $VERSION ) + if ($VERSION) { - my $REVISION = '$Revision: 1.65 $'; + my $REVISION = '$Revision: 1.65 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { $REVISION = $1; @@ -459,10 +454,11 @@ sub parseCommandLineArguments sub checkArguments { + # # We require a location. # - if ( ! defined( $CONFIG{'location'} ) ) + if ( !defined( $CONFIG{'location'} ) ) { print "The '--location' argument is mandatory\n"; exit 1; @@ -472,7 +468,7 @@ sub checkArguments # # Test that the location we've been given exists # - if ( ! -d $CONFIG{'location'} ) + if ( !-d $CONFIG{'location'} ) { print "The installation directory we've been given doesn't exist\n"; print "We tried to use : $CONFIG{'location'}\n"; @@ -483,7 +479,7 @@ sub checkArguments # # We require a distribution name. # - if ( ! defined( $CONFIG{'dist'} ) ) + if ( !defined( $CONFIG{'dist'} ) ) { print "The '--dist' argument is mandatory\n"; exit 1; @@ -497,9 +493,9 @@ sub checkArguments # If there are no scripts then we clearly cannot # customise it! # - my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d"; + my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d"; - if ( ! -d $dir ) + if ( !-d $dir ) { print < $dest\n"; @@ -631,7 +626,7 @@ sub copyDebFiles # # Only copy if the file doesn't already exist. # - if ( ! ( -e $dest . "/" . $name ) ) + if ( !( -e $dest . "/" . $name ) ) { File::Copy::cp( $file, $dest ); } @@ -642,8 +637,6 @@ sub copyDebFiles - - ### # # Installation functions follow. @@ -652,7 +645,6 @@ sub copyDebFiles - =begin doc Install a new image of a distribution using `cp`. @@ -663,14 +655,15 @@ sub copyDebFiles sub do_copy { + # # Find the copy command to run from the configuration file. # - my $cmd = $CONFIG{'copy-cmd'} ; - if ( !defined( $cmd ) ) + my $cmd = $CONFIG{'copy-cmd'}; + if ( !defined($cmd) ) { print "Falling back to default copy command\n"; - $cmd = '/bin/cp -a $src/* $dest'; # Note: single quotes. + $cmd = '/bin/cp -a $src/* $dest'; # Note: single quotes. } # @@ -682,12 +675,11 @@ sub do_copy # # Run the copy command. # - runCommand( $cmd ); + runCommand($cmd); } - =begin doc Install a new image of Debian using 'debootstrap'. @@ -698,12 +690,13 @@ sub do_copy sub do_debootstrap { + # # The command is a little configurable - mostly to allow you # to use cdebootstrap. # - my $cmd = $CONFIG{'debootstrap-cmd'} ; - if ( !defined( $cmd ) ) + my $cmd = $CONFIG{'debootstrap-cmd'}; + if ( !defined($cmd) ) { print "Falling back to default debootstrap command\n"; $cmd = '/usr/sbin/debootstrap'; @@ -717,9 +710,10 @@ sub do_debootstrap if ( $CONFIG{'cache'} eq "yes" ) { print "\nCopying files from host to image.\n"; - runCommand( "mkdir -p $CONFIG{'location'}/var/cache/apt/archives" ); - copyDebFiles( "/var/cache/apt/archives", "$CONFIG{'location'}/var/cache/apt/archives" ); - print( "Done\n" ); + runCommand("mkdir -p $CONFIG{'location'}/var/cache/apt/archives"); + copyDebFiles( "/var/cache/apt/archives", + "$CONFIG{'location'}/var/cache/apt/archives" ); + print("Done\n"); } # @@ -736,19 +730,20 @@ sub do_debootstrap # if ( $CONFIG{'arch'} ) { - $EXTRA .= " --arch $CONFIG{'arch'}" + $EXTRA .= " --arch $CONFIG{'arch'}"; } # # This is the command we'll run # - my $command = "$cmd $EXTRA $CONFIG{'dist'} $CONFIG{'location'} $CONFIG{'mirror'}"; + my $command = + "$cmd $EXTRA $CONFIG{'dist'} $CONFIG{'location'} $CONFIG{'mirror'}"; # # Run the command. # - runCommand( $command ); + runCommand($command); # @@ -760,7 +755,7 @@ sub do_debootstrap print "\nCopying files from new installation to host.\n"; copyDebFiles( "$CONFIG{'location'}/var/cache/apt/archives", "/var/cache/apt/archives" ); - print( "Done\n" ); + print("Done\n"); } @@ -768,7 +763,6 @@ sub do_debootstrap - =begin doc Install a system using the image-server. @@ -781,6 +775,7 @@ sub do_debootstrap sub do_image_server { + # # Load the modules we require. # @@ -793,8 +788,8 @@ sub do_image_server # which users will not require for the typical installation # method(s). # - eval( $test ); - if ( $@ ) + eval($test); + if ($@) { die "The module LDP::UserAgent wasn't found...\n"; } @@ -818,15 +813,16 @@ sub do_image_server # $request .= "&arch=amd64"; $request .= "&root_device=/dev/sda"; - $request .= "&ip1=" . $ENV{'ip1'}; - $request .= "&dist=" . CGI::escapeHTML( $CONFIG{'dist'} ); + $request .= "&ip1=" . $ENV{'ip1'}; + $request .= "&dist=" . CGI::escapeHTML( $CONFIG{'dist'} ); $request .= "&hostname=" . CGI::escapeHTML( $CONFIG{'hostname'} ); # # We only care about some keys # - foreach my $k ( qw/ dhcp broadcast gateway netmask / ) + foreach my $k (qw/ dhcp broadcast gateway netmask /) { + # Skip values which aren't defined. next unless defined $ENV{$k}; @@ -848,8 +844,8 @@ sub do_image_server # # Do the creation step # - my $response = $ua->get( $request ); - if ($response->is_success) + my $response = $ua->get($request); + if ( $response->is_success ) { my $content = $response->content; @@ -857,70 +853,74 @@ sub do_image_server { my $session = $1; my $new = $CONFIG{'install-source'}; - $new .= "/fetch.cgi?session=$session"; + $new .= "/fetch.cgi?session=$session"; my $attempt = 1; # Make sure we don't wait indefinitely. - while( $attempt < $attempts ) + while ( $attempt < $attempts ) { $CONFIG{'verbose'} && print "Request: [$attempt/$attempts]\n"; # # Make a request to see if our tar file is ready yet. # - $response = $ua->head( $new ); + $response = $ua->head($new); if ( $response->is_success ) { # # Get the headers # - my $header = $response->headers(); - my $type = $header->{'content-type'}; + my $header = $response->headers(); + my $type = $header->{'content-type'}; # # OK our file is correct. # if ( $type =~ /tar/ ) { + # # Download it to the installation root. # $ua->get( $new, - ":content_file" => $CONFIG{'location'} . "/$session.tar" - ); + ":content_file" => $CONFIG{'location'} + . "/$session.tar" ); # # If it worked .. then untar, remove, and return. # - system( "cd $CONFIG{'location'} && tar --numeric-owner -xf $session.tar && rm -f $CONFIG{'location'}/$session.tar" ); + system( +"cd $CONFIG{'location'} && tar --numeric-owner -xf $session.tar && rm -f $CONFIG{'location'}/$session.tar" + ); return 1; } } - sleep( $sleep ); + sleep($sleep); $attempt += 1; } - print ( "ERROR: Timeout waiting for image to be ready." ); + print("ERROR: Timeout waiting for image to be ready."); return 0; } else { - print( "ERROR: Failed to find session. Received this:\n$content\n" ); + print( + "ERROR: Failed to find session. Received this:\n$content\n"); return 0; } } else { - print( "ERROR: Submitting the image create request failed:\n" . $response->status_line ); + print( "ERROR: Submitting the image create request failed:\n" + . $response->status_line ); return 0; } } - =begin doc Install a new distribution of GNU/Linux using the rpmstrap tool. @@ -931,17 +931,19 @@ sub do_image_server sub do_rinse { + # # The command we're going to run. # - my $command = "rinse --distribution=$CONFIG{'dist'} --directory=$CONFIG{'location'}"; + my $command = + "rinse --distribution=$CONFIG{'dist'} --directory=$CONFIG{'location'}"; # # Propogate the --arch argument # if ( $CONFIG{'arch'} ) { - $command .= " --arch $CONFIG{'arch'}" + $command .= " --arch $CONFIG{'arch'}"; } @@ -953,7 +955,7 @@ sub do_rinse $command .= " --verbose"; } - runCommand( $command ); + runCommand($command); } @@ -972,7 +974,7 @@ sub do_rpmstrap # # Propogate the verbosity setting. # - my $EXTRA=''; + my $EXTRA = ''; if ( $CONFIG{'verbose'} ) { $EXTRA .= " --verbose"; @@ -990,18 +992,17 @@ sub do_rpmstrap # Setup mirror if present. # my $mirror = ""; - $mirror = $CONFIG{'mirror'} if ( $CONFIG{'mirror'} ); + $mirror = $CONFIG{'mirror'} if ( $CONFIG{'mirror'} ); # # The command we're going to run. # my $command = "rpmstrap $EXTRA $CONFIG{'dist'} $CONFIG{'location'} $mirror"; - runCommand( $command ); + runCommand($command); } - =begin doc Install a new image of a distribution using `tar`. @@ -1012,14 +1013,15 @@ sub do_rpmstrap sub do_tar { + # # Find the tar command to run from the configuration file. # - my $cmd = $CONFIG{'tar-cmd'} ; - if ( !defined( $cmd ) ) + my $cmd = $CONFIG{'tar-cmd'}; + if ( !defined($cmd) ) { print "Falling back to default tar command\n"; - $cmd = '/bin/tar --numeric-owner -xvf $src'; # Note: single quotes. + $cmd = '/bin/tar --numeric-owner -xvf $src'; # Note: single quotes. } # @@ -1030,5 +1032,5 @@ sub do_tar # # Run a command to copy an installed system into the new root. # - runCommand( "cd $CONFIG{'location'} && $cmd" ); + runCommand("cd $CONFIG{'location'} && $cmd"); } diff --git a/debian/changelog b/debian/changelog index 14a7500..4b286ca 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,18 @@ +xen-tools (3.9-5) unstable; urgency=medium + + - Record the ARCH for RPM-based distros. + (Closes: #475125) + - Abort if the generated configuration file already exists. + (Closes: #499475) + + -- Steve Kemp Mon, 13 Oct 2008 19:20:21 +0000 + xen-tools (3.9-4) unstable; urgency=high * Changed two defaults in xen-tools.conf to conform to the defaults used by the xen packages: + serial_device: tty1 -> hvc0 - + disk_device: sda -> xvda + + disk_device: sda -> xvda * Priority High because of RC bug. (closes: #499282) diff --git a/debian/control b/debian/control index c995f12..398a62f 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: extra Maintainer: Roland Stigge Uploaders: Radu Spineanu , Steve Kemp Build-Depends: debhelper (>= 4.0.0), libtest-pod-perl, libtext-template-perl -Standards-Version: 3.7.3 +Standards-Version: 3.8.0 Homepage: http://xen-tools.org/software/xen-tools Package: xen-tools diff --git a/hooks/centos-4/15-setup-arch b/hooks/centos-4/15-setup-arch new file mode 100644 index 0000000..569d572 --- /dev/null +++ b/hooks/centos-4/15-setup-arch @@ -0,0 +1,44 @@ +#!/bin/sh + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Record arch, if present. +# +if [ -d $prefix/etc/rpm ]; then + + logMessage Found /etc/rpm + + # + # If i386 then record this + # + if [ "$arch" = "i386" ]; then + echo "i386-fedora-linux-gnu" >> $prefix/etc/rpm/platform + fi +else + + logMessage Failed to find /etc/rpm + +fi + +# +# Log our finish +# +logMessage Script $0 finished + diff --git a/hooks/centos-4/50-setup-hostname b/hooks/centos-4/50-setup-hostname index 02daf27..ed302b9 100755 --- a/hooks/centos-4/50-setup-hostname +++ b/hooks/centos-4/50-setup-hostname @@ -91,7 +91,7 @@ if [ -z "${dhcp}" ]; then logMessage Adding ${hostname} and ${name} to /etc/hosts on the host - echo "${ip1} ${hostname} ${name}" >> /etc/hosts + echo "${ip1} ${hostname} ${name}" >> /etc/hosts # diff --git a/hooks/centos-5/15-setup-arch b/hooks/centos-5/15-setup-arch new file mode 100644 index 0000000..569d572 --- /dev/null +++ b/hooks/centos-5/15-setup-arch @@ -0,0 +1,44 @@ +#!/bin/sh + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Record arch, if present. +# +if [ -d $prefix/etc/rpm ]; then + + logMessage Found /etc/rpm + + # + # If i386 then record this + # + if [ "$arch" = "i386" ]; then + echo "i386-fedora-linux-gnu" >> $prefix/etc/rpm/platform + fi +else + + logMessage Failed to find /etc/rpm + +fi + +# +# Log our finish +# +logMessage Script $0 finished + diff --git a/hooks/centos-5/50-setup-hostname b/hooks/centos-5/50-setup-hostname index 02daf27..0efa6cb 100755 --- a/hooks/centos-5/50-setup-hostname +++ b/hooks/centos-5/50-setup-hostname @@ -91,8 +91,7 @@ if [ -z "${dhcp}" ]; then logMessage Adding ${hostname} and ${name} to /etc/hosts on the host - echo "${ip1} ${hostname} ${name}" >> /etc/hosts - + echo "${ip1} ${hostname} ${name}" >> /etc/hosts # # If we've updated the /etc/hosts file on the host machine diff --git a/hooks/dapper/50-setup-hostname b/hooks/dapper/50-setup-hostname index 1829909..1c264d7 100755 --- a/hooks/dapper/50-setup-hostname +++ b/hooks/dapper/50-setup-hostname @@ -91,7 +91,7 @@ if [ -z "${dhcp}" ]; then logMessage Adding ${hostname} and ${name} to /etc/hosts on the host - echo "${ip1} ${hostname} ${name}" >> /etc/hosts + echo "${ip1} ${hostname} ${name}" >> /etc/hosts # diff --git a/hooks/debian/50-setup-hostname b/hooks/debian/50-setup-hostname index 32c5994..da55e6d 100755 --- a/hooks/debian/50-setup-hostname +++ b/hooks/debian/50-setup-hostname @@ -91,7 +91,7 @@ if [ -z "${dhcp}" ]; then logMessage Adding ${hostname} and ${name} to /etc/hosts on the host - echo "${ip1} ${hostname} ${name}" >> /etc/hosts + echo "${ip1} ${hostname} ${name}" >> /etc/hosts # # If we've updated the /etc/hosts file on the host machine diff --git a/hooks/edgy/50-setup-hostname b/hooks/edgy/50-setup-hostname index f39da9f..97558a4 100755 --- a/hooks/edgy/50-setup-hostname +++ b/hooks/edgy/50-setup-hostname @@ -90,7 +90,8 @@ if [ -z "${dhcp}" ]; then logMessage Adding ${hostname} and ${name} to /etc/hosts on the host - echo "${ip1} ${hostname} ${name}" >> /etc/hosts + echo "${ip1} ${hostname} ${name}" >> /etc/hosts + # # If we've updated the /etc/hosts file on the host machine # and there is an installation of dnsmasq installed then diff --git a/hooks/fedora-core-6/15-setup-arch b/hooks/fedora-core-6/15-setup-arch new file mode 100644 index 0000000..569d572 --- /dev/null +++ b/hooks/fedora-core-6/15-setup-arch @@ -0,0 +1,44 @@ +#!/bin/sh + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Record arch, if present. +# +if [ -d $prefix/etc/rpm ]; then + + logMessage Found /etc/rpm + + # + # If i386 then record this + # + if [ "$arch" = "i386" ]; then + echo "i386-fedora-linux-gnu" >> $prefix/etc/rpm/platform + fi +else + + logMessage Failed to find /etc/rpm + +fi + +# +# Log our finish +# +logMessage Script $0 finished + diff --git a/hooks/fedora-core-6/50-setup-hostname b/hooks/fedora-core-6/50-setup-hostname index a445229..ed302b9 100755 --- a/hooks/fedora-core-6/50-setup-hostname +++ b/hooks/fedora-core-6/50-setup-hostname @@ -91,7 +91,8 @@ if [ -z "${dhcp}" ]; then logMessage Adding ${hostname} and ${name} to /etc/hosts on the host - echo "${ip1} ${hostname} ${name}" >> /etc/hosts + echo "${ip1} ${hostname} ${name}" >> /etc/hosts + # # If we've updated the /etc/hosts file on the host machine diff --git a/hooks/fedora-core-6/90-make-fstab b/hooks/fedora-core-6/90-make-fstab index dbb00a8..c6d813b 100755 --- a/hooks/fedora-core-6/90-make-fstab +++ b/hooks/fedora-core-6/90-make-fstab @@ -64,7 +64,7 @@ cat < ${prefix}/etc/fstab # # proc /proc proc defaults 0 0 -devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=620 0 0 +devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=620 0 0 E_O_FSTAB for part in `seq 1 ${NUMPARTITIONS}`; do eval "PARTITION=\"\${PARTITION${part}}\"" diff --git a/hooks/gentoo/50-setup-hostname b/hooks/gentoo/50-setup-hostname index 3c48422..dbc633b 100755 --- a/hooks/gentoo/50-setup-hostname +++ b/hooks/gentoo/50-setup-hostname @@ -98,7 +98,7 @@ if [ -z "${dhcp}" ]; then logMessage Adding ${hostname} and ${name} to /etc/hosts on the host - echo "${ip1} ${hostname} ${name}" >> /etc/hosts + echo "${ip1} ${hostname} ${name}" >> /etc/hosts # # If we've updated the /etc/hosts file on the host machine diff --git a/t/modules.sh b/t/modules.sh index b53c9e6..a46337d 100755 --- a/t/modules.sh +++ b/t/modules.sh @@ -25,7 +25,7 @@ use Test::More qw( no_plan ); EOF -for i in `rgrep '^use ' .. | grep -v Expect | grep -v Xen:: | grep -v Moose | awk '{print $2}' | tr -d \;\(\) | sort | uniq`; \ +for i in `rgrep '^use ' .. | grep -v Expect | grep -v POSIX | grep -v Xen:: | grep -v Moose | awk '{print $2}' | tr -d \;\(\) | sort | uniq`; \ do \ echo "BEGIN{ use_ok( '$i' ); }"; \ echo "require_ok( '$i' );" ; \ diff --git a/t/modules.t b/t/modules.t index e9d9791..ed5ef3a 100755 --- a/t/modules.t +++ b/t/modules.t @@ -58,10 +58,6 @@ BEGIN{ use_ok( 'Pod::Usage' ); } require_ok( 'Pod::Usage' ); -BEGIN{ use_ok( 'POSIX' ); } -require_ok( 'POSIX' ); - - BEGIN{ use_ok( 'strict' ); } require_ok( 'strict' ); diff --git a/t/quoted-strings.t b/t/quoted-strings.t new file mode 100644 index 0000000..b137497 --- /dev/null +++ b/t/quoted-strings.t @@ -0,0 +1,78 @@ +#!/usr/bin/perl -w +# +# Test that every bash script using variables uses " not '. +# +# Steve +# -- +# + + +use strict; +use File::Find; +use Test::More qw( no_plan ); + + +# +# Find all the files beneath the current directory, +# and call 'checkFile' with the name. +# +my $dir = undef; +$dir = "../hooks" if ( -d "../hooks" ); +$dir = "./hooks" if ( -d "./hooks" ); +ok( defined( $dir ), "Found hook directory" ); +find( { wanted => \&checkFile, no_chdir => 1 }, $dir ); + + + +# +# Check a file; if it is a shell script. +# +sub checkFile +{ + # The file. + my $file = $File::Find::name; + + # We don't care about directories + return if ( ! -f $file ); + + # Finally mercurial files are fine. + return if ( $file =~ /\.hg\// ); + + # See if it is a shell script. + my $isShell = 0; + + # Read the file. + open( INPUT, "<", $file ); + foreach my $line ( ) + { + if ( ( $line =~ /\/bin\/sh/ ) || + ( $line =~ /\/bin\/bash/ ) ) + { + $isShell = 1; + } + } + close( INPUT ); + + # + # Return if it wasn't a perl file. + # + return if ( ! $isShell ); + + # + # Now read the file. + # + open( FILE, "<", $file ) or die "Failed to open file: $file - $!"; + ok( *FILE, "Opened file: $file" ); + foreach my $line ( ) + { + chomp( $line ); + + next if (!length( $line ) ); + next if ( $line =~ /grep|sed|echo|awk|find|policy-rc.d|chroot|logMessage/ ); + if ( $line =~ /\$/ ) + { + ok( $line !~ /\'/, "Non-masked line '$line'" ); + } + } + close( FILE ); +}