From 5c899053cdd542302d9bb56b6747e231b68a4bc9 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sun, 11 Jan 2009 23:23:59 +0000 Subject: [PATCH] tidy --- Makefile | 2 +- bin/xen-create-image | 891 +++++++++++++++++++-------------------- bin/xen-create-nfs | 68 +-- bin/xen-delete-image | 53 ++- bin/xen-list-images | 12 +- bin/xen-resize-guest | 67 +-- bin/xen-update-image | 57 ++- bin/xt-create-xen-config | 116 +++-- bin/xt-customize-image | 27 +- bin/xt-install-image | 185 ++++---- 10 files changed, 732 insertions(+), 746 deletions(-) diff --git a/Makefile b/Makefile index 4bde579..38edac9 100644 --- a/Makefile +++ b/Makefile @@ -196,7 +196,7 @@ install: fixup-perms install-bin install-etc install-hooks install-libraries ins # Build our manpages via the `pod2man` command. # manpages: - mkdir man + -mkdir man cd bin; for i in *-*; do pod2man --release=${VERSION} --official --section=8 $$i ../man/$$i.8; done for i in man/*.8; do gzip --force -9 $$i; done diff --git a/bin/xen-create-image b/bin/xen-create-image index 469168e..d7c2d1e 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -688,9 +688,9 @@ parseCommandLineArguments(); # # If we received an additional configuration file then read it. # -if ( $CONFIG{'config'} ) +if ( $CONFIG{ 'config' } ) { - my $path = $CONFIG{'config'}; + my $path = $CONFIG{ 'config' }; # If not fully-qualified then read from /etc/xen-tools. if ( $path !~ /^[\/]/ ) @@ -715,12 +715,12 @@ if ( $CONFIG{'config'} ) # # Process --debug # -if ( $CONFIG{'debug'} ) +if ( $CONFIG{ 'debug' } ) { foreach my $key ( sort keys %CONFIG ) { print $key; - print " : " . $CONFIG{$key} if ( $CONFIG{$key} ); + print " : " . $CONFIG{ $key } if ( $CONFIG{ $key } ); print "\n"; } exit 127; @@ -771,9 +771,9 @@ checkBinariesPresent(); if ( !$#PARTITIONS ) { populatePartitionsData() - if ( ( $CONFIG{'dir'} ) - || ( $CONFIG{'evms'} ) - || ( $CONFIG{'lvm'} ) ); + if ( ( $CONFIG{ 'dir' } ) || + ( $CONFIG{ 'evms' } ) || + ( $CONFIG{ 'lvm' } ) ); } @@ -787,7 +787,7 @@ showSummary(); # # Create and format the images if we're using loopback filesystems. # -if ( $CONFIG{'dir'} ) +if ( $CONFIG{ 'dir' } ) { # @@ -801,7 +801,7 @@ if ( $CONFIG{'dir'} ) # createLoopbackImages(); } -elsif ( $CONFIG{'lvm'} ) +elsif ( $CONFIG{ 'lvm' } ) { # @@ -809,7 +809,7 @@ elsif ( $CONFIG{'lvm'} ) # createLVMBits(); } -elsif ( $CONFIG{'evms'} ) +elsif ( $CONFIG{ 'evms' } ) { # @@ -817,7 +817,7 @@ elsif ( $CONFIG{'evms'} ) # createEVMSBits(); } -elsif ( $CONFIG{'image-dev'} ) +elsif ( $CONFIG{ 'image-dev' } ) { # @@ -857,7 +857,7 @@ exportEnvironment(); # a binary name that is reasonably likely to exist under any # distribution of GNU/Linux. # -if ( $CONFIG{'install'} ) +if ( $CONFIG{ 'install' } ) { # @@ -878,7 +878,7 @@ if ( $CONFIG{'install'} ) # # Now customize the installation - setting up networking, etc. # - if ( $CONFIG{'hooks'} ) + if ( $CONFIG{ 'hooks' } ) { runCustomisationHooks(); } @@ -889,7 +889,7 @@ if ( $CONFIG{'install'} ) # # Run any specified role scripts. # -runRoleScripts( $CONFIG{'role'} ); +runRoleScripts( $CONFIG{ 'role' } ); # @@ -901,7 +901,7 @@ runXenConfigCreation(); # # Setup the password if the user wanted that. # -setupRootPassword() if ( $CONFIG{'passwd'} ); +setupRootPassword() if ( $CONFIG{ 'passwd' } ); # @@ -914,7 +914,7 @@ logprint("All done\n"); # If we're supposed to start the new instance do so - note here we # have to unmount the image first. # -if ( $CONFIG{'boot'} ) +if ( $CONFIG{ 'boot' } ) { # @@ -937,7 +937,8 @@ if ( $CONFIG{'boot'} ) if ( -d "/etc/xen/auto" ) { my $cfg = - $CONFIG{'output'} . "/" . $CONFIG{'hostname'} . $CONFIG{'extension'}; + $CONFIG{ 'output' } . "/" . $CONFIG{ 'hostname' } . + $CONFIG{ 'extension' }; if ( !-e $cfg ) { @@ -953,8 +954,8 @@ if ( $CONFIG{'boot'} ) # # Start the image # - $CONFIG{'pid'} = fork(); - if ( $CONFIG{'pid'} ) + $CONFIG{ 'pid' } = fork(); + if ( $CONFIG{ 'pid' } ) { # Parent. @@ -965,7 +966,8 @@ if ( $CONFIG{'boot'} ) # Config file. my $cfg = - $CONFIG{'output'} . "/" . $CONFIG{'hostname'} . $CONFIG{'extension'}; + $CONFIG{ 'output' } . "/" . $CONFIG{ 'hostname' } . + $CONFIG{ 'extension' }; # Child. system("$CONFIG{'xm'} create $cfg >/dev/null 2>/dev/null"); @@ -1015,7 +1017,7 @@ sub checkSystem # my $test = "use Text::Template"; eval($test); - if ( ($@) && ( !$CONFIG{'force'} ) ) + if ( ($@) && ( !$CONFIG{ 'force' } ) ) { print <) { next if ( !$_ || !length($_) ); @@ -1095,19 +1097,19 @@ sub testXenConfig # vif if ( $_ =~ /^\(vif-script ([^)]+)/ ) { - $cfg{'vif-script'} = $1; + $cfg{ 'vif-script' } = $1; } # network if ( $_ =~ /^\(network-script ([^)]+)/ ) { - $cfg{'network-script'} = $1; + $cfg{ 'network-script' } = $1; } } close(CONFIG); - if ( !defined( $cfg{'network-script'} ) - || !defined( $cfg{'vif-script'} ) ) + if ( !defined( $cfg{ 'network-script' } ) || + !defined( $cfg{ 'vif-script' } ) ) { print < $CONFIG{'partitions'} ); + tie %partitions, 'Config::IniFiles', ( -file => $CONFIG{ 'partitions' } ); @PARTITIONS = (); @@ -2061,70 +2071,66 @@ EOF exit 127; } - if ( !( $details->{'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" + "The size $details->{'size'} of partition $name contains is not recognized.\n" ); exit 127; } - if ( $details->{'type'} eq 'swap' ) + 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" ); + "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" ); + "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" ); + "The mount options $details->{'options'} of partition $name are invalid.\n" + ); exit 127; } - if ( !$details->{'options'} ) + if ( !$details->{ 'options' } ) { - $details->{'options'} = 'defaults'; + $details->{ 'options' } = 'defaults'; } - if ( $details->{'mountpoint'} eq '/' ) + if ( $details->{ 'mountpoint' } eq '/' ) { $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' } } ); } } @@ -2140,7 +2146,9 @@ EOF # This makes it easy to mount parent folders first # (e.g. /var before /var/tmp) # - @PARTITIONS = sort { length $a->{'mountpoint'} <=> length $b->{'mountpoint'} } @PARTITIONS; + @PARTITIONS = + sort {length $a->{ 'mountpoint' } <=> length $b->{ 'mountpoint' }} + @PARTITIONS; } @@ -2161,21 +2169,18 @@ 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 @@ -2188,23 +2193,20 @@ sub populatePartitionsData # XFS has different default options. # $options = "errors=remount-ro"; - $options = "defaults" if ( $CONFIG{'fs'} eq "xfs" ); + $options = "defaults" if ( $CONFIG{ 'fs' } eq "xfs" ); } # # [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 + } ); } @@ -2221,19 +2223,16 @@ sub populatePartitionsData sub exportPartitionsToConfig { - $CONFIG{'NUMPARTITIONS'} = $#PARTITIONS + 1; + $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' }; } } @@ -2258,11 +2257,11 @@ sub showSummary logprint("Hostname : $CONFIG{'hostname'}\n"); logprint("Distribution : $CONFIG{'dist'}\n"); - if ( defined $CONFIG{'image-dev'} ) + if ( defined $CONFIG{ 'image-dev' } ) { logprint("Root Device : $CONFIG{'image-dev'}\n"); } - if ( defined $CONFIG{'swap-dev'} ) + if ( defined $CONFIG{ 'swap-dev' } ) { logprint("Swap Device : $CONFIG{'swap-dev'}\n"); } @@ -2275,11 +2274,11 @@ sub showSummary { next if ( !$partition ); $info = sprintf( '%-15s %-5s (%s)', - ( $partition->{'type'} ne 'swap' ) - ? $partition->{'mountpoint'} - : 'swap', - $partition->{'size'}, - $partition->{'type'} ); + ( $partition->{ 'type' } ne 'swap' ) ? + $partition->{ 'mountpoint' } : + 'swap', + $partition->{ 'size' }, + $partition->{ 'type' } ); if ( $partcount++ ) { @@ -2294,17 +2293,17 @@ sub showSummary logprint("Image type : $CONFIG{'image'}\n"); logprint("Memory size : $CONFIG{'memory'}\n"); - if ( defined( $CONFIG{'kernel'} ) && length( $CONFIG{'kernel'} ) ) + if ( defined( $CONFIG{ 'kernel' } ) && length( $CONFIG{ 'kernel' } ) ) { logprint("Kernel path : $CONFIG{'kernel'}\n"); } - if ( defined( $CONFIG{'modules'} ) && length( $CONFIG{'modules'} ) ) + if ( defined( $CONFIG{ 'modules' } ) && length( $CONFIG{ 'modules' } ) ) { logprint("Module path : $CONFIG{'modules'}\n"); } - if ( defined( $CONFIG{'initrd'} ) && length( $CONFIG{'initrd'} ) ) + if ( defined( $CONFIG{ 'initrd' } ) && length( $CONFIG{ 'initrd' } ) ) { logprint("Initrd path : $CONFIG{'initrd'}\n"); } @@ -2317,8 +2316,8 @@ sub showSummary # # Note we only allow the first IP address to have a MAC address specified. # - my $ips = $CONFIG{'ip'}; - my $mac = $CONFIG{'mac'}; + my $ips = $CONFIG{ 'ip' }; + my $mac = $CONFIG{ 'mac' }; my $count = 1; if ( defined $ips ) @@ -2347,8 +2346,8 @@ sub showSummary # It works. Even if it's nasty, (or if it is a clever hack!) # $ips = undef; - push( @$ips, $CONFIG{'ip'} ); - $CONFIG{'ip'} = $ips; + push( @$ips, $CONFIG{ 'ip' } ); + $CONFIG{ 'ip' } = $ips; } } @@ -2377,13 +2376,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) ) { - $CONFIG{'verbose'} && logprint("Claimed $i\n"); + $CONFIG{ 'verbose' } && logprint("Claimed $i\n"); } else { @@ -2417,9 +2416,9 @@ EOF # mac address setting still works even for DHCP, but in that # case only the first one works. # - if ( $CONFIG{'dhcp'} ) + if ( $CONFIG{ 'dhcp' } ) { - if ( defined( $CONFIG{'mac'} ) ) + if ( defined( $CONFIG{ 'mac' } ) ) { logprint("IP Address : DHCP [MAC: $CONFIG{'mac'}]\n"); } @@ -2429,10 +2428,11 @@ EOF } } - $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"; } @@ -2487,7 +2487,7 @@ sub createLoopbackImages # # Make sure we have the relevant output directory. # - my $output = $CONFIG{'dir'} . "/domains/" . $CONFIG{'hostname'}; + my $output = $CONFIG{ 'dir' } . "/domains/" . $CONFIG{ 'hostname' }; if ( !-d $output ) { @@ -2495,7 +2495,7 @@ sub createLoopbackImages # # Catch errors with eval. # - eval { mkpath( $output, 0, 0755 ); }; + eval {mkpath( $output, 0, 0755 );}; if ($@) { die "Cannot create directory tree $output - $@"; @@ -2506,21 +2506,20 @@ sub createLoopbackImages # # Only proceed overwritting if we have --force specified. # - if ( !$CONFIG{'force'} ) + if ( !$CONFIG{ 'force' } ) { foreach my $partition (@PARTITIONS) { my $disk = - $CONFIG{'dir'} - . '/domains/' - . $CONFIG{'hostname'} . '/' - . $partition->{'name'} . '.img'; + $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" ); + "Specify '--force' to overwrite, or remove the following file\n" + ); logprint( $disk . "\n" ); exit 127; } @@ -2531,21 +2530,19 @@ sub createLoopbackImages foreach my $partition (@PARTITIONS) { my $disk = - $CONFIG{'dir'} - . '/domains/' - . $CONFIG{'hostname'} . '/' - . $partition->{'name'} . '.img'; + $CONFIG{ 'dir' } . '/domains/' . $CONFIG{ 'hostname' } . '/' . + $partition->{ 'name' } . '.img'; # # Save the image path to the partitions array # - $partition->{'imagetype'} = 'file:'; - $partition->{'image'} = $disk; + $partition->{ 'imagetype' } = 'file:'; + $partition->{ 'image' } = $disk; # # Modify the size to something reasonable # - my $size = $partition->{'size'}; + my $size = $partition->{ 'size' }; # # Convert Gb -> Mb for the partition image size. @@ -2565,14 +2562,14 @@ sub createLoopbackImages # logprint("\nCreating partition image: $disk\n"); my $image_cmd; - if ( $CONFIG{'image'} eq "sparse" ) + 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"; } @@ -2589,13 +2586,13 @@ sub createLoopbackImages # # Finally create the filesystem / swap # - if ( $partition->{'type'} eq 'swap' ) + if ( $partition->{ 'type' } eq 'swap' ) { createSwap($disk); } else { - createFilesystem( $disk, $partition->{'type'} ); + createFilesystem( $disk, $partition->{ 'type' } ); } } } @@ -2621,56 +2618,51 @@ sub usePhysicalDevice @PARTITIONS = (); - if ( defined $CONFIG{'swap-dev'} ) + if ( defined $CONFIG{ 'swap-dev' } ) { - $swap_img = $CONFIG{'swap-dev'}; + $swap_img = $CONFIG{ 'swap-dev' }; if ( !-e $swap_img ) { logprint( -"The physical device or logical volume for swap-dev $swap_img doesn't exist. Aborting.\n" + "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" ); + "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'; - if ( $CONFIG{'fs'} eq 'xfs' ) + if ( $CONFIG{ 'fs' } eq 'xfs' ) { $options = 'defaults'; } - if ( defined $CONFIG{'image-dev'} ) + if ( defined $CONFIG{ 'image-dev' } ) { - $phys_img = $CONFIG{'image-dev'}; + $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 { @@ -2678,8 +2670,8 @@ sub usePhysicalDevice exit 127; } - createFilesystem( $phys_img, $CONFIG{'fs'} ); - createSwap($swap_img) unless ( $CONFIG{'noswap'} ); + createFilesystem( $phys_img, $CONFIG{ 'fs' } ); + createSwap($swap_img) unless ( $CONFIG{ 'noswap' } ); } @@ -2702,14 +2694,14 @@ sub createLVMBits # 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'} ) + if ( $CONFIG{ 'force' } ) { logprint( "Removing $lvm_disk - since we're forcing the install\n"); @@ -2726,14 +2718,14 @@ sub createLVMBits foreach my $partition (@PARTITIONS) { - my $disk = $CONFIG{'hostname'} . '-' . $partition->{'name'}; + my $disk = $CONFIG{ 'hostname' } . '-' . $partition->{ 'name' }; my $lvm_disk = "/dev/$CONFIG{'lvm'}/$disk"; # # Save the image path to the partitions array # - $partition->{'imagetype'} = 'phy:'; - $partition->{'image'} = $lvm_disk; + $partition->{ 'imagetype' } = 'phy:'; + $partition->{ 'image' } = $lvm_disk; # # The commands to create the volume. @@ -2761,13 +2753,13 @@ sub createLVMBits # # Finally create the filesystem / swap # - if ( $partition->{'type'} eq 'swap' ) + if ( $partition->{ 'type' } eq 'swap' ) { createSwap($lvm_disk); } else { - createFilesystem( $lvm_disk, $partition->{'type'} ); + createFilesystem( $lvm_disk, $partition->{ 'type' } ); } } @@ -2797,23 +2789,25 @@ sub createEVMSBits foreach my $partition (@PARTITIONS) { -# Check whether the EVMS volume already exists, abort unless '--force' is specified. + # 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'} ) + if ( $CONFIG{ 'force' } ) { logprint( -"Removing $evms_volume_disk - since we're forcing the install\n" ); + "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" ); + "The EVMS volume $evms_volume_disk already exists. Aborting.\n" + ); logprint("Specify '--force' to delete and recreate\n"); exit 127; } @@ -2831,16 +2825,18 @@ sub createEVMSBits { # Delete if forcing - if ( $CONFIG{'force'} ) + if ( $CONFIG{ 'force' } ) { logprint( -"Removing $evms_object_disk - since we're forcing the install\n" ); + "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" ); + "The EVMS object $evms_object_disk already exists. Aborting.\n" + ); logprint("Specify '--force' to delete and recreate\n"); exit 127; } @@ -2849,19 +2845,19 @@ sub createEVMSBits foreach my $partition (@PARTITIONS) { - my $disk = $CONFIG{'hostname'} . '-' . $partition->{'name'}; + my $disk = $CONFIG{ 'hostname' } . '-' . $partition->{ 'name' }; my $evms_disk = "/dev/evms/$disk"; # # Save the image path to the partitions array # - $partition->{'imagetype'} = 'phy:'; - $partition->{'image'} = $evms_disk; + $partition->{ 'imagetype' } = 'phy:'; + $partition->{ 'image' } = $evms_disk; # # Modify the size to something reasonable # - my $size = $partition->{'size'}; + my $size = $partition->{ 'size' }; # # Convert Gb -> Mb for the partition image size. @@ -2882,7 +2878,7 @@ sub createEVMSBits # create the object # my $disk_cmd_object = -"echo allocate : $CONFIG{'evms'}/Freespace, size=$CONFIG{'size'}, name=$disk | evms"; + "echo allocate : $CONFIG{'evms'}/Freespace, size=$CONFIG{'size'}, name=$disk | evms"; # # these will be piped to evms, but gotta check it first @@ -2899,13 +2895,13 @@ sub createEVMSBits # # Initialise the partition with the relevant filesystem. # - if ( $partition->{'type'} eq 'swap' ) + if ( $partition->{ 'type' } eq 'swap' ) { createSwap($disk_cmd_volume); } else { - createFilesystem( $disk_cmd_volume, $partition->{'type'} ); + createFilesystem( $disk_cmd_volume, $partition->{ 'type' } ); } } @@ -2929,7 +2925,7 @@ sub createFilesystem # 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 @@ -2943,7 +2939,8 @@ sub createFilesystem if ( !defined( findBinary($binary) ) ) { logprint( -"The binary '$binary' required to create the filesystem $fs is missing\n" ); + "The binary '$binary' required to create the filesystem $fs is missing\n" + ); exit 127; } } @@ -3006,10 +3003,10 @@ sub mountImage foreach my $partition (@PARTITIONS) { - if ( $partition->{'type'} ne 'swap' ) + if ( $partition->{ 'type' } ne 'swap' ) { - my $image = $partition->{'image'}; - my $mountpoint = $MOUNT_POINT . $partition->{'mountpoint'}; + my $image = $partition->{ 'image' }; + my $mountpoint = $MOUNT_POINT . $partition->{ 'mountpoint' }; mkpath( $mountpoint, 0, 0755 ); @@ -3017,20 +3014,20 @@ 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 # - if ( $CONFIG{'lvm'} ) + if ( $CONFIG{ 'lvm' } ) { $mount_cmd = "mount $mount_type $image $mountpoint"; } - elsif ( $CONFIG{'evms'} ) + elsif ( $CONFIG{ 'evms' } ) { $mount_cmd = "mount $mount_type $image $mountpoint"; } - elsif ( $CONFIG{'image-dev'} ) + elsif ( $CONFIG{ 'image-dev' } ) { $mount_cmd = "mount $mount_type $image $mountpoint"; } @@ -3061,10 +3058,10 @@ sub installSystem # # We might have a per-distro mirror. - my $distMirror = "mirror_" . $CONFIG{'dist'}; - if ( $CONFIG{$distMirror} && length( $CONFIG{$distMirror} ) ) + my $distMirror = "mirror_" . $CONFIG{ 'dist' }; + if ( $CONFIG{ $distMirror } && length( $CONFIG{ $distMirror } ) ) { - $CONFIG{'mirror'} = $CONFIG{$distMirror}; + $CONFIG{ 'mirror' } = $CONFIG{ $distMirror }; } # @@ -3072,34 +3069,34 @@ sub installSystem # Basic command # my $cmd = -"xt-install-image --hostname=$CONFIG{'hostname'} --location=$MOUNT_POINT --dist=$CONFIG{'dist'} --install-method=$CONFIG{'install-method'}"; + "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'} ) ); + if ( defined( $CONFIG{ 'install-source' } ) ); # # Do we have a per-image configuration file? # - $cmd .= " --config=$CONFIG{'config'}" if ( defined( $CONFIG{'config'} ) ); + $cmd .= " --config=$CONFIG{'config'}" if ( defined( $CONFIG{ 'config' } ) ); # # Add on the mirror, if defined # - $cmd .= " --mirror=$CONFIG{'mirror'}" if ( defined( $CONFIG{'mirror'} ) ); + $cmd .= " --mirror=$CONFIG{'mirror'}" if ( defined( $CONFIG{ 'mirror' } ) ); # # Add on the current cache setting # - $cmd .= " --cache=$CONFIG{'cache'}" if length( $CONFIG{'cache'} ); + $cmd .= " --cache=$CONFIG{'cache'}" if length( $CONFIG{ 'cache' } ); # # Propogate --verbose # - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { $cmd .= " --verbose"; } @@ -3107,7 +3104,7 @@ sub installSystem # # Propogate --arche # - if ( $CONFIG{'arch'} ) + if ( $CONFIG{ 'arch' } ) { $cmd .= " --arch=$CONFIG{'arch'}"; } @@ -3121,9 +3118,9 @@ sub installSystem # # 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" ) ) + 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"); } @@ -3157,10 +3154,10 @@ sub exportEnvironment # # Per-distribution mirror? # - my $distMirror = "mirror_" . $CONFIG{'dist'}; - if ( $CONFIG{$distMirror} && length( $CONFIG{$distMirror} ) ) + my $distMirror = "mirror_" . $CONFIG{ 'dist' }; + if ( $CONFIG{ $distMirror } && length( $CONFIG{ $distMirror } ) ) { - $CONFIG{'mirror'} = $CONFIG{$distMirror}; + $CONFIG{ 'mirror' } = $CONFIG{ $distMirror }; } # @@ -3170,9 +3167,9 @@ sub exportEnvironment foreach my $key ( keys %CONFIG ) { - if ( defined( $CONFIG{$key} ) ) + if ( defined( $CONFIG{ $key } ) ) { - $ENV{$key} = $CONFIG{$key}; + $ENV{ $key } = $CONFIG{ $key }; } } } @@ -3207,33 +3204,33 @@ sub runCustomisationHooks # these are handled specially since we use arrays. # # Remove the value we set above. - delete $ENV{'ip'}; + delete $ENV{ 'ip' }; # # Setup a seperate ip$count value for each IP address. # - my $ips = $CONFIG{'ip'}; + my $ips = $CONFIG{ 'ip' }; my $count = 1; foreach my $i (@$ips) { - $ENV{'ip' . $count} = $i; + $ENV{ 'ip' . $count } = $i; $count += 1; } - $ENV{'ip_count'} = ( $count - 1 ); + $ENV{ 'ip_count' } = ( $count - 1 ); # # Now show the environment the children get # - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { logprint("Customization Script Environment:\n"); logprint("---------------------------------\n"); foreach my $key ( sort keys %ENV ) { - logprint( "\t'" . $key . "' = '" . $ENV{$key} . "'\n" ); + logprint( "\t'" . $key . "' = '" . $ENV{ $key } . "'\n" ); } } @@ -3243,7 +3240,7 @@ sub runCustomisationHooks # my $customize = "xt-customize-image --dist=$CONFIG{'dist'} --location=$MOUNT_POINT"; - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { $customize .= " --verbose"; } @@ -3272,13 +3269,13 @@ 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); @@ -3308,8 +3305,8 @@ 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); @@ -3400,14 +3397,14 @@ sub runRoleScript { my ($role) = (@_); - my $roleDir = $CONFIG{'roledir'}; + my $roleDir = $CONFIG{ 'roledir' }; # # Role-script arguments are optional. If present prepare to # append. # my $args = ''; - $args = " " . $CONFIG{'role-args'} if ( $CONFIG{'role-args'} ); + $args = " " . $CONFIG{ 'role-args' } if ( $CONFIG{ 'role-args' } ); # # The complete path to the role script @@ -3463,9 +3460,9 @@ sub runXenConfigCreation # # Configuration file we'll create # - my $dir = $CONFIG{'output'}; - my $ext = $CONFIG{'extension'}; - my $file = $dir . "/" . $CONFIG{'hostname'} . $ext; + my $dir = $CONFIG{ 'output' }; + my $ext = $CONFIG{ 'extension' }; + my $file = $dir . "/" . $CONFIG{ 'hostname' } . $ext; # @@ -3473,7 +3470,7 @@ sub runXenConfigCreation # if ( -e $file ) { - unless ( $CONFIG{'force'} ) + unless ( $CONFIG{ 'force' } ) { logprint("The Xen configuration file $file exists\n"); logprint("Specify --force to force overwriting it.\n"); @@ -3491,16 +3488,16 @@ sub runXenConfigCreation # # Add the template if specified # - if ( ( defined( $CONFIG{'template'} ) ) - && ( -e $CONFIG{'template'} ) ) + if ( ( defined( $CONFIG{ 'template' } ) ) && + ( -e $CONFIG{ 'template' } ) ) { - $command .= " --template=" . $CONFIG{'template'}; + $command .= " --template=" . $CONFIG{ 'template' }; } # # Add the admins, if any. # - if ( defined( $CONFIG{'admins'} ) ) + if ( defined( $CONFIG{ 'admins' } ) ) { $command .= " --admins=$CONFIG{'admins'}"; } @@ -3553,10 +3550,10 @@ sub logprint # # Log. # - if ( $CONFIG{'hostname'} ) + if ( $CONFIG{ 'hostname' } ) { - open( LOGFILE, ">>", "/var/log/xen-tools/$CONFIG{'hostname'}.log" ) - or return; + open( LOGFILE, ">>", "/var/log/xen-tools/$CONFIG{'hostname'}.log" ) or + return; print LOGFILE $text; close(LOGFILE); } @@ -3581,7 +3578,7 @@ sub findBinary # strip any path which might be present. $bin = $2 if ( $bin =~ /(.*)[\/\\](.*)/ ); - foreach my $entry ( split( /:/, $ENV{'PATH'} ) ) + foreach my $entry ( split( /:/, $ENV{ 'PATH' } ) ) { # guess of location. @@ -3615,12 +3612,12 @@ sub runCommand # # 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. # - $CONFIG{'verbose'} && print "Executing : $cmd\n"; + $CONFIG{ 'verbose' } && print "Executing : $cmd\n"; # # Copy stderr to stdout, so we can see it, and make sure we log it. @@ -3633,7 +3630,7 @@ sub runCommand my $output = `$cmd`; - $CONFIG{'verbose'} && print "Finished : $cmd\n"; + $CONFIG{ 'verbose' } && print "Finished : $cmd\n"; if ( $? != 0 ) { @@ -3668,8 +3665,8 @@ sub unMountImage # my @points; - open( MOUNTED, "<", "/proc/mounts" ) - or die "Failed to open mount list"; + open( MOUNTED, "<", "/proc/mounts" ) or + die "Failed to open mount list"; foreach my $line () { @@ -3696,7 +3693,7 @@ sub unMountImage foreach my $path (@points) { - $CONFIG{'verbose'} && print "Unmounting : $path\n"; + $CONFIG{ 'verbose' } && print "Unmounting : $path\n"; runCommand("umount $path"); } @@ -3731,9 +3728,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"; @@ -3743,14 +3740,14 @@ 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'}"); } diff --git a/bin/xen-create-nfs b/bin/xen-create-nfs index 3c859d1..7be1435 100755 --- a/bin/xen-create-nfs +++ b/bin/xen-create-nfs @@ -124,7 +124,7 @@ my %CONFIG; # # Default options # -$CONFIG{'template'} = '/etc/xen-tools/xm-nfs.tmpl'; +$CONFIG{ 'template' } = '/etc/xen-tools/xm-nfs.tmpl'; # @@ -134,7 +134,7 @@ my $RELEASE = '4.1'; # store version number away. -$CONFIG{'xen_tools_version'} = $RELEASE; +$CONFIG{ 'xen_tools_version' } = $RELEASE; # @@ -161,13 +161,13 @@ testArguments(); if ( -e "/etc/xen/$CONFIG{'hostname'}.cfg" ) { die "Configuration file for $CONFIG{'hostname'} already exists" - unless ( $CONFIG{'force'} ); + unless ( $CONFIG{ 'force' } ); } # # If we've been given any administrators then set them up. # -if ( $CONFIG{'admins'} ) +if ( $CONFIG{ 'admins' } ) { setupAdminUsers(); } @@ -258,7 +258,7 @@ sub readConfigurationFile } # Store value. - $CONFIG{$key} = $val; + $CONFIG{ $key } = $val; } } @@ -288,30 +288,30 @@ 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'}, + "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_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'}, + "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'}, + "verbose", \$CONFIG{ 'verbose' }, "version", \$VERSION ); @@ -349,33 +349,33 @@ sub testArguments # # Hostname is mandatory # - die "No hostname" unless ( $CONFIG{'hostname'} ); + die "No hostname" unless ( $CONFIG{ 'hostname' } ); my @network = qw/ ip gateway netmask /; # # If DHCP then all the other options aren't needed # - if ( $CONFIG{'dhcp'} ) + if ( $CONFIG{ 'dhcp' } ) { foreach my $f (@network) { - delete( $CONFIG{$f} ); + delete( $CONFIG{ $f } ); } } else { 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. @@ -420,7 +420,7 @@ sub setupAdminUsers # For each user make sure they exist, and setup the # login shell for them. # - foreach my $user ( split( /,/, $ENV{'admins'} ) ) + foreach my $user ( split( /,/, $ENV{ 'admins' } ) ) { # Strip leading and trailing whitespace. @@ -435,22 +435,22 @@ sub setupAdminUsers { # Change shell. - $CONFIG{'verbose'} && print "Changing shell for $user: $shell\n"; + $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"; + $CONFIG{ 'verbose' } && print "Adding new user: $user\n"; system( "useradd", "-s", $shell, $user ); } # # Add the entry to /etc/sudoers. # - open( SUDOERS, ">>", "/etc/sudoers" ) - or warn "Failed to add user to sudoers file : $user - $!"; + 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); @@ -470,13 +470,13 @@ sub setupAdminUsers sub createNewConfigurationFile { die "Template file missing: $CONFIG{'template'}" - unless ( -e $CONFIG{'template'} ); + unless ( -e $CONFIG{ 'template' } ); # # Load the template. # my $template = new Text::Template( TYPE => 'FILE', - SOURCE => $CONFIG{'template'} ); + SOURCE => $CONFIG{ 'template' } ); my $result = $template->fill_in( HASH => \%CONFIG ); diff --git a/bin/xen-delete-image b/bin/xen-delete-image index 8edeb51..8ce0c1e 100755 --- a/bin/xen-delete-image +++ b/bin/xen-delete-image @@ -198,7 +198,7 @@ checkArguments(); # # Abort if non-root user. # -if ( ( !$CONFIG{'test'} ) && ( $EFFECTIVE_USER_ID != 0 ) ) +if ( ( !$CONFIG{ 'test' } ) && ( $EFFECTIVE_USER_ID != 0 ) ) { print < 2 ) if $MANUAL; @@ -390,10 +389,10 @@ sub checkArguments # # When testing we only care about loopback images, not disk images. # - if ( $CONFIG{'test'} ) + if ( $CONFIG{ 'test' } ) { - $CONFIG{'lvm'} = undef; - $CONFIG{'evms'} = undef; + $CONFIG{ 'lvm' } = undef; + $CONFIG{ 'evms' } = undef; } # @@ -402,7 +401,7 @@ sub checkArguments my $count = 0; foreach my $type (qw/dir lvm evms/) { - $count += 1 if defined( $CONFIG{$type} ); + $count += 1 if defined( $CONFIG{ $type } ); } # @@ -435,8 +434,8 @@ sub xenRunning my $running = 0; - open( CMD, "xm list $hostname 2>/dev/null |" ) - or die "Failed to run 'xm list $hostname'"; + open( CMD, "xm list $hostname 2>/dev/null |" ) or + die "Failed to run 'xm list $hostname'"; while () { my $line = $_; @@ -499,9 +498,9 @@ sub deleteXenImage } - if ( defined( $CONFIG{'dir'} ) ) + if ( defined( $CONFIG{ 'dir' } ) ) { - my $prefix = $CONFIG{'dir'} . "/domains/"; + my $prefix = $CONFIG{ 'dir' } . "/domains/"; # # Now remove the directory. @@ -512,7 +511,7 @@ sub deleteXenImage rmdir( $prefix . $hostname ); } } - elsif ( defined( $CONFIG{'lvm'} ) ) + elsif ( defined( $CONFIG{ 'lvm' } ) ) { # @@ -535,7 +534,7 @@ sub deleteXenImage } } - elsif ( defined( $CONFIG{'evms'} ) ) + elsif ( defined( $CONFIG{ 'evms' } ) ) { # @@ -589,12 +588,12 @@ sub runCommand # # Header. # - $CONFIG{'verbose'} && print "Executing : $cmd\n"; + $CONFIG{ 'verbose' } && print "Executing : $cmd\n"; # # Hide output unless running with --debug. # - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { # @@ -624,10 +623,10 @@ sub runCommand # # All done. # - $CONFIG{'verbose'} && print "Output\n"; - $CONFIG{'verbose'} && print "======\n"; - $CONFIG{'verbose'} && print $output . "\n"; - $CONFIG{'verbose'} && print "Finished : $cmd\n"; + $CONFIG{ 'verbose' } && print "Output\n"; + $CONFIG{ 'verbose' } && print "======\n"; + $CONFIG{ 'verbose' } && print $output . "\n"; + $CONFIG{ 'verbose' } && print "Finished : $cmd\n"; return ($output); } diff --git a/bin/xen-list-images b/bin/xen-list-images index 1f3d765..e688fb9 100755 --- a/bin/xen-list-images +++ b/bin/xen-list-images @@ -97,7 +97,7 @@ my %CONFIG; # # Default prefix # -$CONFIG{'prefix'} = "/etc/xen"; +$CONFIG{ 'prefix' } = "/etc/xen"; # # Release number. @@ -131,7 +131,7 @@ my @instances = findXenInstances(); my $count = 0; foreach my $instance (@instances) { - if ($count) { print "\n"; } + if ($count) {print "\n";} displayInstance($instance); $count += 1; @@ -214,7 +214,7 @@ sub readConfigurationFile } # Store value. - $CONFIG{$key} = $val; + $CONFIG{ $key } = $val; } } close(FILE); @@ -238,8 +238,8 @@ sub parseCommandLineArguments # 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; @@ -273,7 +273,7 @@ sub findXenInstances { my @found; - foreach my $file ( sort( glob( $CONFIG{'prefix'} . "/*.cfg" ) ) ) + foreach my $file ( sort( glob( $CONFIG{ 'prefix' } . "/*.cfg" ) ) ) { push @found, $file if ( -e $file ); } diff --git a/bin/xen-resize-guest b/bin/xen-resize-guest index 5237263..a788625 100755 --- a/bin/xen-resize-guest +++ b/bin/xen-resize-guest @@ -143,13 +143,14 @@ testArguments(); # my $path = undef; -if ( $CONFIG{'dir'} ) +if ( $CONFIG{ 'dir' } ) { # # Make sure we can find the disk # - $path = $CONFIG{'dir'} . "/domains/" . $CONFIG{'hostname'} . "/disk.img"; + $path = + $CONFIG{ 'dir' } . "/domains/" . $CONFIG{ 'hostname' } . "/disk.img"; if ( !-e $path ) { print < Mb; # - if ( $CONFIG{'add'} =~ /^([0-9.]+)Gb*$/i ) + if ( $CONFIG{ 'add' } =~ /^([0-9.]+)Gb*$/i ) { - $CONFIG{'add'} = $1 * 1024; + $CONFIG{ 'add' } = $1 * 1024; } - if ( $CONFIG{'add'} =~ /^([0-9.]+)Mb*$/i ) + if ( $CONFIG{ 'add' } =~ /^([0-9.]+)Mb*$/i ) { - $CONFIG{'add'} = $1; + $CONFIG{ 'add' } = $1; } } @@ -534,8 +537,8 @@ sub xenRunning my $running = 0; - open( CMD, "xm list $hostname 2>/dev/null |" ) - or die "Failed to run 'xm list $hostname'"; + open( CMD, "xm list $hostname 2>/dev/null |" ) or + die "Failed to run 'xm list $hostname'"; while () { my $line = $_; diff --git a/bin/xen-update-image b/bin/xen-update-image index ecdcfe2..708d4b8 100755 --- a/bin/xen-update-image +++ b/bin/xen-update-image @@ -210,11 +210,11 @@ sub updateXenImage # If we're dealing with loopback images find the main one, # and mount it. # - if ( $CONFIG{'dir'} ) + if ( $CONFIG{ 'dir' } ) { # The loopback image. - $img = $CONFIG{'dir'} . "/domains/" . $name . "/disk.img"; + $img = $CONFIG{ 'dir' } . "/domains/" . $name . "/disk.img"; if ( !-e $img ) { @@ -224,11 +224,11 @@ sub updateXenImage $mount_cmd = "mount -t auto -o loop $img $tmp"; } - elsif ( $CONFIG{'lvm'} ) + elsif ( $CONFIG{ 'lvm' } ) { # The LVM volume - $img = "/dev/" . $CONFIG{'lvm'} . "/$name-disk"; + $img = "/dev/" . $CONFIG{ 'lvm' } . "/$name-disk"; # make sure it exists. if ( !-e $img ) @@ -239,22 +239,22 @@ sub updateXenImage $mount_cmd = "mount -t auto $img $tmp"; } - elsif ( $CONFIG{'evms'} ) + 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 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 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. @@ -279,8 +279,8 @@ 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" ) ) { # @@ -293,7 +293,7 @@ sub updateXenImage # Now upgrade # system( -"DEBIAN_FRONTEND=noninteractive chroot $tmp /usr/bin/apt-get upgrade --yes --force-yes" + "DEBIAN_FRONTEND=noninteractive chroot $tmp /usr/bin/apt-get upgrade --yes --force-yes" ); } else @@ -326,8 +326,8 @@ sub xenRunning my $running = 0; - open( CMD, "xm list 2>/dev/null |" ) - or die "Failed to run 'xm list $hostname'"; + open( CMD, "xm list 2>/dev/null |" ) or + die "Failed to run 'xm list $hostname'"; while () { my $line = $_; @@ -407,7 +407,7 @@ sub readConfigurationFile } # Store value. - $CONFIG{$key} = $val; + $CONFIG{ $key } = $val; } } @@ -432,11 +432,10 @@ sub parseCommandLineArguments # Parse options. # - GetOptions( - "dir=s", \$CONFIG{'dir'}, "lvm=s", \$CONFIG{'lvm'}, - "evms=s", \$CONFIG{'evms'}, "help", \$HELP, - "manual", \$MANUAL, "version", \$VERSION - ); + GetOptions( "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; @@ -475,7 +474,7 @@ sub checkArguments my $count = 0; foreach my $type (qw/dir lvm evms/) { - $count += 1 if defined( $CONFIG{$type} ); + $count += 1 if defined( $CONFIG{ $type } ); } # diff --git a/bin/xt-create-xen-config b/bin/xt-create-xen-config index 267ba17..3a6b9c3 100755 --- a/bin/xt-create-xen-config +++ b/bin/xt-create-xen-config @@ -150,7 +150,7 @@ my @PARTITIONS = undef; # # Default options # -$CONFIG{'template'} = '/etc/xen-tools/xm.tmpl'; +$CONFIG{ 'template' } = '/etc/xen-tools/xm.tmpl'; # @@ -175,7 +175,7 @@ checkArguments(); # # If we've been given any administrators then set them up. # -if ( $ENV{'admins'} ) +if ( $ENV{ 'admins' } ) { setupAdminUsers(); } @@ -213,16 +213,15 @@ sub parseCommandLineArguments # # Parse options. # - GetOptions( - "admins=s", \$ENV{'admins'}, - "output=s", \$CONFIG{'output'}, - "extension=s", \$CONFIG{'extension'}, - "template=s", \$CONFIG{'template'}, - "verbose", \$CONFIG{'verbose'}, + 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 - ); + ); pod2usage(1) if $HELP; pod2usage( -verbose => 2 ) if $MANUAL; @@ -257,7 +256,7 @@ sub checkArguments # # We require an output location. # - if ( !defined( $CONFIG{'output'} ) ) + if ( !defined( $CONFIG{ 'output' } ) ) { print "The '--output' argument is mandatory\n"; exit 1; @@ -266,10 +265,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"; + "The output directory we've been given, $CONFIG{'output'}, doesnt exist\n"; print "Aborting\n"; exit 1; } @@ -277,12 +276,12 @@ sub checkArguments # # Make sure that any specified template file exists. # - if ( defined( $CONFIG{'template'} ) ) + if ( defined( $CONFIG{ 'template' } ) ) { - if ( !-e $CONFIG{'template'} ) + if ( !-e $CONFIG{ 'template' } ) { print -"The specified template file, $CONFIG{'template'} does not exist.\n"; + "The specified template file, $CONFIG{'template'} does not exist.\n"; exit 1; } } @@ -306,21 +305,17 @@ 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] } ); } } @@ -342,26 +337,27 @@ sub createXenConfig # # The output file we're going to process. # - my $file = $CONFIG{'output'} . '/' . $ENV{'hostname'} . $ENV{'extension'}; + my $file = + $CONFIG{ 'output' } . '/' . $ENV{ 'hostname' } . $ENV{ 'extension' }; # # The template we're going to read from. # my $template = new Text::Template( TYPE => 'FILE', - SOURCE => $CONFIG{'template'} ); + SOURCE => $CONFIG{ 'template' } ); # # The device we're using. # my $device = 'sda'; - if ( defined( $ENV{'ide'} ) ) + if ( defined( $ENV{ 'ide' } ) ) { $device = 'hda'; } - elsif ( defined( $ENV{'disk_device'} ) ) + elsif ( defined( $ENV{ 'disk_device' } ) ) { - $device = $ENV{'disk_device'}; + $device = $ENV{ 'disk_device' }; # strip /dev/, if present. if ( $device =~ /^(.*)\/(.*)$/ ) @@ -369,65 +365,65 @@ sub createXenConfig $device = $2; } } - $ENV{'device'} = $device; + $ENV{ 'device' } = $device; # # The memory size: Convert Gb -> Mb. # - if ( $ENV{'memory'} =~ /^(\d+)Gb*$/i ) + if ( $ENV{ 'memory' } =~ /^(\d+)Gb*$/i ) { - $ENV{'memory'} = $1 * 1024; + $ENV{ 'memory' } = $1 * 1024; } # # Remove any trailing Mb. # - if ( $ENV{'memory'} =~ /^(\d+)Mb*$/i ) + if ( $ENV{ 'memory' } =~ /^(\d+)Mb*$/i ) { - $ENV{'memory'} = $1; + $ENV{ 'memory' } = $1; } # # Images as presented to Xen - either loopback images, or LVM partitions. # - if ( $ENV{'lvm'} ) + if ( $ENV{ 'lvm' } ) { - $ENV{'image_prefix'} = "phy:$ENV{'lvm'}/$ENV{'hostname'}-"; - $ENV{'image_suffix'} = ''; + $ENV{ 'image_prefix' } = "phy:$ENV{'lvm'}/$ENV{'hostname'}-"; + $ENV{ 'image_suffix' } = ''; importPartitionsFromEnvironment(); } - elsif ( $ENV{'evms'} ) + elsif ( $ENV{ 'evms' } ) { - $ENV{'image_prefix'} = "phy:/dev/evms/$ENV{'hostname'}-"; - $ENV{'image_suffix'} = ''; + $ENV{ 'image_prefix' } = "phy:/dev/evms/$ENV{'hostname'}-"; + $ENV{ 'image_suffix' } = ''; importPartitionsFromEnvironment(); } - elsif ( $ENV{'image-dev'} ) + elsif ( $ENV{ 'image-dev' } ) { - $ENV{'image_vbd'} = "phy:$ENV{'image-dev'}"; + $ENV{ 'image_vbd' } = "phy:$ENV{'image-dev'}"; - if ( $ENV{'swap-dev'} ) + if ( $ENV{ 'swap-dev' } ) { - $ENV{'swap_vbd'} = "phy:$ENV{'swap-dev'}"; + $ENV{ 'swap_vbd' } = "phy:$ENV{'swap-dev'}"; } else { - $ENV{'swap_vbd'} = undef; + $ENV{ 'swap_vbd' } = undef; } } else { - $ENV{'image_prefix'} = "file:$ENV{'dir'}/domains/$ENV{'hostname'}/"; - $ENV{'image_suffix'} = '.img'; + $ENV{ 'image_prefix' } = "file:$ENV{'dir'}/domains/$ENV{'hostname'}/"; + $ENV{ 'image_suffix' } = '.img'; importPartitionsFromEnvironment(); } # # The xen-tools version. # - $ENV{'xen_tools_version'} = $RELEASE; + $ENV{ 'xen_tools_version' } = $RELEASE; # @@ -438,9 +434,9 @@ sub createXenConfig my %vars; foreach my $key ( sort keys %ENV ) { - $vars{$key} = $ENV{$key}; + $vars{ $key } = $ENV{ $key }; } - $vars{'PARTITIONS'} = \@PARTITIONS; + $vars{ 'PARTITIONS' } = \@PARTITIONS; # # Now output the data. @@ -510,7 +506,7 @@ sub setupAdminUsers # For each user make sure they exist, and setup the # login shell for them. # - foreach my $user ( split( /,/, $ENV{'admins'} ) ) + foreach my $user ( split( /,/, $ENV{ 'admins' } ) ) { # Strip leading and trailing whitespace. @@ -525,22 +521,22 @@ sub setupAdminUsers { # Change shell. - $CONFIG{'verbose'} && print "Changing shell for $user: $shell\n"; + $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"; + $CONFIG{ 'verbose' } && print "Adding new user: $user\n"; system( "useradd", "-s", $shell, $user ); } # # Add the entry to /etc/sudoers. # - open( SUDOERS, ">>", "/etc/sudoers" ) - or warn "Failed to add user to sudoers file : $user - $!"; + 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 a7ac3e5..cf6cf94 100755 --- a/bin/xt-customize-image +++ b/bin/xt-customize-image @@ -144,14 +144,13 @@ sub parseCommandLineArguments # # Parse options. # - GetOptions( - "location=s", \$CONFIG{'location'}, - "dist=s", \$CONFIG{'dist'}, - "verbose", \$CONFIG{'verbose'}, + GetOptions( "location=s", \$CONFIG{ 'location' }, + "dist=s", \$CONFIG{ 'dist' }, + "verbose", \$CONFIG{ 'verbose' }, "help", \$HELP, "manual", \$MANUAL, "version", \$VERSION - ); + ); pod2usage(1) if $HELP; pod2usage( -verbose => 2 ) if $MANUAL; @@ -186,7 +185,7 @@ sub checkArguments # # We require a location. # - if ( !defined( $CONFIG{'location'} ) ) + if ( !defined( $CONFIG{ 'location' } ) ) { print "The '--location' argument is mandatory\n"; exit 1; @@ -196,7 +195,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"; @@ -207,7 +206,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; @@ -221,7 +220,7 @@ 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 ) { @@ -263,12 +262,12 @@ sub runDistributionHooks # # Hook directory. # - my $hooks = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d/"; + my $hooks = "/usr/lib/xen-tools/" . $CONFIG{ 'dist' } . ".d/"; # # Installation prefix # - my $prefix = $CONFIG{'location'}; + my $prefix = $CONFIG{ 'location' }; # # If we're running verbosely then setup the client environment @@ -277,9 +276,9 @@ sub runDistributionHooks # This is useful in case this script is called outwith the usual # xen-create-image framework. # - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { - $ENV{'verbose'} = 1; + $ENV{ 'verbose' } = 1; } # @@ -317,7 +316,7 @@ sub runDistributionHooks # Run the command. This has different prolog and epilog # depending on whether we're running verbosely or not. # - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { print "Running hook $name ['$cmd']\n"; print "--\n"; diff --git a/bin/xt-install-image b/bin/xt-install-image index 23befeb..f1498bd 100755 --- a/bin/xt-install-image +++ b/bin/xt-install-image @@ -128,33 +128,26 @@ my $RELEASE = '4.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, - } -); + "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, + } ); @@ -173,9 +166,9 @@ parseCommandLineArguments(); # # If we received a configuration file then read it. # -if ( $CONFIG{'config'} ) +if ( $CONFIG{ 'config' } ) { - my $path = $CONFIG{'config'}; + my $path = $CONFIG{ 'config' }; # If not fully-qualified then read from /etc/xen-tools. if ( $path !~ /^[\/]/ ) @@ -197,14 +190,14 @@ 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) ) { @@ -214,48 +207,48 @@ if ( defined( $CONFIG{'install-method'} ) # # 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 "\t" . $installer->{'needBinary'} . "\n"; + "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'} ) + if ( $CONFIG{ 'install-source' } ) { print -"The specified directory $CONFIG{'install-source'} does not exist.\n"; + "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'} ) + if ( $CONFIG{ 'install-source' } ) { print -"The specified file $CONFIG{'install-source'} does not exist.\n"; + "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; @@ -266,7 +259,7 @@ if ( defined( $CONFIG{'install-method'} ) # # Now we can call the appropriate handler. # - $installer->{'sub'}->(); + $installer->{ 'sub' }->(); # # Did the operation succeed? @@ -275,7 +268,7 @@ if ( defined( $CONFIG{'install-method'} ) # 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"; @@ -375,7 +368,7 @@ sub readConfigurationFile } # Store value. - $CONFIG{$key} = $val; + $CONFIG{ $key } = $val; } } @@ -404,22 +397,22 @@ sub parseCommandLineArguments GetOptions( # Mandatory - "location=s", \$CONFIG{'location'}, - "dist=s", \$CONFIG{'dist'}, - "hostname=s", \$CONFIG{'hostname'}, + "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'}, + "install-method=s", \$CONFIG{ 'install-method' }, + "install-source=s", \$CONFIG{ 'install-source' }, # Misc - "arch=s", \$CONFIG{'arch'}, - "cache=s", \$CONFIG{'cache'}, - "config=s", \$CONFIG{'config'}, - "mirror=s", \$CONFIG{'mirror'}, + "arch=s", \$CONFIG{ 'arch' }, + "cache=s", \$CONFIG{ 'cache' }, + "config=s", \$CONFIG{ 'config' }, + "mirror=s", \$CONFIG{ 'mirror' }, # Help. - "verbose", \$CONFIG{'verbose'}, + "verbose", \$CONFIG{ 'verbose' }, "help", \$HELP, "manual", \$MANUAL, "version", \$VERSION @@ -458,7 +451,7 @@ sub checkArguments # # We require a location. # - if ( !defined( $CONFIG{'location'} ) ) + if ( !defined( $CONFIG{ 'location' } ) ) { print "The '--location' argument is mandatory\n"; exit 1; @@ -468,7 +461,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"; @@ -479,7 +472,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; @@ -493,7 +486,7 @@ 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 ) { @@ -516,12 +509,12 @@ E_OR # Test that we received a valid installation type. # my $valid = 0; - if ( defined( $CONFIG{'install-method'} ) ) + if ( defined( $CONFIG{ 'install-method' } ) ) { foreach my $recognised ( keys %dispatch ) { $valid = 1 - if ( lc( $CONFIG{'install-method'} ) eq lc($recognised) ); + if ( lc( $CONFIG{ 'install-method' } ) eq lc($recognised) ); } } else @@ -567,7 +560,7 @@ sub runCommand # # Command start. # - $CONFIG{'verbose'} && print "Executing : $cmd\n"; + $CONFIG{ 'verbose' } && print "Executing : $cmd\n"; # # Copy stderr to stdout, so we can see it, and make sure we log it. @@ -589,7 +582,7 @@ sub runCommand # # Command finished. # - $CONFIG{'verbose'} && print "Finished : $cmd\n"; + $CONFIG{ 'verbose' } && print "Finished : $cmd\n"; return ($output); } @@ -659,7 +652,7 @@ sub do_copy # # Find the copy command to run from the configuration file. # - my $cmd = $CONFIG{'copy-cmd'}; + my $cmd = $CONFIG{ 'copy-cmd' }; if ( !defined($cmd) ) { print "Falling back to default copy command\n"; @@ -695,7 +688,7 @@ sub do_debootstrap # The command is a little configurable - mostly to allow you # to use cdebootstrap. # - my $cmd = $CONFIG{'debootstrap-cmd'}; + my $cmd = $CONFIG{ 'debootstrap-cmd' }; if ( !defined($cmd) ) { print "Falling back to default debootstrap command\n"; @@ -707,7 +700,7 @@ sub do_debootstrap # Cache from host -> new installation if we've got caching # enabled. # - if ( $CONFIG{'cache'} eq "yes" ) + if ( $CONFIG{ 'cache' } eq "yes" ) { print "\nCopying files from host to image.\n"; runCommand("mkdir -p $CONFIG{'location'}/var/cache/apt/archives"); @@ -720,7 +713,7 @@ sub do_debootstrap # Propogate --verbose appropriately. # my $EXTRA = ''; - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { $EXTRA = ' --verbose'; } @@ -728,7 +721,7 @@ sub do_debootstrap # # Propogate the --arch argument # - if ( $CONFIG{'arch'} ) + if ( $CONFIG{ 'arch' } ) { $EXTRA .= " --arch $CONFIG{'arch'}"; } @@ -750,7 +743,7 @@ sub do_debootstrap # Cache from the new installation -> the host if we've got caching # enabled. # - if ( $CONFIG{'cache'} eq "yes" ) + if ( $CONFIG{ 'cache' } eq "yes" ) { print "\nCopying files from new installation to host.\n"; copyDebFiles( "$CONFIG{'location'}/var/cache/apt/archives", @@ -806,16 +799,16 @@ sub do_image_server # # Build up the request we're going to send. # - my $request = $CONFIG{'install-source'} . "/create.cgi?submit=1"; + my $request = $CONFIG{ 'install-source' } . "/create.cgi?submit=1"; # # Some parameters are hard-wired. # $request .= "&arch=amd64"; $request .= "&root_device=/dev/sda"; - $request .= "&ip1=" . $ENV{'ip1'}; - $request .= "&dist=" . CGI::escapeHTML( $CONFIG{'dist'} ); - $request .= "&hostname=" . CGI::escapeHTML( $CONFIG{'hostname'} ); + $request .= "&ip1=" . $ENV{ 'ip1' }; + $request .= "&dist=" . CGI::escapeHTML( $CONFIG{ 'dist' } ); + $request .= "&hostname=" . CGI::escapeHTML( $CONFIG{ 'hostname' } ); # # We only care about some keys @@ -824,10 +817,10 @@ sub do_image_server { # Skip values which aren't defined. - next unless defined $ENV{$k}; + next unless defined $ENV{ $k }; # CGI encode. - my $val = CGI::escapeHTML( $ENV{$k} ); + my $val = CGI::escapeHTML( $ENV{ $k } ); # Add on to the request $request .= "&$k=$val"; @@ -852,14 +845,14 @@ sub do_image_server if ( $content =~ /fetch.cgi\?session=([^"]+)"/ ) { my $session = $1; - my $new = $CONFIG{'install-source'}; + my $new = $CONFIG{ 'install-source' }; $new .= "/fetch.cgi?session=$session"; my $attempt = 1; # Make sure we don't wait indefinitely. while ( $attempt < $attempts ) { - $CONFIG{'verbose'} && print "Request: [$attempt/$attempts]\n"; + $CONFIG{ 'verbose' } && print "Request: [$attempt/$attempts]\n"; # # Make a request to see if our tar file is ready yet. @@ -872,7 +865,7 @@ sub do_image_server # Get the headers # my $header = $response->headers(); - my $type = $header->{'content-type'}; + my $type = $header->{ 'content-type' }; # # OK our file is correct. @@ -884,14 +877,14 @@ sub do_image_server # 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" + "cd $CONFIG{'location'} && tar --numeric-owner -xf $session.tar && rm -f $CONFIG{'location'}/$session.tar" ); return 1; } @@ -913,8 +906,8 @@ sub do_image_server } 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; } } @@ -941,7 +934,7 @@ sub do_rinse # # Propogate the --arch argument # - if ( $CONFIG{'arch'} ) + if ( $CONFIG{ 'arch' } ) { $command .= " --arch $CONFIG{'arch'}"; } @@ -950,7 +943,7 @@ sub do_rinse # # Propogate the verbosity setting. # - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { $command .= " --verbose"; } @@ -975,7 +968,7 @@ sub do_rpmstrap # Propogate the verbosity setting. # my $EXTRA = ''; - if ( $CONFIG{'verbose'} ) + if ( $CONFIG{ 'verbose' } ) { $EXTRA .= " --verbose"; } @@ -983,7 +976,7 @@ sub do_rpmstrap # # Propogate any arch setting we might have. # - if ( $CONFIG{'arch'} ) + if ( $CONFIG{ 'arch' } ) { $EXTRA .= " --arch $CONFIG{'arch'}"; } @@ -992,7 +985,7 @@ 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. @@ -1017,7 +1010,7 @@ sub do_tar # # Find the tar command to run from the configuration file. # - my $cmd = $CONFIG{'tar-cmd'}; + my $cmd = $CONFIG{ 'tar-cmd' }; if ( !defined($cmd) ) { print "Falling back to default tar command\n";