2009-11-07 22:09:57 +00:00
|
|
|
#!/usr/bin/perl
|
2009-12-17 21:06:41 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT =
|
|
|
|
$ENV{'XCATROOT'} ? $ENV{'XCATROOT'}
|
|
|
|
: -d '/opt/xcat' ? '/opt/xcat'
|
|
|
|
: '/usr';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2009-11-07 22:09:57 +00:00
|
|
|
use strict;
|
2009-12-17 21:06:41 +00:00
|
|
|
|
|
|
|
use Getopt::Long;
|
|
|
|
require xCAT::MsgUtils;
|
|
|
|
require xCAT::DSHCLI;
|
|
|
|
use xCAT::Utils;
|
2009-11-07 22:09:57 +00:00
|
|
|
use Term::ANSIColor;
|
|
|
|
use File::Basename;
|
|
|
|
# genimage is a wrapper to the genimages located in
|
|
|
|
# /opt/xcat/share/xcat/netboot/<os>/
|
|
|
|
# put tab completion
|
|
|
|
# colors
|
|
|
|
# remember the last one done
|
|
|
|
$::XCATROOT = "/opt/xcat";
|
|
|
|
my $os = "";
|
|
|
|
my $profile = "";
|
|
|
|
my $interface = "";
|
2009-12-17 21:06:41 +00:00
|
|
|
my $version;
|
2009-11-07 22:09:57 +00:00
|
|
|
my $drivers = "";
|
|
|
|
my $otherInterfaces = "";
|
|
|
|
my $kernel = "";
|
|
|
|
my @oses; # available OSes.
|
|
|
|
my @profiles; # available profiles
|
|
|
|
my $profDir; # root where you do ./genimage from
|
|
|
|
my $help;
|
|
|
|
my $match = 0;
|
2009-12-15 20:27:36 +00:00
|
|
|
my $color = 0;
|
2009-12-17 21:06:41 +00:00
|
|
|
my $method;
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
2009-11-07 22:09:57 +00:00
|
|
|
|
2009-12-17 21:06:41 +00:00
|
|
|
=head3 print_usage - usage message
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub print_usage
|
|
|
|
{
|
|
|
|
print "Usage: genimage -h\n";
|
|
|
|
print " genimage -v\n";
|
|
|
|
print " genimage [-i <nodebootif>] [-n <nodenetdrivers>] [-r <additional_nics>]\n [-o <os>] [-p <profile>] [-k <kernal_version>] [-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";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!GetOptions(
|
2009-11-07 22:09:57 +00:00
|
|
|
'o=s' => \$os,
|
|
|
|
'i=s' => \$interface,
|
|
|
|
'p=s' => \$profile,
|
|
|
|
'n=s' => \$drivers,
|
|
|
|
'k=s' => \$kernel,
|
|
|
|
'r=s' => \$otherInterfaces,
|
2009-11-20 16:33:44 +00:00
|
|
|
'h|help' => \$help,
|
2009-12-17 21:06:41 +00:00
|
|
|
'v|version' => \$version,
|
2009-12-15 20:27:36 +00:00
|
|
|
'm=s' => \$method,
|
|
|
|
'c' => \$color
|
2009-12-17 21:06:41 +00:00
|
|
|
|
|
|
|
)) {
|
|
|
|
&print_usage;
|
|
|
|
exit 1;
|
|
|
|
}
|
2009-11-07 22:09:57 +00:00
|
|
|
|
|
|
|
if($help){
|
2009-12-17 21:06:41 +00:00
|
|
|
print "genimage is a shell for the genimage located in /opt/xcat/share/xcat/netboot/<osfamily>.\n";
|
|
|
|
&print_usage;
|
|
|
|
exit 0;
|
2009-11-07 22:09:57 +00:00
|
|
|
}
|
|
|
|
|
2009-12-17 21:06:41 +00:00
|
|
|
if ($version){
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
xCAT::MsgUtils->message("N", $version);
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
}
|
2009-11-07 22:09:57 +00:00
|
|
|
unless($os){
|
|
|
|
# get the install directory
|
|
|
|
my $installdir = `gettab key=installdir site.value`;
|
|
|
|
chomp($installdir);
|
|
|
|
# lots of error checking to make sure it exists.
|
|
|
|
if($installdir eq ''){
|
|
|
|
print "Could not get install directory from site table. Assuming your OSes are stored in '/install'\n";
|
|
|
|
$installdir = "/install";
|
|
|
|
}
|
|
|
|
|
|
|
|
unless(-d $installdir){
|
|
|
|
print "The directory where your OS distributions resides: $installdir does not exist. Please check site table\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
my @dircontents = `ls $installdir`;
|
|
|
|
chomp(@dircontents);
|
|
|
|
foreach (@dircontents) {
|
|
|
|
if($_ =~ /(rhel|fedora|sl|centos|suse)/){
|
|
|
|
push @oses,$_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($#oses eq -1){
|
|
|
|
print "There are no OS repositories in $installdir. Please run copycds for the OS first.\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# now they have the OSes, make sure they select one that is available
|
|
|
|
$match = 0;
|
|
|
|
while(1){
|
2009-12-17 21:06:41 +00:00
|
|
|
print color("bold");
|
2009-12-15 20:27:36 +00:00
|
|
|
print "Available OSes: \n";
|
2009-12-17 21:06:41 +00:00
|
|
|
print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
foreach(@oses){
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("green" );
|
|
|
|
print "$_\n";
|
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
}
|
|
|
|
# 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? [";
|
|
|
|
print color("bold"), $oses[0] , color("reset");
|
|
|
|
print "] ";
|
|
|
|
|
|
|
|
$os = <stdin>;
|
|
|
|
chomp($os);
|
|
|
|
if($os eq ""){
|
|
|
|
$os = @oses[0];
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
foreach(@oses){
|
|
|
|
if($os eq $_){
|
|
|
|
$match = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($match){
|
|
|
|
last;
|
|
|
|
}else{
|
|
|
|
print color("red bold"), "$os is not found in '$installdir'\n", color("reset");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
chomp($os);
|
|
|
|
}
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("cyan");
|
2009-12-15 20:27:36 +00:00
|
|
|
print "os: $os\n";
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("reset");
|
|
|
|
|
2009-11-07 22:09:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
### Get the Profile ####
|
|
|
|
my $osfamily = $os;
|
|
|
|
$osfamily =~ s/\d+//g;
|
|
|
|
$osfamily =~ s/\.//g;
|
|
|
|
if($osfamily =~ /rh/){
|
|
|
|
$osfamily = "rh";
|
|
|
|
}
|
|
|
|
|
2010-08-17 23:35:09 +00:00
|
|
|
# OS version on s390x can contain 'sp', e.g. sles11sp1
|
|
|
|
# If the $osfamily contains 'sles' and 'sp', the $osfamily = sles
|
|
|
|
if ($osfamily =~ /sles/ && $osfamily =~ /sp/) {
|
|
|
|
$osfamily = "sles";
|
|
|
|
}
|
|
|
|
|
2009-11-07 22:09:57 +00:00
|
|
|
#print "OSfamily: $osfamily\n";
|
|
|
|
$profDir = "$::XCATROOT/share/xcat/netboot/$osfamily";
|
|
|
|
unless(-d $profDir){
|
|
|
|
print color("red bold") , "Unable to find profiles in $profDir\n", color("reset");
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unless($profile){
|
|
|
|
my @proList = `ls $profDir/*.pkglist`;
|
|
|
|
my %seen = ();
|
|
|
|
foreach (@proList) {
|
|
|
|
my $f = basename($_);
|
|
|
|
$f =~ s/([^\.]*).*/$1/;
|
|
|
|
chomp($f);
|
|
|
|
$seen{$f}++;
|
|
|
|
}
|
|
|
|
@profiles = keys %seen;
|
|
|
|
if($#profiles eq -1){
|
|
|
|
print color("red bold"), "There are no profiles in $::XCATROOT/share/xcat/netboot/$osfamily.\n", color("reset");
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
$match = 0;
|
|
|
|
while(1){
|
|
|
|
print color("bold"), "Available Profiles for $os: \n", color("reset");
|
|
|
|
foreach(@profiles){
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("green");
|
|
|
|
print "$_\n";
|
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
}
|
|
|
|
# default is the first OS cause in many cases, they'll only have 1.
|
|
|
|
print "Which profile do you want to use for $os? [";
|
|
|
|
print color("bold"), $profiles[0] , color("reset");
|
|
|
|
print "] ";
|
|
|
|
|
|
|
|
$profile = <stdin>;
|
|
|
|
chomp($profile);
|
|
|
|
if($profile eq ""){
|
|
|
|
$profile = $profiles[0];
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
foreach(@profiles){
|
|
|
|
if($profile eq $_){
|
|
|
|
$match = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($match eq 1){
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("cyan");
|
|
|
|
print "profile: $profile\n";
|
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
|
|
|
|
# get the interface
|
|
|
|
unless($interface){
|
|
|
|
while(1){
|
|
|
|
print "Which network interface do you want the image to boot from? [";
|
|
|
|
print color("bold"), "eth0" ,color("reset");
|
|
|
|
print "] ";
|
|
|
|
$interface = <stdin>;
|
|
|
|
chomp($interface);
|
|
|
|
if($interface eq ""){
|
|
|
|
$interface = "eth0";
|
|
|
|
last;
|
|
|
|
}else{
|
|
|
|
print "You want your stateless machines to boot off of ";
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("cyan");
|
|
|
|
print "$interface";
|
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
print "? ";
|
|
|
|
print color("bold"),"[Y/n] ", color("reset");
|
|
|
|
my $conf = <stdin>;
|
|
|
|
chomp($conf);
|
|
|
|
if($conf eq ""){
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
if($conf =~ /Y|y|[Yy][Ee][Ss]/){
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("cyan");
|
2009-12-15 20:27:36 +00:00
|
|
|
print "interface: $interface\n";
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
# get drivers
|
|
|
|
unless($drivers){
|
|
|
|
while(1){
|
|
|
|
print "Which network drivers will you need? (press enter if you're not sure) ";
|
2009-12-17 21:06:41 +00:00
|
|
|
print color("bold"), "\n[igb,e1000e,e1000,bnx2,tg3] ", color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
|
|
|
|
$drivers = <stdin>;
|
|
|
|
chomp($drivers);
|
|
|
|
if($drivers eq ""){
|
|
|
|
$drivers = "igb,e1000e,e1000,bnx2,tg3";
|
|
|
|
last;
|
|
|
|
}else{
|
2009-12-17 21:06:41 +00:00
|
|
|
print "You want to use the following driver(s): ";
|
|
|
|
$color && print color("cyan");
|
|
|
|
print $drivers;
|
|
|
|
$color && color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
print "? ";
|
|
|
|
print color("bold"),"[Y/n] ", color("reset");
|
|
|
|
my $conf = <stdin>;
|
|
|
|
chomp($conf);
|
|
|
|
if($conf eq ""){
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
if($conf =~ /Y|y|[Yy][Ee][Ss]/){
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("cyan");
|
|
|
|
print "$drivers\n";
|
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
|
|
|
|
# get other interfaces
|
|
|
|
unless($otherInterfaces){
|
|
|
|
while(1){
|
|
|
|
print "Do you need to set up other interfaces? ";
|
|
|
|
print color("bold"), "[y/N] ",color("reset");
|
|
|
|
my $conf = <stdin>;
|
|
|
|
chomp($conf);
|
|
|
|
if($conf eq "" || $conf =~/N|n|[Nn][Oo]/){
|
|
|
|
$otherInterfaces ="";
|
|
|
|
last;
|
|
|
|
}else{
|
|
|
|
$otherInterfaces = "eth1";
|
|
|
|
if($otherInterfaces eq $interface){
|
|
|
|
$otherInterfaces = "eth0";
|
|
|
|
}
|
|
|
|
print "What other interface do you need? [";
|
|
|
|
print color("bold"), $otherInterfaces, color("reset");
|
|
|
|
print "] ";
|
|
|
|
my $tmp = <stdin>;
|
|
|
|
chomp($tmp);
|
|
|
|
if($tmp eq ""){
|
|
|
|
last;
|
|
|
|
}else{
|
2009-12-17 21:06:41 +00:00
|
|
|
print "You want to also set up: ";
|
|
|
|
$color && print color("cyan");
|
|
|
|
print $tmp;
|
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
print "? ";
|
|
|
|
print color("bold"),"[Y/n] ", color("reset");
|
|
|
|
my $conf = <stdin>;
|
|
|
|
chomp($conf);
|
|
|
|
if($conf eq ""){
|
|
|
|
$otherInterfaces = $tmp;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
if($conf =~ /Y|y|[Yy][Ee][Ss]/){
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
|
|
|
|
} #end confirmation
|
|
|
|
} # end part where they don't want default
|
|
|
|
} # end question loop
|
|
|
|
} # end getting other interfaces
|
|
|
|
if($otherInterfaces){
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("cyan");
|
|
|
|
print "Other Interfaces: $otherInterfaces\n";
|
|
|
|
$color && color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# get kernel info
|
|
|
|
unless($kernel){
|
|
|
|
while(1){
|
|
|
|
print "Which kernel do you want to use? [";
|
|
|
|
print color("bold"), "default" , color("reset");
|
|
|
|
print "] ";
|
|
|
|
$kernel = <stdin>;
|
|
|
|
chomp($kernel);
|
|
|
|
if($kernel eq ""){
|
|
|
|
# special case of RHEL5.4 where kenrel must be specified or you
|
|
|
|
# get some other one
|
2009-12-17 21:06:41 +00:00
|
|
|
if($os =~ /rhels5.4|centos5.4|rhel5.4|sl5.4/){
|
2009-11-07 22:09:57 +00:00
|
|
|
$kernel = "2.6.18-164.el5";
|
|
|
|
}
|
|
|
|
last;
|
|
|
|
}else{
|
|
|
|
print "You want to use: ";
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("cyan");
|
2009-12-15 20:27:36 +00:00
|
|
|
print $kernel;
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
print "? ";
|
|
|
|
print color("bold"),"[Y/n] ", color("reset");
|
|
|
|
my $conf = <stdin>;
|
|
|
|
chomp($conf);
|
|
|
|
if($conf eq ""){
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
if($conf =~ /Y|y|[Yy][Ee][Ss]/){
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} # end unless kernel
|
2009-12-15 20:27:36 +00:00
|
|
|
|
2009-12-17 21:06:41 +00:00
|
|
|
|
2009-12-15 20:27:36 +00:00
|
|
|
unless($method){
|
|
|
|
while(1){
|
|
|
|
print "Do you want the image to be statelite? [";
|
2009-12-17 21:06:41 +00:00
|
|
|
print color("bold"), '[y/N] ', color("reset");
|
2009-12-15 20:27:36 +00:00
|
|
|
my $conf = <stdin>;
|
|
|
|
chomp($conf);
|
2009-12-17 21:06:41 +00:00
|
|
|
if($conf =~ /^Y|^y|[Yy][Ee][Ss]/){
|
|
|
|
$method = "statelite";
|
2009-12-15 20:27:36 +00:00
|
|
|
last;
|
|
|
|
}
|
2009-12-17 21:06:41 +00:00
|
|
|
if($conf eq ""){ last; }
|
2009-12-15 20:27:36 +00:00
|
|
|
if($conf =~ /N|n|[Nn][Oo]/){
|
2009-12-17 21:06:41 +00:00
|
|
|
last;
|
2009-12-15 20:27:36 +00:00
|
|
|
}
|
2009-12-17 21:06:41 +00:00
|
|
|
|
2009-12-15 20:27:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-17 21:06:41 +00:00
|
|
|
|
2009-11-07 22:09:57 +00:00
|
|
|
if($kernel){
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("blue");
|
2009-12-15 20:27:36 +00:00
|
|
|
print "kernel: $kernel\n";
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print "Generating image:\n";
|
|
|
|
my $cmd = "./genimage -i $interface -n $drivers -o $os -p $profile ";
|
|
|
|
if($kernel){
|
|
|
|
$cmd .= " -k $kernel";
|
|
|
|
}
|
|
|
|
if($otherInterfaces){
|
|
|
|
$cmd .= " -r $otherInterfaces";
|
|
|
|
}
|
2009-12-15 20:27:36 +00:00
|
|
|
if($method){
|
|
|
|
$cmd .= " -m $method";
|
|
|
|
}
|
2009-12-17 21:06:41 +00:00
|
|
|
$color && print color("cyan");
|
|
|
|
print "cd $profDir\n";
|
|
|
|
print "$cmd\n";
|
|
|
|
$color && print color("reset");
|
2009-11-07 22:09:57 +00:00
|
|
|
exec("cd $profDir; $cmd");
|