From d86805bf1e155e5601a21e7b9fc11a90dea56b62 Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 18 Dec 2005 16:32:32 +0000 Subject: [PATCH] 2005-12-18 16:32:32 by steve Moved more things to the $CONFIG hash. Removed global help + manual markers they are now local. --- etc/xen-tools.conf | 7 ++- xen-create-image | 129 ++++++++++++++++++++++++++------------------- 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/etc/xen-tools.conf b/etc/xen-tools.conf index dd22b87..5c1c9c1 100644 --- a/etc/xen-tools.conf +++ b/etc/xen-tools.conf @@ -11,7 +11,7 @@ # --fs=ext3 becomes 'fs=ext3'. # # -# $Id: xen-tools.conf,v 1.2 2005-12-18 16:22:11 steve Exp $ +# $Id: xen-tools.conf,v 1.3 2005-12-18 16:32:32 steve Exp $ # @@ -22,4 +22,7 @@ # fs = ext3 -gateway=192.168.1.1 \ No newline at end of file +gateway=192.168.1.1 + +netmask=255.255.255.0 + diff --git a/xen-create-image b/xen-create-image index 6ab41c8..3446483 100755 --- a/xen-create-image +++ b/xen-create-image @@ -120,7 +120,7 @@ Read the manual, with examples. -- http://www.steve.org.uk/ - $Id: xen-create-image,v 1.13 2005-12-18 16:22:11 steve Exp $ + $Id: xen-create-image,v 1.14 2005-12-18 16:32:32 steve Exp $ =cut @@ -154,7 +154,6 @@ my %CONFIG; # # Options set on the command line. # -my $HOSTNAME; # Mandatory. my $DIR; # Mandatory. @@ -163,17 +162,9 @@ my $DIR; # Mandatory. # DHCP must be selected. # # -my $NETMASK="255.255.255.0"; # set with '--mask=dd.dd.dd.dd' -my $BROADCAST="192.168.1.255"; # set with '--broadcase=ddd.dd.dd.d' -my $NETWORK="192.168.1.0"; # set with '--network=dd.dd.dd.dd' - my $MIRROR="http://ftp.us.debian.org/debian"; # set with '--mirror=http://www.etc.com"' -my $SIZE="2000M"; # set with '--size=1000M[b] / 1G[b]" -my $SWAP_SIZE="128M"; # set with '--swapsize=... like --size" -my $MEMORY="96M"; # set with --memory=128Mb/128M my $FS='ext3'; -my $HELP; -my $MANUAL; + # @@ -193,8 +184,17 @@ $FILESYSTEM_MOUNT{'reiserfs'} = '-t reiserfs'; # -# Start of the script. +# Setup defaults: # +# Memory = 96M, Image = 2000Mb, Swap = 128Mb, and filesystem is ext3. +# +# These may be overriden by one of the configuration files, or by the +# command line arguments. +# +$CONFIG{'memory'} = '96Mb'; +$CONFIG{'size'} = '2000Mb'; +$CONFIG{'swap'} = '128M'; +$CONFIG{'fs'} = 'ext3'; # @@ -227,7 +227,24 @@ parseCommandLineArguments(); # checkArguments(); +print "\n"; +print "Hostname : $CONFIG{'hostname'}\n"; +print "Image size: $CONFIG{'size'}\n"; +print "Swap size: $CONFIG{'swap'}\n"; +print "Fileystem: $CONFIG{'fs'}\n"; +if ( $CONFIG{'dhcp'} ) +{ + print "DHCP\n"; +} +else +{ + $CONFIG{'ip'} && print "IP : $CONFIG{'ip'}\n"; + $CONFIG{'network'} && print "Network : $CONFIG{'network'}\n"; + $CONFIG{'broadcast'} && print "Broadcast: $CONFIG{'broadcast'}\n"; + $CONFIG{'gateway'} && print "Gateway : $CONFIG{'gateway'}\n"; +} +print "---\n"; # # If the output directories don't exist then create them. @@ -237,10 +254,10 @@ if ( ! -d $DIR . "/domains/" ) mkdir $DIR . '/domains', 0777 || die "Cannot create $DIR/domains - $!"; } -if ( ! -d $DIR . "/domains/" . $HOSTNAME ) +if ( ! -d $DIR . "/domains/" . $CONFIG{'hostname'} ) { - mkdir $DIR. '/domains/' . $HOSTNAME, 0777 - || die "Cannot create $DIR/domains/$HOSTNAME - $!" ; + mkdir $DIR. '/domains/' . $CONFIG{'hostname'}, 0777 + || die "Cannot create $DIR/domains/$CONFIG{'hostname'} - $!" ; } @@ -248,15 +265,15 @@ if ( ! -d $DIR . "/domains/" . $HOSTNAME ) # # The two images we'll use, one for the disk image, one for swap. # -my $image = $DIR . '/domains/' . $HOSTNAME . "/disk.img" ; -my $swap = $DIR . '/domains/' . $HOSTNAME . "/swap.img" ; +my $image = $DIR . '/domains/' . $CONFIG{'hostname'} . "/disk.img" ; +my $swap = $DIR . '/domains/' . $CONFIG{'hostname'} . "/swap.img" ; # # Create swapfile and initialise it. # print "Creating swapfile : $swap\n"; -$SWAP_SIZE =~ s/Mb*$//i; -`/bin/dd if=/dev/zero of=$swap bs=1024k count=$SWAP_SIZE >/dev/null 2>/dev/null`; +$CONFIG{'swap'} =~ s/Mb*$//i; +`/bin/dd if=/dev/zero of=$swap bs=1024k count=$CONFIG{'swap'} >/dev/null 2>/dev/null`; print "Initializing swap file\n"; `/sbin/mkswap $swap`; print "Done\n"; @@ -265,8 +282,8 @@ print "Done\n"; # Create disk file and initialise it. # print "Creating disk image: $image\n"; -$SIZE =~ s/Mb*$/k/i; -`/bin/dd if=/dev/zero of=$image bs=$SIZE count=1 seek=1024 >/dev/null 2>/dev/null`; +$CONFIG{'size'} =~ s/Mb*$/k/i; +`/bin/dd if=/dev/zero of=$image bs=$CONFIG{'size'} count=1 seek=1024 >/dev/null 2>/dev/null`; print "Creating EXT3 filesystem\n"; my $create = $FILESYSTEM_CREATE{lc( $FS ) } . $image; @@ -402,11 +419,11 @@ fixupInittab( $dir ); # Finally setup Xen to allow us to create the image. # print "Setting up Xen configuration file .. "; -open( XEN, ">", "/etc/xen/$HOSTNAME.cfg" ); +open( XEN, ">", "/etc/xen/$CONFIG{'hostname'}.cfg" ); print XEN< Mb - if ( $SIZE =~ /^(\d+)Gb*$/i ) + if ( $CONFIG{'size'} =~ /^(\d+)Gb*$/i ) { - $SIZE = $1 * 1024 . "M"; + $CONFIG{'size'} = $1 * 1024 . "M"; } - if ( $SWAP_SIZE =~ /^(\d+)Gb*$/i ) + if ( $CONFIG{'swap'} =~ /^(\d+)Gb*$/i ) { - $SWAP_SIZE = $1 * 1024 . "M"; + $CONFIG{'swap'} = $1 * 1024 . "M"; } # Strip trailing Mb from the memory size. - if ( $MEMORY =~ /^(\d+)Mb*$/i ) + if ( $CONFIG{'memory'} =~ /^(\d+)Mb*$/i ) { - $MEMORY = $1; + $CONFIG{'memory'} = $1; } @@ -644,10 +663,10 @@ EOF if ( $CONFIG{'dhcp'} ) { - $CONFIG{'gateway'} = ''; - $NETMASK = ""; - $BROADCAST = ""; - $CONFIG{'ip'} = ''; + $CONFIG{'gateway'} = ''; + $CONFIG{'netmask'} = ''; + $CONFIG{'broadcast'} = ''; + $CONFIG{'ip'} = ''; } # @@ -678,7 +697,7 @@ sub setupNetworking { my ( $prefix ) = ( @_ ); - `echo '$HOSTNAME' > $prefix/etc/hostname`; + `echo '$CONFIG{'hostname'}' > $prefix/etc/hostname`; open( IP, ">", $prefix . "/etc/network/interfaces" ); @@ -713,9 +732,9 @@ auto eth0 iface eth0 inet static address $CONFIG{'ip'} gateway $CONFIG{'gateway'} - netmask $NETMASK - network $NETWORK - broadcast $BROADCAST + netmask $CONFIG{'netmask'} + network $CONFIG{'network'} + broadcast $CONFIG{'broadcast'} E_O_STATIC_IP }