From 44c01cb949faf5ddd30630fc075a015121675c1c Mon Sep 17 00:00:00 2001 From: angli-xcat Date: Wed, 6 Jul 2011 09:15:36 +0000 Subject: [PATCH] This is to enable group install for .pkglist file =========================================================== Target Dist: SLES 11, RHELS6, both for stateless Aim: To Support "group" format of .pkglist file e.g.: "@ X Window system" (for RHELS6) "@ file_server" (for SLES11) user impact: N/A By-effect: N/A Limitations: N/A Note: Note there's a space after "@" ============================================================ git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10023 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/share/xcat/netboot/rh/genimage | 84 ++++++++++---------- xCAT-server/share/xcat/netboot/sles/genimage | 45 ++++++++--- 2 files changed, 79 insertions(+), 50 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 150eed5b6..fef18eda4 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -330,48 +330,52 @@ unless ($onlyinitrd) { my %pkg_hash=imgutils::get_package_names($pkglist); my $index=1; my $pass; - foreach $pass (sort (keys(%pkg_hash))) { - my $pkgnames = ""; - foreach (keys(%{$pkg_hash{$pass}})) { - if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;} - my $pa=$pkg_hash{$pass}{$_}; - my @npa = (); - # replace the kernel package with the name has the specific version - foreach my $p (@$pa) { - if ($p =~ /^kernel$/ && $kernelver) { - my $kernelname = "kernel-".$kernelver; - my $searchkern = $yumcmd . " list $kernelname -q"; - my @kernpkgs = `$searchkern`; - my $found = 0; - foreach my $k (@kernpkgs) { - if ($k =~ /\s*kernel[^\s]*\s+([\w\.-]+)/) { - my $version = $1; - my $relversion = $kernelver; - $relversion =~ s/\.[^\.]+$//; - if ($version == $relversion) { - $found++; - } - } - } - if ($found eq 0) { - print "Cannot find the kernel with version $kernelver.\n"; - exit 1; - } - push @npa, $kernelname; - } else { - push @npa, $p; + foreach $pass (sort (keys(%pkg_hash))) { + my $pkgnames = ""; + foreach (keys(%{$pkg_hash{$pass}})) { + if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;} + my $pa=$pkg_hash{$pass}{$_}; + my @npa = (); + # replace the kernel package with the name has the specific version + foreach my $p (@$pa) { + if ($p =~ /^kernel$/ && $kernelver) { + my $kernelname = "kernel-".$kernelver; + my $searchkern = $yumcmd . " list $kernelname -q"; + my @kernpkgs = `$searchkern`; + my $found = 0; + foreach my $k (@kernpkgs) { + if ($k =~ /\s*kernel[^\s]*\s+([\w\.-]+)/) { + my $version = $1; + my $relversion = $kernelver; + $relversion =~ s/\.[^\.]+$//; + if ($version == $relversion) { + $found++; + } + } + } + if ($found eq 0) { + print "Cannot find the kernel with version $kernelver.\n"; + exit 1; + } + push @npa, $kernelname; + } + elsif ($p =~ /^@/) { + push @npa, "\"$p\""; + } + else { + push @npa, $p; + } } - } - $pkgnames .= " " . join(' ', @npa); - } + $pkgnames .= " " . join(' ', @npa); + } - print "$yumcmd install $pkgnames\n"; - my $rc = system("$yumcmd install $pkgnames"); - if ($rc) { - print "yum invocation failed\n"; - exit 1; - } - } + print "$yumcmd install $pkgnames\n"; + my $rc = system("$yumcmd install $pkgnames"); + if ($rc) { + print "yum invocation failed\n"; + exit 1; + } + } #Now let's handle extra packages unless ($imagename) { diff --git a/xCAT-server/share/xcat/netboot/sles/genimage b/xCAT-server/share/xcat/netboot/sles/genimage index 376fadd69..b9cfd6a16 100755 --- a/xCAT-server/share/xcat/netboot/sles/genimage +++ b/xCAT-server/share/xcat/netboot/sles/genimage @@ -441,7 +441,7 @@ unless ($onlyinitrd) { #mkpath("$rootimg_dir/var/lib/yum"); my $yumcmd; if($osver =~ /sles11/ && $osver_host == 11) { - $yumcmd = "zypper -R $rootimg_dir install -l "; #add -l for SLES11 + $yumcmd = "zypper -R $rootimg_dir install -l -y "; #add -l for SLES11 }else { $yumcmd = "zypper -R $rootimg_dir install "; } @@ -464,11 +464,13 @@ unless ($onlyinitrd) { my $index=1; foreach $pass (sort (keys(%pkg_hash))) { $pkgnames = ""; + $group_pkgnames = ""; foreach (keys(%{$pkg_hash{$pass}})) { if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;} my $pa=$pkg_hash{$pass}{$_}; # replace the kernel package with the name has the specific version my @npa = (); + my @npa_group = (); foreach my $p (@$pa) { if ($p =~ /^kernel$/ && $kernelver) { # get all files in $srcdir and $kerneldir @@ -488,19 +490,42 @@ unless ($onlyinitrd) { my $kernelname = "$kern=".$krpmver; push @npa, $kernelname; } - } else { - push @npa, $p; + } + else { + if($p =~ s/^@//) + { + push @npa_group, $p; + } + else + { + push @npa, $p; + } } } $pkgnames .= " " . join(' ', @npa); + $group_pkgnames .= " " . join(' ', @npa_group); } - print "$yumcmd $pkgnames\n"; - my $rc = system("$yumcmd $pkgnames"); - $rc = $rc >> 8; - if (($rc) && ($rc != '104')) { - print "zypper invocation failed with rc: $rc\n"; - exit 1; - } + + if($pkgnames ne ' ') + { + print "$yumcmd $pkgnames\n"; + my $rc = system("$yumcmd $pkgnames"); + $rc = $rc >> 8; + if (($rc) && ($rc != '104')) { + print "zypper invocation failed with rc: $rc\n"; + exit 1; + } + } + if($group_pkgnames ne ' ') + { + print "$yumcmd -t pattern $group_pkgnames\n"; + $rc = system("$yumcmd -t pattern $group_pkgnames"); + $rc = $rc >> 8; + if (($rc) && ($rc != '104')) { + print "zypper invocation failed with rc: $rc\n"; + exit 1; + } + } } foreach $pass (sort (keys(%extra_hash))) {