added interactive feature for genimage

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.7@12022 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
linggao 2012-03-27 19:20:36 +00:00
parent 97f5def116
commit 8fc204c7b1
7 changed files with 459 additions and 300 deletions

View File

@ -38,6 +38,7 @@ my $tmplimit;
my $krpmver;
my $kerneldir;
my $mode;
my $interactive;
#-----------------------------------------------------------------------------
@ -50,18 +51,19 @@ sub print_usage
{
print "Usage:\n";
print " genimage\n\n";
print ' genimage -o <osver> [-a <arch>] -p <profile> -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] [-k <kernelver>] [-g <krpmver>] [-m statelite] [-l rootlimitsize] [-t tmplimitsize] [--permission <permission>]'."\n\n";
print ' genimage [-o <osver>] [-a <arch>] [-p <profile>] [-i <nodebootif>] [-n <nodenetdrivers>] [-r <otherifaces>] [-k <kernelver>] [-g <krpmver>] [-m statelite] [-l rootlimitsize] [-t tmplimitsize] [--permission <permission>] <imagename>'."\n\n";
print ' genimage -o <osver> [-a <arch>] -p <profile> -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] [-k <kernelver>] [-g <krpmver>] [-m statelite] [-l rootlimitsize] [-t tmplimitsize] [--permission <permission>] [--interactive]'."\n\n";
print ' genimage [-o <osver>] [-a <arch>] [-p <profile>] [-i <nodebootif>] [-n <nodenetdrivers>] [-r <otherifaces>] [-k <kernelver>] [-g <krpmver>] [-m statelite] [-l rootlimitsize] [-t tmplimitsize] [--permission <permission>] [--interactive] <imagename>'."\n\n";
print " --permission is used for statelite only\n";
print " -g is used for SLES only\n\n";
print " -m is used for urbuntu, debian and fedora12 only\n\n";
print "Examples:\n";
print " genimage\n";
print " genimage --interactive\n";
print " genimage -i eth0 -n tg3 -o sles11 -p compute\n";
print " genimage -i eth0 -r eth1,eth2 -n tg3,bnx2 -o centos5.1 -p compute\n";
print " genimage -i eth0 -r eth1,eth2 -n tg3,bnx2 -o centos5.1 -p compute --interactive\n";
print " genimage -i eth0 -n tg3,bnx2 -o sles11 -p compute\n";
print " genimage -i eth0 -n igb,e1000e,e1000,bnx2,tg3 -o centos5.4 -p nfsroot --permission 777\n";
print " genimage -i eth0 -n tg3 myimagename\n";
print " genimage -i eth0 -n tg3 --interactive myimagename\n";
print " genimage myimagename\n";
}
@ -78,7 +80,8 @@ if (!GetOptions(
'g=s' => \$krpmver,
'm=s' => \$mode,
'permission=s' => \$permission,
'kerneldir=s' => \$kerneldir,
'kerneldir=s' => \$kerneldir,
'interactive' => \$interactive,
'h|help' => \$help,
'v|version' => \$version,
)) {
@ -125,7 +128,7 @@ if ((!$imagename) && (!$profile) && (!$os) && (!$arch)) {
my $img = <stdin>;
chomp($img);
if($img eq ""){
$imagename = @images[0];
$imagename = $images[0];
last;
}
foreach(@images){
@ -189,7 +192,7 @@ if ((!$imagename) && (!$os)){
$os = <stdin>;
chomp($os);
if($os eq ""){
$os = @oses[0];
$os = $oses[0];
last;
}
foreach(@oses){
@ -377,11 +380,53 @@ if ($kerneldir) {
push @arg, "$kerneldir";
}
my $tempfile="/tmp/xcat_genimage.$$";
push @arg, "--tempfile"; #this is the file that contains the output
push @arg, "$tempfile";
if ($interactive) {
push @arg, "--interactive";
}
my $cmdref;
push (@{$cmdref->{arg}}, @arg);
$cmdref->{command}->[0] = "genimage";
xCAT::Client::submit_request($cmdref, \&xCAT::Client::handle_response);
exit $xCAT::Client::EXITCODE;
if (!$interactive) {
xCAT::Client::submit_request($cmdref, \&xCAT::Client::handle_response);
exit $xCAT::Client::EXITCODE;
} else {
#when in interactive mode, first call genimage.pm get info from DB,
xCAT::Client::submit_request($cmdref, \&xCAT::Client::handle_response);
#then call the specific genimage under /opt/xcat/share...
if (-f $tempfile) {
my $cmdname;
#read the command name
open(FILE1, "<$tempfile");
my @output = <FILE1>;
if (@output >0) {
$cmdname=$output[0];
} else {
close FILE1;
return 1;
}
close FILE1;
# run the specific genimage command
#print "cmdname=$cmdname\n";
system("$cmdname");
#then call genimage.pm to save the DB
my @arg1;
push @arg1, $tempfile;
my $request;
push (@{$request->{arg}}, @arg1);
$request->{command}->[0] = "saveimgdata";
xCAT::Client::submit_request($request, \&xCAT::Client::handle_response);
exit $xCAT::Client::EXITCODE;
} else {
exit 1;
}
}

View File

@ -7,42 +7,17 @@ use lib "$::XCATROOT/lib/perl";
use xCAT::Utils;
use xCAT::SvrUtils;
use xCAT::Table;
use Data::Dumper;
#use Data::Dumper;
use File::Path;
use Getopt::Long;
Getopt::Long::Configure("bundling");
Getopt::Long::Configure("pass_through");
my $prinic; #TODO be flexible on node primary nic
my $othernics; #TODO be flexible on node primary nic
my $netdriver;
my $arch;
my $profile;
my $osver;
my $rootlimit;
my $tmplimit;
my $installroot = "/install";
my $kerneldir;
my $kernelver = "";
my $imagename;
my $pkglist;
my $srcdir;
my $destdir;
my $srcdir_otherpkgs;
my $otherpkglist;
my $postinstall_filename;
my $rootimg_dir;
my $mode;
my $permission; #the permission works only for statelite mode currently
my $krpmver;
my $kerneldir;
my $mode;
sub handled_commands {
return {
genimage => "genimage",
saveimgdata => "genimage",
}
}
@ -50,14 +25,47 @@ sub process_request {
my $request = shift;
my $callback = shift;
my $doreq = shift;
my $installroot = xCAT::Utils->getInstallDir();
my $command = $request->{command}->[0];
@ARGV = @{$request->{arg}};
#saveimg
if ($command eq "saveimgdata") { #it is called by /opt/xcat/bin/genimage with interactive mode
my $tempfile1=$ARGV[0];
return save_image_data($callback, $doreq, $tempfile1);
}
#my $rsp;
#$rsp->{data}->[0]="genimage plugin gets called with ARGV=@ARGV" ;
#$callback->($rsp);
#now handle genimage
my $installroot = "/install";
$installroot = xCAT::Utils->getInstallDir();
my $prinic; #TODO be flexible on node primary nic
my $othernics; #TODO be flexible on node primary nic
my $netdriver;
my $arch;
my $profile;
my $osver;
my $rootlimit;
my $tmplimit;
my $kerneldir;
my $kernelver = "";
my $imagename;
my $pkglist;
my $srcdir;
my $destdir;
my $srcdir_otherpkgs;
my $otherpkglist;
my $postinstall_filename;
my $rootimg_dir;
my $mode;
my $permission; #the permission works only for statelite mode currently
my $krpmver;
my $interactive;
my $tempfile;
GetOptions(
'a=s' => \$arch,
'p=s' => \$profile,
@ -71,7 +79,9 @@ sub process_request {
'g=s' => \$krpmver,
'm=s' => \$mode,
'kerneldir=s' => \$kerneldir,
'permission=s' => \$permission
'permission=s' => \$permission,
'interactive' => \$interactive,
'tempfile=s' => \$tempfile,
);
my $osimagetab;
@ -109,7 +119,6 @@ sub process_request {
}
if (@ARGV > 0) {
$imagename=$ARGV[0];
if ($arch or $osver or $profile) {
@ -276,82 +285,146 @@ sub process_request {
if ($mode) { $cmd .= " -m $mode";}
if ($permission) { $cmd .= " --permission $permission"; }
if ($kerneldir) { $cmd .= " --kerneldir $kerneldir"; }
if ($interactive) { $cmd .= " --interactive" }
$cmd.= " --internal";
if ($srcdir) { $cmd .= " --srcdir $srcdir";}
if ($pkglist) { $cmd .= " --pkglist $pkglist";}
if ($srcdir_otherpkgs) { $cmd .= " --otherpkgdir $srcdir_otherpkgs"; }
if ($otherpkglist) { $cmd .= " --otherpkglist $otherpkglist"; }
if ($postinstall_filename) { $cmd .= " --postinstall $postinstall_filename"; }
if ($destdir) { $cmd .= " --rootimgdir $destdir"; }
if ($tempfile) { $cmd .= " --tempfile $tempfile"; }
if ($imagename) {
$cmd.= " $imagename";
}
# now run the specific genimage command
$callback->({info=>["$cmd"]});
$::CALLBACK=$callback;
#my $output = xCAT::Utils->runcmd("$cmd", 0, 1); # non-stream
my $output = xCAT::Utils->runcmd("$cmd", 0, 1, 1); # stream output
open(FILE, ">/tmp/genimageoutput");
foreach my $entry (@$output) {
print FILE $entry;
print FILE "\n";
if ($tempfile) {
#first print the command
open(FILE, ">$tempfile");
print FILE "$cmd\n\n";
#then print the update info for osimage and linuximage table
if (keys(%updates_os) > 0) {
print FILE "The output for table updates starts here\n";
print FILE "table::osimage\n";
print FILE "imagename::aaaaa_not_known_yet_aaaaa\n"; #special image name
my @a=%updates_os;
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
if (keys(%updates_linux) > 0) {
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::aaaaa_not_known_yet_aaaaa\n"; #special image name
my @a=%updates_linux;
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
close File;
} else {
$callback->({error=>["NO temp file provided to store the genimage command."]});
return;
}
close FILE;
#save the new settings to the osimage and linuximage tables
$cmd="cat /tmp/genimageoutput";
$output = xCAT::Utils->runcmd("$cmd", 0, 1);
if ($output && (@$output > 0)) {
my $i=0;
while ($i < @$output) {
if ( $output->[$i] =~ /The output for table updates starts here/) {
#print "----got here $i\n";
my $tn;
my %keyhash;
my %updates;
my $s1=$output->[$i +1];
my $s2=$output->[$i +2];
my $s3=$output->[$i +3];
if ($s1 =~ /^table::(.*)$/) {
$tn=$1;
}
if ($s2 =~ /^imagename::(.*)$/) {
$keyhash{'imagename'} = $1;
}
if ($tn eq 'osimage') {
%updates=%updates_os;
} elsif ($tn eq 'linuximage') {
%updates=%updates_linux;
}
my @a=split("::", $s3);
for (my $j=0; $j < @a; $j=$j+2) {
$updates{$a[$j]} = $a[$j+1];
}
splice(@$output, $i, 5);
if (($tn) && (keys(%keyhash) > 0) && (keys(%updates) > 0)) {
my $tab= xCAT::Table->new($tn, -create=>1);
if ($tab) {
$tab->setAttribs(\%keyhash, \%updates);
#print "table=$tn,%keyhash,%updates\n";
#print Dumper(%keyhash);
#print Dumper(%updates);
}
}
} else {
$i++;
}
}
# remove tmp file
#`rm /tmp/genimageoutput`;
#remove the database upgrade section
# runcmd_S displays the output
#$callback->({info=>$output});
if ($interactive) {
return; #back to the client, client will run
} else {
#my $output = xCAT::Utils->runcmd("$cmd", 0, 1); # non-stream
my $output = xCAT::Utils->runcmd("$cmd", 0, 1, 1); # stream output
#open(FILE, ">>$tempfile");
#foreach my $entry (@$output) {
# print FILE $entry;
# print FILE "\n";
#}
#close FILE;
#parse the output and save the image data to osimage and linuximage table
save_image_data($callback, $doreq, $tempfile);
}
}
sub save_image_data {
my $callback=shift;
my $doreq=shift;
my $filename=shift;
#updates_os and updates_linux are defined at the top of the given file with imagename::aaaaa_not_known_yet_aaaaa
my %updates_os=();
my %updates_linux=();
my $cmd="cat $filename";
my $output = xCAT::Utils->runcmd("$cmd", 0, 1);
if ($output && (@$output > 0)) {
my $i=0;
while ($i < @$output) {
if ( $output->[$i] =~ /The output for table updates starts here/) {
#print "----got here $i\n";
my $tn;
my $imgname;
my %keyhash;
my %updates;
my $s1=$output->[$i +1];
my $s2=$output->[$i +2];
my $s3=$output->[$i +3];
if ($s1 =~ /^table::(.*)$/) {
$tn=$1;
}
if ($s2 =~ /^imagename::(.*)$/) {
$imgname=$1;
$keyhash{'imagename'} = $imgname;
}
if ($tn eq 'osimage') {
%updates=%updates_os;
} elsif ($tn eq 'linuximage') {
%updates=%updates_linux;
}
my @a=split("::", $s3);
for (my $j=0; $j < @a; $j=$j+2) {
$updates{$a[$j]} = $a[$j+1];
}
splice(@$output, $i, 5);
if ($imgname eq "aaaaa_not_known_yet_aaaaa") {
#the file contains updates_os and updates_linux at the begining of the file. So read them out and save the to the variables, do not commit yet because the real image name will be provided later in the file.
if (($tn) && (keys(%updates) > 0)) {
if ($tn eq 'osimage') {
%updates_os=%updates;
} elsif ($tn eq 'linuximage') {
%updates_linux=%updates;
}
}
} else {
if (($tn) && (keys(%keyhash) > 0) && (keys(%updates) > 0)) {
my $tab= xCAT::Table->new($tn, -create=>1);
if ($tab) {
$tab->setAttribs(\%keyhash, \%updates);
#print "table=$tn,%keyhash,%updates\n";
#print "*** keyhash=" . Dumper(%keyhash);
#print "*** updates=" . Dumper(%updates);
}
}
}
} else { # if ( $output->[$i] =~ ....)
$i++;
}
} #if ($output && (@$output > 0))
# remove tmp file
#`rm /tmp/genimageoutput`;
#remove the database upgrade section
# runcmd_S displays the output
#$callback->({info=>$output});
}
}
1;

View File

@ -49,8 +49,9 @@ my $rootimg_dir;
my $rwfiles; # these files are used by statelite for tmpfs rw
my $mode;
my $permission; # the permission works only for statelite mode currently
my $internal;
my $tempfile;
my $kerneldir;
my $prompt;
sub xdie {
@ -72,13 +73,14 @@ GetOptions(
'm=s' => \$mode,
'permission=s' => \$permission,
'kerneldir=s' => \$kerneldir,
'internal' =>\$internal, #internal flag
'tempfile=s' =>\$tempfile, #internal flag
'pkglist=s' => \$pkglist, #internal flag
'srcdir=s' => \$srcdir, #internal flag
'otherpkgdir=s' => \$srcdir_otherpkgs, #internal flag
'otherpkglist=s' => \$otherpkglist, #internal flag
'postinstall=s' => \$postinstall_filename, #internal flag
'rootimgdir=s' => \$destdir, #internal flag
'interactive' =>\$prompt, #internal flag
);
if (@ARGV > 0) {
@ -92,7 +94,7 @@ if ($mode eq "statelite") {
if (!$permission) {
$permission = "755";
}
$updates{'permission'} = $permission if ( $internal );
$updates{'permission'} = $permission if ( $tempfile );
}
if (!$arch) {
@ -106,18 +108,18 @@ if (!$arch) {
if (!$srcdir) {
$srcdir="$installroot/$osver/$arch";
}
$updates{'pkgdir'} = $srcdir if ($internal);
$updates{'pkgdir'} = $srcdir if ($tempfile);
if (!$srcdir_otherpkgs) {
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch";
}
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($internal);
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($tempfile);
if (!$destdir)
{
$destdir="$installroot/netboot/$osver/$arch/$profile";
}
$updates{'rootimgdir'} = $destdir if ($internal);
$updates{'rootimgdir'} = $destdir if ($tempfile);
$rootimg_dir="$destdir/rootimg";
@ -128,7 +130,7 @@ unless ($osver and $profile and $netdriver and $prinic) {
}
if ($netdriver) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($internal) ) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($tempfile) ) {
$updates{'netdrivers'} = $netdriver;
}
}
@ -180,12 +182,16 @@ unless ($onlyinitrd) {
close($aptconfig);
mkpath "$rootimg_dir/etc";
my $non_interactive;
if (!$prompt) { $non_interactive="-y"; }
my $fd;
open($fd,">>","$rootimg_dir/etc/fstab");
print $fd "#Dummy fstab for rpm postscripts to see\n";
close($fd);
my @line=split(" ",`ls -lh $installroot/$osver/$arch/dists/ | grep dr`);
#print "$line\n";
#print "$index\n";
@ -208,7 +214,7 @@ unless ($onlyinitrd) {
}
if ($pkglist) {
$updates{'pkglist'} = $pkglist if ($internal);
$updates{'pkglist'} = $pkglist if ($tempfile);
} else {
print "Unable to find package list for $profile!";
exit 1;
@ -240,7 +246,7 @@ unless ($onlyinitrd) {
}
my %extra_hash=();
if ($otherpkglist) {
$updates{'otherpkglist'} = $otherpkglist if ($internal);
$updates{'otherpkglist'} = $otherpkglist if ($tempfile);
%extra_hash=get_package_names($otherpkglist);
}
my %extrapkgnames;
@ -259,7 +265,7 @@ unless ($onlyinitrd) {
}
close($yumconfig);
$index--;
$yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
$yumcmd = "yum $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
foreach (0..$repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
}
@ -343,7 +349,7 @@ unless ($kernelver) {
$kernelver=$basekernelver;
}
chomp($kernelver);
#$updates{'kernelver'} = $kernelver if ($internal);
#$updates{'kernelver'} = $kernelver if ($tempfile);
open($moddeps,"<","$rootimg_dir/lib/modules/$kernelver/modules.dep");
my @moddeps = <$moddeps>;
@ -380,7 +386,7 @@ if (!$imagename) {
if (($postinstall_filename) && (-x $postinstall_filename)) {
$updates{'postinstall'} = $postinstall_filename if ($internal);
$updates{'postinstall'} = $postinstall_filename if ($tempfile);
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
if($rc) {
@ -418,15 +424,16 @@ if($mode eq "statelite"){
# now, update the linuximage and osimage tables
# TODO: do statelite and stateless share the same attributes?
#BEGIN: PLEASE DO NOT CHANGE THE FOLLOWING CODE, genimage PLUGIN NEEDS TO PARSE THR OUTPUT
if ($internal) {
if ($tempfile) {
open(FILE, ">>$tempfile");
if ($imagename) {
if (keys(%updates) > 0) {
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$imagename\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$imagename\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
} else {
$updates_os{'profile'} = $profile;
@ -441,20 +448,21 @@ if ($internal) {
$updates_os{'osdistro'} = 'sles'; # not used currently
$updates_os{'osarch'} = $arch;
# update the imagename for stateless
print "The output for table updates starts here\n";
print "table::osimage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::osimage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates_os;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
}
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
close FILE;
}
#END

View File

@ -53,8 +53,9 @@ my $postinstall_filename;
my $rootimg_dir;
my $mode;
my $permission; # the permission works only for statelite mode currently
my $internal;
my $tempfile;
my $kerneldir;
my $prompt;
sub xdie {
@ -76,13 +77,14 @@ GetOptions(
'm=s' => \$mode,
'permission=s' => \$permission,
'kerneldir=s' => \$kerneldir,
'internal' =>\$internal, #internal flag
'tempfile=s' =>\$tempfile, #internal flag
'pkglist=s' => \$pkglist, #internal flag
'srcdir=s' => \$srcdir, #internal flag
'otherpkgdir=s' => \$srcdir_otherpkgs, #internal flag
'otherpkglist=s' => \$otherpkglist, #internal flag
'postinstall=s' => \$postinstall_filename, #internal flag
'rootimgdir=s' => \$destdir, #internal flag
'interactive' =>\$prompt, #internal flag
);
if (@ARGV > 0) {
@ -96,7 +98,7 @@ if ($mode eq "statelite") {
if (!$permission) {
$permission = "755";
}
$updates{'permission'} = $permission if ( $internal );
$updates{'permission'} = $permission if ( $tempfile );
}
if (!$arch) {
@ -110,18 +112,18 @@ if (!$arch) {
if (!$srcdir) {
$srcdir="$installroot/$osver/$arch";
}
$updates{'pkgdir'} = $srcdir if ($internal);
$updates{'pkgdir'} = $srcdir if ($tempfile);
if (!$srcdir_otherpkgs) {
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch";
}
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($internal);
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($tempfile);
if (!$destdir)
{
$destdir="$installroot/netboot/$osver/$arch/$profile";
}
$updates{'rootimgdir'} = $destdir if ($internal);
$updates{'rootimgdir'} = $destdir if ($tempfile);
$rootimg_dir="$destdir/rootimg";
@ -132,7 +134,7 @@ unless ($osver and $profile and $netdriver and $prinic) {
}
if ($netdriver) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($internal) ) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($tempfile) ) {
$updates{'netdrivers'} = $netdriver;
}
}
@ -182,7 +184,11 @@ unless ($onlyinitrd) {
open($fd,">>","$rootimg_dir/etc/fstab");
print $fd "#Dummy fstab for rpm postscripts to see\n";
close($fd);
my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
my $non_interactive;
if (!$prompt) { $non_interactive="-y"; }
my $yumcmd = "yum $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
foreach (0..$repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
}
@ -198,7 +204,7 @@ unless ($onlyinitrd) {
}
if ($pkglist) {
$updates{'pkglist'} = $pkglist if ($internal);
$updates{'pkglist'} = $pkglist if ($tempfile);
} else {
print "Unable to find package list for $profile!";
exit 1;
@ -230,7 +236,7 @@ unless ($onlyinitrd) {
}
my %extra_hash=();
if ($otherpkglist) {
$updates{'otherpkglist'} = $otherpkglist if ($internal);
$updates{'otherpkglist'} = $otherpkglist if ($tempfile);
%extra_hash=imgutils::get_package_names($otherpkglist);
}
my %extrapkgnames;
@ -249,7 +255,7 @@ unless ($onlyinitrd) {
}
close($yumconfig);
$index--;
$yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
$yumcmd = "yum $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
foreach (0..$repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
}
@ -333,7 +339,7 @@ unless ($kernelver) {
$kernelver=$basekernelver;
}
chomp($kernelver);
#$updates{'kernelver'} = $kernelver if ($internal);
#$updates{'kernelver'} = $kernelver if ($tempfile);
open($moddeps,"<","$rootimg_dir/lib/modules/$kernelver/modules.dep");
@ -371,7 +377,7 @@ if (!$imagename) {
if (($postinstall_filename) && (-x $postinstall_filename)) {
$updates{'postinstall'} = $postinstall_filename if ($internal);
$updates{'postinstall'} = $postinstall_filename if ($tempfile);
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
if($rc) {
@ -409,15 +415,16 @@ if($mode eq "statelite"){
# now, update the linuximage and osimage tables
# TODO: do statelite and stateless share the same attributes?
#BEGIN: PLEASE DO NOT CHANGE THE FOLLOWING CODE, genimage PLUGIN NEEDS TO PARSE THR OUTPUT
if ($internal) {
if ($tempfile) {
open(FILE, ">>$tempfile");
if ($imagename) {
if (keys(%updates) > 0) {
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$imagename\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$imagename\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
} else {
$updates_os{'profile'} = $profile;
@ -432,20 +439,21 @@ if ($internal) {
$updates_os{'osdistro'} = 'sles'; # not used currently
$updates_os{'osarch'} = $arch;
# update the imagename for stateless
print "The output for table updates starts here\n";
print "table::osimage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::osimage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates_os;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
}
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
close FILE;
}
#END

View File

@ -56,7 +56,8 @@ my $otherpkglist;
my $postinstall_filename;
my $rootimg_dir;
my $permission; # the permission works only for statelite mode currently
my $internal;
my $tempfile;
my $prompt;
sub xdie {
@ -77,13 +78,14 @@ GetOptions(
'k=s' => \$kernelver,
'permission=s' => \$permission,
'kerneldir=s' => \$kerneldir,
'internal' =>\$internal, #internal flag
'tempfile=s' =>\$tempfile, #internal flag
'pkglist=s' => \$pkglist, #internal flag
'srcdir=s' => \$srcdir, #internal flag
'otherpkgdir=s' => \$srcdir_otherpkgs, #internal flag
'otherpkglist=s' => \$otherpkglist, #internal flag
'postinstall=s' => \$postinstall_filename, #internal flag
'rootimgdir=s' => \$destdir, #internal flag
'interactive' =>\$prompt, #internal flag
);
if (@ARGV > 0) {
@ -95,7 +97,7 @@ my %updates = (); # the hash for updating linuximage table
$permission = "755" unless ($permission);
$updates{'permission'} = $permission if ( $internal );
$updates{'permission'} = $permission if ( $tempfile );
unless ($arch) {
$arch = `uname -m`;
@ -104,18 +106,18 @@ unless ($arch) {
}
$srcdir="$installroot/$osver/$arch" unless ($srcdir);
$updates{'pkgdir'} = $srcdir if ($internal);
$updates{'pkgdir'} = $srcdir if ($tempfile);
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch" unless ($srcdir_otherpkgs);
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($internal);
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($tempfile);
$destdir="$installroot/netboot/$osver/$arch/$profile" unless ($destdir);
$updates{'rootimgdir'} = $destdir if ($internal);
$updates{'rootimgdir'} = $destdir if ($tempfile);
$rootimg_dir="$destdir/rootimg";
$kerneldir = "$installroot/kernels" unless ($kerneldir); # the default directory for 3rd-party kernel is "$installroot/kernels";
#$updates{'kerneldir'} = $kerneldir if ($internal);
#$updates{'kerneldir'} = $kerneldir if ($tempfile);
# Get the subchannels of the given interface
my $subchn;
@ -150,7 +152,7 @@ unless ($osver and $profile) {
my @ndrivers;
if ($netdriver) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($internal) ) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($tempfile) ) {
$updates{'netdrivers'} = $netdriver;
}
} else {
@ -203,11 +205,16 @@ unless ($onlyinitrd) {
mkpath "$rootimg_dir/etc";
my $fd;
open($fd,">>","$rootimg_dir/etc/fstab");
print $fd "#Dummy fstab for rpm postscripts to see\n";
close($fd);
my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
my $non_interactive;
if (!$prompt) { $non_interactive="-y"; }
my $yumcmd = "yum $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
foreach (0..$repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
}
@ -222,7 +229,7 @@ unless ($onlyinitrd) {
}
if ($pkglist) {
$updates{'pkglist'} = $pkglist if ($internal);
$updates{'pkglist'} = $pkglist if ($tempfile);
} else {
print "Unable to find package list for $profile!";
exit 1;
@ -289,7 +296,7 @@ unless ($onlyinitrd) {
}
my %extra_hash=();
if ($otherpkglist) {
$updates{'otherpkglist'} = $otherpkglist if ($internal);
$updates{'otherpkglist'} = $otherpkglist if ($tempfile);
%extra_hash = imgutils::get_package_names($otherpkglist);
}
my %extrapkgnames;
@ -308,7 +315,7 @@ unless ($onlyinitrd) {
}
close($yumconfig);
$index--;
$yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
$yumcmd = "yum $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
foreach (0..$repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
}
@ -339,22 +346,23 @@ unless ($onlyinitrd) {
# append extra pkg names to yum command
if ($extrapkgnames{$pass}) {
$yumcmd .= " $extrapkgnames{$pass} ";
$yumcmd =~ s/ $/\n/;
# debug
#print "yumcmd=$yumcmd\n";
#my $repo=`cat /tmp/genimage.$$.yum.conf`;
#print "repo=$repo";
print "$envlist $yumcmd\n";
my $rc = system("$envlist $yumcmd");
if ($rc) {
print "yum invocation failed\n";
exit 1;
}
$yumcmd =~ s/ $/\n/;
# debug
#print "yumcmd=$yumcmd\n";
#my $repo=`cat /tmp/genimage.$$.yum.conf`;
#print "repo=$repo";
print "$envlist $yumcmd\n";
my $rc = system("$envlist $yumcmd");
if ($rc) {
print "yum invocation failed\n";
exit 1;
}
} else {
print "No Packages marked for install\n";
print "No Packages marked for install\n";
}
# remove the packages that are specified in the otherpkgs.list files with leading '--'
if (exists ($extra_hash{$pass}{'POST_REMOVE'})) {
@ -399,7 +407,7 @@ $basekernelver = `uname -r` unless ($basekernelver);
$kernelver = $basekernelver unless ($kernelver);
chomp($kernelver);
#$updates{'kernelver'} = $kernelver if ($internal);
#$updates{'kernelver'} = $kernelver if ($tempfile);
# copy the kernel to $destdir
if ( -e "$rootimg_dir/boot/vmlinux-$kernelver") {
@ -473,7 +481,7 @@ unless ($imagename) {
if (($postinstall_filename) && (-x $postinstall_filename)) {
$updates{'postinstall'} = $postinstall_filename if ($internal);
$updates{'postinstall'} = $postinstall_filename if ($tempfile);
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
if($rc) {
@ -486,15 +494,16 @@ if (($postinstall_filename) && (-x $postinstall_filename)) {
# now, update the linuximage and osimage tables
# TODO: do statelite and stateless share the same attributes?
#BEGIN: PLEASE DO NOT CHANGE THE FOLLOWING CODE, genimage PLUGIN NEEDS TO PARSE THR OUTPUT
if ($internal) {
if ($tempfile) {
open(FILE, ">>$tempfile");
if ($imagename) {
if (keys(%updates) > 0) {
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$imagename\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$imagename\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
} else {
$updates_os{'profile'} = $profile;
@ -504,36 +513,37 @@ if ($internal) {
$updates_os{'osvers'} = $osver;
$updates_os{'osarch'} = $arch;
# update the imagename for stateless
print "The output for table updates starts here\n";
print "table::osimage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::osimage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates_os;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
# update the imagename for statelite
$updates_os{'provmethod'} = 'statelite';
print "The output for table updates starts here\n";
print "table::osimage\n";
print "imagename::$osver-$arch-statelite-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::osimage\n";
print FILE "imagename::$osver-$arch-statelite-$profile\n";
my @a=%updates_os;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$osver-$arch-statelite-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$osver-$arch-statelite-$profile\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
close FILE;
}
#END

View File

@ -56,7 +56,9 @@ my $rootimg_dir;
my $mode;
my $permission; #the permission works only for statelite mode currently
my $krpmver;
my $internal;
my $tempfile;
my $prompt;
sub xdie {
system("rm -rf /tmp/xcatinitrd.$$");
@ -92,13 +94,14 @@ GetOptions(
'g=s' => \$krpmver,
'permission=s' => \$permission,
'kerneldir=s' => \$kerneldir,
'internal' =>\$internal, #internal flag
'tempfile=s' =>\$tempfile, #internal flag
'pkglist=s' => \$pkglist, #internal flag
'srcdir=s' => \$srcdir, #internal flag
'otherpkgdir=s' => \$srcdir_otherpkgs, #internal flag
'otherpkglist=s' => \$otherpkglist, #internal flag
'postinstall=s' => \$postinstall_filename, #internal flag
'rootimgdir=s' => \$destdir, #internal flag
'interactive' =>\$prompt, #internal flag
);
if (@ARGV > 0) {
@ -111,7 +114,7 @@ my %updates = (); # the hash for updating linuximage table
$permission = "755" unless ($permission);
$updates{'permission'} = $permission if ($internal);
$updates{'permission'} = $permission if ($tempfile);
unless ($arch) {
$arch = `uname -m`;
@ -120,14 +123,14 @@ unless ($arch) {
}
$srcdir="$installroot/$osver/$arch" unless ($srcdir);
$updates{'pkgdir'} = $srcdir if ($internal);
$updates{'pkgdir'} = $srcdir if ($tempfile);
$srcdir = $srcdir . "/1";
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch" unless ($srcdir_otherpkgs);
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($internal);
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($tempfile);
$destdir="$installroot/netboot/$osver/$arch/$profile" unless ($destdir);
$updates{'rootimgdir'} = $destdir if ($internal);
$updates{'rootimgdir'} = $destdir if ($tempfile);
$rootimg_dir="$destdir/rootimg";
@ -136,7 +139,7 @@ if ($kernelver && (!$krpmver)) {
exit 1;
}
$kerneldir = "$installroot/kernels" unless ($kerneldir); # the default directory for 3rd-party kernel is "$installroot/kernels";
#$updates{'kerneldir'} = $kerneldir if ($internal);
#$updates{'kerneldir'} = $kerneldir if ($tempfile);
unless ($osver and $profile) {
usage();
@ -145,7 +148,7 @@ unless ($osver and $profile) {
my @ndrivers;
if ($netdriver) {
if ( ($updates{'netdrivers'} ne $netdriver) and $internal ) {
if ( ($updates{'netdrivers'} ne $netdriver) and $tempfile ) {
$updates{'netdrivers'} = $netdriver;
}
} else {
@ -195,7 +198,7 @@ unless ($onlyinitrd) {
unless ($imagename) {
$otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "otherpkgs.pkglist");
unless ($otherpkglist) { $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "otherpkgs.pkglist"); }
$updates{'otherpkglist'} = $otherpkglist if ($internal and $otherpkglist);
$updates{'otherpkglist'} = $otherpkglist if ($tempfile and $otherpkglist);
}
my %extra_hash=();
%extra_hash=imgutils::get_package_names($otherpkglist) if ($otherpkglist);
@ -230,22 +233,25 @@ unless ($onlyinitrd) {
open($fd,">>","$rootimg_dir/etc/fstab"); # TODO: is it necessary?
print $fd "#Dummy fstab for rpm postscripts to see\n";
close($fd);
my $non_interactive;
if (!$prompt) { $non_interactive="--non-interactive --no-gpg-checks"; }
if($osver_host == 11) {#zypper in SLES11 is different
if(-e "$rootimg_dir/etc/zypp/repos.d/$osver.repo") {
system("rm -rf $rootimg_dir/etc/zypp/repos.d/$osver.repo");
}
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks ar file:$srcdir $osver");
system("zypper -R $rootimg_dir $non_interactive ar file:$srcdir $osver");
if(-e "$rootimg_dir/etc/zypp/repos.d/${osver}sdk.repo") {
system("rm -rf $rootimg_dir/etc/zypp/repos.d/${osver}sdk.repo");
}
my $srcdir_sdk = "$installroot/$osver/$arch/sdk1";
if ( -e "$srcdir_sdk") {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks ar file:$srcdir_sdk ${osver}sdk");
system("zypper -R $rootimg_dir $non_interactive ar file:$srcdir_sdk ${osver}sdk");
}
}else {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks sa file:$srcdir");
system("zypper -R $rootimg_dir $non_interactive sa file:$srcdir");
}
# Add the rep for kernel packages
@ -258,22 +264,22 @@ unless ($onlyinitrd) {
if (-e "$rootimg_dir/etc/zypp/repos.d/$kernelver.repo") {
system("rm -rf $rootimg_dir/etc/zypp/repos.d/$kernelver.repo");
}
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks ar file:$kerneldir $kernelver");
system("zypper -R $rootimg_dir $non_interactive ar file:$kerneldir $kernelver");
} else {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks sa file:$kerneldir");
system("zypper -R $rootimg_dir $non_interactive sa file:$kerneldir");
}
}
#remove the old repository for extra packages
if ($osver_host == 11) {
my $result=`zypper -R $rootimg_dir --non-interactive --no-gpg-checks lr |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`;
my $result=`zypper -R $rootimg_dir $non_interactive lr |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`;
if ($result =~ /\S/) {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks rr $result");
system("zypper -R $rootimg_dir $non_interactive rr $result");
}
} else {
my $result=`zypper -R $rootimg_dir --non-interactive --no-gpg-checks sl |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`;
my $result=`zypper -R $rootimg_dir $non_interactive sl |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`;
if ($result =~ /\S/) {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks sd $result");
system("zypper -R $rootimg_dir $non_interactive sd $result");
}
}
@ -292,15 +298,15 @@ unless ($onlyinitrd) {
my $whole_path="$srcdir_otherpkgs/$_";
if (-r "$srcdir_otherpkgs/$_/repodata/repomd.xml") {
if($osver_host == 11) {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks ar file:$srcdir_otherpkgs/$_ otherpkg$index");
system("zypper -R $rootimg_dir $non_interactive ar file:$srcdir_otherpkgs/$_ otherpkg$index");
}else {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks sa file:$srcdir_otherpkgs/$_");
system("zypper -R $rootimg_dir $non_interactive sa file:$srcdir_otherpkgs/$_");
}
} else {
if($osver_host == 11) {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks ar -t Plaindir file:$srcdir_otherpkgs/$_ otherpkg$index");
system("zypper -R $rootimg_dir $non_interactive ar -t Plaindir file:$srcdir_otherpkgs/$_ otherpkg$index");
}else {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks sa -t Plaindir file:$srcdir_otherpkgs/$_");
system("zypper -R $rootimg_dir $non_interactive sa -t Plaindir file:$srcdir_otherpkgs/$_");
}
}
$index++;
@ -327,24 +333,24 @@ unless ($onlyinitrd) {
next if /^\s*#/;
my ($repotype,$repourl,$repoalias) = split m/\|/;
if($osver_host == 11) {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks ar $repourl $repoalias");
system("zypper -R $rootimg_dir $non_interactive ar $repourl $repoalias");
}else {
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks sa $repourl $repoalias");
system("zypper -R $rootimg_dir $non_interactive sa $repourl $repoalias");
}
}
}
# Refresh the zypper cache in case there is still old data out there
system("zypper -R $rootimg_dir --non-interactive --no-gpg-checks refresh");
system("zypper -R $rootimg_dir $non_interactive refresh");
#my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir --disablerepo=* ";
#$yumcmd .= "install ";
#mkpath("$rootimg_dir/var/lib/yum");
my $yumcmd;
if($osver =~ /sles11/ && $osver_host == 11) {
$yumcmd = "zypper -R $rootimg_dir --non-interactive --no-gpg-checks install -l "; #add -l for SLES11
$yumcmd = "zypper -R $rootimg_dir $non_interactive install -l "; #add -l for SLES11
}else {
$yumcmd = "zypper -R $rootimg_dir --non-interactive --no-gpg-checks install ";
$yumcmd = "zypper -R $rootimg_dir $non_interactive install ";
}
#install packages from pkglist file
@ -355,7 +361,7 @@ unless ($onlyinitrd) {
}
if ($pkglist) {
$updates{'pkglist'} = $pkglist if ($internal);
$updates{'pkglist'} = $pkglist if ($tempfile);
} else {
print "Unable to find package list for $profile!";
exit 1;
@ -445,7 +451,7 @@ unless ($onlyinitrd) {
$envlist = join(' ', @{$extra_hash{$pass}{ENVLIST}});
}
my $yumcmd_remove= "zypper -R $rootimg_dir --non-interactive --no-gpg-checks remove ";
my $yumcmd_remove= "zypper -R $rootimg_dir $non_interactive remove ";
if (exists ($extra_hash{$pass}{'PRE_REMOVE'})) {
my $pa=$extra_hash{$pass}{'PRE_REMOVE'};
my $rm_packges= join(' ', @$pa);
@ -482,9 +488,9 @@ unless ($onlyinitrd) {
# needed when running genimage again after updating software in repositories
my $yumcmd_update;
if ($osver_host == 11) {
$yumcmd_update = "zypper -R $rootimg_dir --non-interactive --no-gpg-checks update ";
$yumcmd_update = "zypper -R $rootimg_dir $non_interactive update ";
} else {
$yumcmd_update = "zypper -R $rootimg_dir --non-interactive --no-gpg-checks update ";
$yumcmd_update = "zypper -R $rootimg_dir $non_interactive update ";
}
$rc = system("$yumcmd_update");
# ignore any return code
@ -537,7 +543,7 @@ unless ($basekernelver) {
$kernelver = $basekernelver unless ($kernelver);
chomp $kernelver;
#$updates{kernelver} = $kernelver if ($internal);
#$updates{kernelver} = $kernelver if ($tempfile);
# copy the kernel to $destdir
if ( -e "$rootimg_dir/boot/vmlinux-$kernelver") {
@ -561,7 +567,7 @@ unless ($imagename) {
if (($postinstall_filename) && (-x $postinstall_filename)) {
#print "postinstall_filename=$postinstall_filename\n";
$updates{'postinstall'} = $postinstall_filename if ($internal);
$updates{'postinstall'} = $postinstall_filename if ($tempfile);
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
if($rc) {
@ -575,15 +581,16 @@ if (($postinstall_filename) && (-x $postinstall_filename)) {
# now, update the linuximage and osimage tables
# TODO: do statelite and stateless share the same attributes? currently, I will update both of them
#BEGIN: PLEASE DO NOT CHANGE THE FOLLOWING CODE, genimage PLUGIN NEEDS TO PARSE THR OUTPUT
if ($internal) {
if ($tempfile) {
open(FILE, ">>$tempfile");
if ($imagename) {
if (keys(%updates) > 0) {
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$imagename\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$imagename\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
} else {
$updates_os{'profile'} = $profile;
@ -594,36 +601,37 @@ if ($internal) {
$updates_os{'osdistro'} = 'sles'; # not used currently
$updates_os{'osarch'} = $arch;
# update the imagename for stateless
print "The output for table updates starts here\n";
print "table::osimage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::osimage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates_os;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
# update the imagename for statelite
$updates_os{'provmethod'} = 'statelite';
print "The output for table updates starts here\n";
print "table::osimage\n";
print "imagename::$osver-$arch-statelite-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::osimage\n";
print FILE "imagename::$osver-$arch-statelite-$profile\n";
my @a=%updates_os;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$osver-$arch-statelite-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$osver-$arch-statelite-$profile\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
close FILE;
}
#END

View File

@ -49,8 +49,9 @@ my $rootimg_dir;
my $rwfiles; # these files are used by statelite for tmpfs rw
my $mode;
my $permission; # the permission works only for statelite mode currently
my $internal;
my $tempfile;
my $kerneldir;
my $prompt;
sub xdie {
@ -72,13 +73,14 @@ GetOptions(
'm=s' => \$mode,
'permission=s' => \$permission,
'kerneldir=s' => \$kerneldir,
'internal' =>\$internal, #internal flag
'tempfile=s' =>\$tempfile, #internal flag
'pkglist=s' => \$pkglist, #internal flag
'srcdir=s' => \$srcdir, #internal flag
'otherpkgdir=s' => \$srcdir_otherpkgs, #internal flag
'otherpkglist=s' => \$otherpkglist, #internal flag
'postinstall=s' => \$postinstall_filename, #internal flag
'rootimgdir=s' => \$destdir, #internal flag
'interactive' =>\$prompt, #internal flag
);
@ -94,7 +96,7 @@ if ($mode eq "statelite") {
if (!$permission) {
$permission = "755";
}
$updates{'permission'} = $permission if ( $internal );
$updates{'permission'} = $permission if ( $tempfile );
}
if (!$arch) {
@ -108,18 +110,18 @@ if (!$arch) {
if (!$srcdir) {
$srcdir="$installroot/$osver/$arch";
}
$updates{'pkgdir'} = $srcdir if ($internal);
$updates{'pkgdir'} = $srcdir if ($tempfile);
if (!$srcdir_otherpkgs) {
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch";
}
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($internal);
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($tempfile);
if (!$destdir)
{
$destdir="$installroot/netboot/$osver/$arch/$profile";
}
$updates{'rootimgdir'} = $destdir if ($internal);
$updates{'rootimgdir'} = $destdir if ($tempfile);
$rootimg_dir="$destdir/rootimg";
@ -130,7 +132,7 @@ unless ($osver and $profile and $netdriver and $prinic) {
}
if ($netdriver) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($internal) ) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($tempfile) ) {
$updates{'netdrivers'} = $netdriver;
}
}
@ -188,6 +190,9 @@ unless ($onlyinitrd) {
print $fd "#Dummy fstab for rpm postscripts to see\n";
close($fd);
my $non_interactive;
if (!$prompt) { $non_interactive="-y"; }
my @line=split(" ",`ls -lh $installroot/$osver/$arch/dists/ | grep dr`);
#print "$line\n";
#print "$index\n";
@ -210,7 +215,7 @@ unless ($onlyinitrd) {
}
if ($pkglist) {
$updates{'pkglist'} = $pkglist if ($internal);
$updates{'pkglist'} = $pkglist if ($tempfile);
} else {
print "Unable to find package list for $profile!";
exit 1;
@ -242,7 +247,7 @@ unless ($onlyinitrd) {
}
my %extra_hash=();
if ($otherpkglist) {
$updates{'otherpkglist'} = $otherpkglist if ($internal);
$updates{'otherpkglist'} = $otherpkglist if ($tempfile);
%extra_hash=get_package_names($otherpkglist);
}
my %extrapkgnames;
@ -261,7 +266,7 @@ unless ($onlyinitrd) {
}
close($yumconfig);
$index--;
$yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
$yumcmd = "yum $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
foreach (0..$repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
}
@ -345,7 +350,7 @@ unless ($kernelver) {
$kernelver=$basekernelver;
}
chomp($kernelver);
#$updates{'kernelver'} = $kernelver if ($internal);
#$updates{'kernelver'} = $kernelver if ($tempfile);
open($moddeps,"<","$rootimg_dir/lib/modules/$kernelver/modules.dep");
my @moddeps = <$moddeps>;
@ -382,7 +387,7 @@ if (!$imagename) {
if (($postinstall_filename) && (-x $postinstall_filename)) {
$updates{'postinstall'} = $postinstall_filename if ($internal);
$updates{'postinstall'} = $postinstall_filename if ($tempfile);
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
if($rc) {
@ -420,15 +425,16 @@ if($mode eq "statelite"){
# now, update the linuximage and osimage tables
# TODO: do statelite and stateless share the same attributes?
#BEGIN: PLEASE DO NOT CHANGE THE FOLLOWING CODE, genimage PLUGIN NEEDS TO PARSE THR OUTPUT
if ($internal) {
if ($tempfile) {
open(FILE, ">>$tempfile");
if ($imagename) {
if (keys(%updates) > 0) {
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$imagename\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$imagename\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
} else {
$updates_os{'profile'} = $profile;
@ -443,20 +449,21 @@ if ($internal) {
$updates_os{'osdistro'} = 'sles'; # not used currently
$updates_os{'osarch'} = $arch;
# update the imagename for stateless
print "The output for table updates starts here\n";
print "table::osimage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::osimage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates_os;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
print "The output for table updates starts here\n";
print "table::linuximage\n";
print "imagename::$osver-$arch-netboot-$profile\n";
print FILE "The output for table updates starts here\n";
print FILE "table::linuximage\n";
print FILE "imagename::$osver-$arch-netboot-$profile\n";
my @a=%updates;
print join('::',@a) . "\n";
print "The output for table updates ends here\n";
}
print FILE join('::',@a) . "\n";
print FILE "The output for table updates ends here\n";
}
close FILE;
}
#END