From 0e13487eeba56d51f795e5a0b8ec7df3babac964 Mon Sep 17 00:00:00 2001 From: vallard Date: Thu, 17 Dec 2009 21:06:41 +0000 Subject: [PATCH] added back Lissas changes that I accidentally overwrote git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4822 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-client/bin/genimage | 169 +++++++++++++++++++++++---------------- 1 file changed, 101 insertions(+), 68 deletions(-) diff --git a/xCAT-client/bin/genimage b/xCAT-client/bin/genimage index 67e156fe6..313ecc391 100755 --- a/xCAT-client/bin/genimage +++ b/xCAT-client/bin/genimage @@ -1,8 +1,20 @@ #!/usr/bin/perl +BEGIN +{ + $::XCATROOT = + $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} + : -d '/opt/xcat' ? '/opt/xcat' + : '/usr'; +} +use lib "$::XCATROOT/lib/perl"; use strict; + +use Getopt::Long; +require xCAT::MsgUtils; +require xCAT::DSHCLI; +use xCAT::Utils; use Term::ANSIColor; use File::Basename; -use Getopt::Long; # genimage is a wrapper to the genimages located in # /opt/xcat/share/xcat/netboot// # put tab completion @@ -12,18 +24,37 @@ $::XCATROOT = "/opt/xcat"; my $os = ""; my $profile = ""; my $interface = ""; +my $version; my $drivers = ""; my $otherInterfaces = ""; my $kernel = ""; -my $method = ""; my @oses; # available OSes. my @profiles; # available profiles my $profDir; # root where you do ./genimage from my $help; my $match = 0; my $color = 0; +my $method; -GetOptions( +#----------------------------------------------------------------------------- + +=head3 print_usage - usage message + +=cut + +#----------------------------------------------------------------------------- +sub print_usage +{ + print "Usage: genimage -h\n"; + print " genimage -v\n"; + print " genimage [-i ] [-n ] [-r ]\n [-o ] [-p ] [-k ] [-m ]\n"; + print "Examples:\n"; + print " genimage -i eth0 -n igb,e1000e,bnx2 -o centos5.4 -p compute\n"; + print " genimage -o suse11\n"; + print " genimage\n"; + return; +} +if (!GetOptions( 'o=s' => \$os, 'i=s' => \$interface, 'p=s' => \$profile, @@ -31,20 +62,27 @@ GetOptions( 'k=s' => \$kernel, 'r=s' => \$otherInterfaces, 'h|help' => \$help, + 'v|version' => \$version, 'm=s' => \$method, 'c' => \$color -); - -if($help){ - print 'genimage is a shell for the genimage located in /opt/xcat/share/xcat/netboot//\n'; - print 'Usage: genimage [-i ] [-n ] [-r ] [-o ] [-p ] [-k ] <-m statelite>'."\n"; - print "Examples:\n"; - print " genimage -i eth0 -n igb,e1000e,bnx2 -o centos5.4 -p compute\n"; - print " genimage -o suse11\n"; - print " genimage\n"; + +)) { + &print_usage; exit 1; } +if($help){ + print "genimage is a shell for the genimage located in /opt/xcat/share/xcat/netboot/.\n"; + &print_usage; + exit 0; +} + +if ($version){ + my $version = xCAT::Utils->Version(); + xCAT::MsgUtils->message("N", $version); + exit 0; + +} unless($os){ # get the install directory my $installdir = `gettab key=installdir site.value`; @@ -75,13 +113,13 @@ unless($os){ # now they have the OSes, make sure they select one that is available $match = 0; while(1){ - print color("bold") if $color; + print color("bold"); print "Available OSes: \n"; - print color("reset") if $color; + print color("reset"); foreach(@oses){ - print color("yellow bold") if $color; - print "$_\n"; - print color("reset") if $color; + $color && print color("green" ); + print "$_\n"; + $color && print color("reset"); } # default is the first OS cause in many cases, they'll only have 1. print "Which OS to you want to build a netboot image for? ["; @@ -109,10 +147,10 @@ unless($os){ chomp($os); } -print color("cyan") if $color; +$color && print color("cyan"); print "os: $os\n"; -print color("reset"); - +$color && print color("reset"); + ### Get the Profile #### @@ -148,9 +186,9 @@ unless($profile){ while(1){ print color("bold"), "Available Profiles for $os: \n", color("reset"); foreach(@profiles){ - print color("yellow bold") if $color; - print "$_\n"; - print color("reset") if $color; + $color && print color("green"); + print "$_\n"; + $color && print color("reset"); } # default is the first OS cause in many cases, they'll only have 1. print "Which profile do you want to use for $os? ["; @@ -173,9 +211,9 @@ unless($profile){ } } } -print color("cyan") if $color; -print "profile: $profile\n"; -print color("reset") if $color; +$color && print color("cyan"); +print "profile: $profile\n"; +$color && print color("reset"); # get the interface unless($interface){ @@ -190,9 +228,9 @@ unless($interface){ last; }else{ print "You want your stateless machines to boot off of "; - print color("cyan") if $color; - print $interface; - print color("reset") if $color; + $color && print color("cyan"); + print "$interface"; + $color && print color("reset"); print "? "; print color("bold"),"[Y/n] ", color("reset"); my $conf = ; @@ -206,18 +244,16 @@ unless($interface){ } } } -print color("cyan") if $color; +$color && print color("cyan"); print "interface: $interface\n"; -print color("reset") if $color; +$color && print color("reset"); # get drivers unless($drivers){ while(1){ print "Which network drivers will you need? (press enter if you're not sure) "; - print color("bold"); - print "\n[igb,e1000e,e1000,bnx2,tg3] "; - print color("reset"); + print color("bold"), "\n[igb,e1000e,e1000,bnx2,tg3] ", color("reset"); $drivers = ; chomp($drivers); @@ -225,10 +261,10 @@ unless($drivers){ $drivers = "igb,e1000e,e1000,bnx2,tg3"; last; }else{ - print "You want to use the following driver(s):"; - print color("cyan") if $color; - print $drivers; - print color("reset") if $color; + print "You want to use the following driver(s): "; + $color && print color("cyan"); + print $drivers; + $color && color("reset"); print "? "; print color("bold"),"[Y/n] ", color("reset"); my $conf = ; @@ -242,9 +278,9 @@ unless($drivers){ } } } -print color("cyan") if $color; -print "$drivers\n"; -print color("reset") if $color; +$color && print color("cyan"); +print "$drivers\n"; +$color && print color("reset"); # get other interfaces unless($otherInterfaces){ @@ -269,10 +305,10 @@ unless($otherInterfaces){ if($tmp eq ""){ last; }else{ - print "You want to also set up:"; - print color("cyan") if $color; - print $tmp ; - print color("reset") if $color; + print "You want to also set up: "; + $color && print color("cyan"); + print $tmp; + $color && print color("reset"); print "? "; print color("bold"),"[Y/n] ", color("reset"); my $conf = ; @@ -290,9 +326,9 @@ unless($otherInterfaces){ } # end question loop } # end getting other interfaces if($otherInterfaces){ - print color("cyan") if $color; - print "Other Interfaces: $otherInterfaces\n"; - print color("reset") if $color; + $color && print color("cyan"); + print "Other Interfaces: $otherInterfaces\n"; + $color && color("reset"); } @@ -307,15 +343,15 @@ unless($kernel){ if($kernel eq ""){ # special case of RHEL5.4 where kenrel must be specified or you # get some other one - if($os =~ /rhels5.4|centos5.4/){ + if($os =~ /rhels5.4|centos5.4|rhel5.4|sl5.4/){ $kernel = "2.6.18-164.el5"; } last; }else{ print "You want to use: "; - print color("cyan") if $color; + $color && print color("cyan"); print $kernel; - print color("reset") if $color; + $color && print color("reset"); print "? "; print color("bold"),"[Y/n] ", color("reset"); my $conf = ; @@ -330,30 +366,31 @@ unless($kernel){ } } # end unless kernel + unless($method){ while(1){ print "Do you want the image to be statelite? ["; - print color("bold"), "[y/N] ", color("reset"); + print color("bold"), '[y/N] ', color("reset"); my $conf = ; chomp($conf); - if($conf =~ /Y|y|[Yy][Ee][Ss]/){ - $method = "statelite"; + if($conf =~ /^Y|^y|[Yy][Ee][Ss]/){ + $method = "statelite"; last; } - if($conf eq ""){ - last; - } + if($conf eq ""){ last; } if($conf =~ /N|n|[Nn][Oo]/){ - last; + last; } + } } + if($kernel){ - print color("blue") if $color; + $color && print color("blue"); print "kernel: $kernel\n"; - print color("reset") if $color; + $color && print color("reset"); } print "Generating image:\n"; @@ -367,12 +404,8 @@ if($otherInterfaces){ if($method){ $cmd .= " -m $method"; } -print color("cyan") if $color; -print "cd $profDir\n"; -print color("reset") if $color; - -print color("cyan") if $color; -print "$cmd\n"; -print color("reset") if $color; - +$color && print color("cyan"); +print "cd $profDir\n"; +print "$cmd\n"; +$color && print color("reset"); exec("cd $profDir; $cmd");