From 17731a33ec5795404f31c556bed3ab56626ba6ad Mon Sep 17 00:00:00 2001 From: mxi1 Date: Fri, 9 Jul 2010 06:19:30 +0000 Subject: [PATCH] for defect 3012545, "netboot/imgutils/imgutils.pm" is created to hold all the functions used in different "genimage" commands; git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6683 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- .../share/xcat/netboot/fedora12/genimage | 42 +++++------------ .../share/xcat/netboot/imgutils/imgutils.pm | 35 +++++++++++++++ xCAT-server/share/xcat/netboot/rh/genimage | 42 +++++------------ xCAT-server/share/xcat/netboot/sles/genimage | 45 ++++++------------- 4 files changed, 70 insertions(+), 94 deletions(-) create mode 100644 xCAT-server/share/xcat/netboot/imgutils/imgutils.pm diff --git a/xCAT-server/share/xcat/netboot/fedora12/genimage b/xCAT-server/share/xcat/netboot/fedora12/genimage index a84a5d439..0c32f8055 100755 --- a/xCAT-server/share/xcat/netboot/fedora12/genimage +++ b/xCAT-server/share/xcat/netboot/fedora12/genimage @@ -5,12 +5,17 @@ BEGIN } use lib "$::XCATROOT/lib/perl"; +use lib "../imgutils"; + use File::Basename; use File::Path; use File::Copy; use File::Find; use Getopt::Long; use Cwd qw(realpath); + +use imgutils; + #use strict; Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); @@ -229,9 +234,9 @@ unless ($onlyinitrd) { mkpath("$rootimg_dir/var/lib/yum"); if (!$imagename) { - $pkglist= get_profile_def_filename($customdir, "pkglist"); + $pkglist= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "pkglist"); if (!$pkglist) { - $pkglist= get_profile_def_filename($pathtofiles, "pkglist"); + $pkglist= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "pkglist"); } } @@ -261,8 +266,8 @@ unless ($onlyinitrd) { #Now let's handle extra packages if (!$imagename) { - $otherpkglist=get_profile_def_filename($customdir, "otherpkgs.pkglist"); - if (!$otherpkglist) { $otherpkglist=get_profile_def_filename($pathtofiles, "otherpkgs.pkglist"); } + $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "otherpkgs.pkglist"); + if (!$otherpkglist) { $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "otherpkgs.pkglist"); } } my %extra_hash=(); if ($otherpkglist) { @@ -395,9 +400,9 @@ unlink "/tmp/genimage.$$.yum.conf"; #-- run postinstall script if (!$imagename) { - $postinstall_filename= get_profile_def_filename($customdir, "postinstall"); + $postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "postinstall"); if (!$postinstall_filename) { - $postinstall_filename= get_profile_def_filename($pathtofiles, "postinstall"); + $postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "postinstall"); } } @@ -1195,28 +1200,3 @@ sub include_file } - -sub get_profile_def_filename { - my $base=shift; - my $ext=shift; - my $dotpos = rindex($osver, "."); - my $osbase = substr($osver, 0, $dotpos); - if (-r "$base/$profile.$osver.$arch.$ext") { - return "$base/$profile.$osver.$arch.$ext"; - } elsif (-r "$base/$profile.$osbase.$arch.$ext") { - return "$base/$profile.$osbase.$arch.$ext"; - } elsif (-r "$base/$profile.$arch.$ext") { - return "$base/$profile.$arch.$ext"; - } elsif (-r "$base/$profile.$osver.$ext") { - return "$base/$profile.$osver.$ext"; - } elsif (-r "$base/$profile.$osbase.$ext") { - return "$base/$profile.$osbase.$ext"; - } elsif (-r "$base/$profile.$ext") { - return "$base/$profile.$ext"; - } - - return ""; -} - - - diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm new file mode 100644 index 000000000..fc4cf4bac --- /dev/null +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -0,0 +1,35 @@ +#!/usr/bin/perl -w +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +# #(C)IBM Corp +package imgutils; + +use strict; +use warnings "all"; + +sub get_profile_def_filename { + my $osver = shift; + my $profile = shift; + my $arch = shift; + + my $base=shift; + my $ext=shift; + my $dotpos = rindex($osver, "."); + my $osbase = substr($osver, 0, $dotpos); + if (-r "$base/$profile.$osver.$arch.$ext") { + return "$base/$profile.$osver.$arch.$ext"; + } elsif (-r "$base/$profile.$osbase.$arch.$ext") { + return "$base/$profile.$osbase.$arch.$ext"; + } elsif (-r "$base/$profile.$arch.$ext") { + return "$base/$profile.$arch.$ext"; + } elsif (-r "$base/$profile.$osver.$ext") { + return "$base/$profile.$osver.$ext"; + } elsif (-r "$base/$profile.$osbase.$ext") { + return "$base/$profile.$osbase.$ext"; + } elsif (-r "$base/$profile.$ext") { + return "$base/$profile.$ext"; + } + + return ""; +} + +1; diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 80d9f15f9..24aa2c173 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -5,12 +5,17 @@ BEGIN } use lib "$::XCATROOT/lib/perl"; +use lib "../imgutils"; + use File::Basename; use File::Path; use File::Copy qw/copy cp mv move/; use File::Find; use Getopt::Long; use Cwd qw(realpath); + +use imgutils; + #use strict; Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); @@ -265,9 +270,9 @@ unless ($onlyinitrd) { mkpath("$rootimg_dir/var/lib/yum"); if (!$imagename) { - $pkglist= get_profile_def_filename($customdir, "pkglist"); + $pkglist= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "pkglist"); if (!$pkglist) { - $pkglist= get_profile_def_filename($pathtofiles, "pkglist"); + $pkglist= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "pkglist"); } } @@ -297,8 +302,8 @@ unless ($onlyinitrd) { #Now let's handle extra packages if (!$imagename) { - $otherpkglist=get_profile_def_filename($customdir, "otherpkgs.pkglist"); - if (!$otherpkglist) { $otherpkglist=get_profile_def_filename($pathtofiles, "otherpkgs.pkglist"); } + $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "otherpkgs.pkglist"); + if (!$otherpkglist) { $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "otherpkgs.pkglist"); } } my %extra_hash=(); if ($otherpkglist) { @@ -437,9 +442,9 @@ if (-d "$rootimg_dir/usr/share/dracut") { #-- run postinstall script if (!$imagename) { - $postinstall_filename= get_profile_def_filename($customdir, "postinstall"); + $postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "postinstall"); if (!$postinstall_filename) { - $postinstall_filename= get_profile_def_filename($pathtofiles, "postinstall"); + $postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "postinstall"); } } @@ -1396,28 +1401,3 @@ sub include_file } - -sub get_profile_def_filename { - my $base=shift; - my $ext=shift; - my $dotpos = rindex($osver, "."); - my $osbase = substr($osver, 0, $dotpos); - if (-r "$base/$profile.$osver.$arch.$ext") { - return "$base/$profile.$osver.$arch.$ext"; - } elsif (-r "$base/$profile.$osbase.$arch.$ext") { - return "$base/$profile.$osbase.$arch.$ext"; - } elsif (-r "$base/$profile.$arch.$ext") { - return "$base/$profile.$arch.$ext"; - } elsif (-r "$base/$profile.$osver.$ext") { - return "$base/$profile.$osver.$ext"; - } elsif (-r "$base/$profile.$osbase.$ext") { - return "$base/$profile.$osbase.$ext"; - } elsif (-r "$base/$profile.$ext") { - return "$base/$profile.$ext"; - } - - return ""; -} - - - diff --git a/xCAT-server/share/xcat/netboot/sles/genimage b/xCAT-server/share/xcat/netboot/sles/genimage index d0639ee8c..718fc0091 100755 --- a/xCAT-server/share/xcat/netboot/sles/genimage +++ b/xCAT-server/share/xcat/netboot/sles/genimage @@ -5,12 +5,17 @@ BEGIN } use lib "$::XCATROOT/lib/perl"; +use lib "../imgutils"; + use File::Basename; use File::Path; use File::Copy; use File::Find; use Getopt::Long; use Cwd qw(realpath); + +use imgutils; + #use strict; Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); @@ -235,8 +240,8 @@ if(`grep VERSION /etc/SuSE-release` =~ /VERSION = (\d+)/) { unless ($onlyinitrd) { if (!$imagename) { - $otherpkglist=get_profile_def_filename($customdir, "otherpkgs.pkglist"); - if (!$otherpkglist) { $otherpkglist=get_profile_def_filename($pathtofiles, "otherpkgs.pkglist"); } + $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "otherpkgs.pkglist"); + if (!$otherpkglist) { $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "otherpkgs.pkglist"); } } my %extra_hash=(); if ($otherpkglist) { @@ -307,9 +312,9 @@ unless ($onlyinitrd) { #-- add custom repositories to the image #TODO: should we add the support to otherpkgs for this? we have too many list files and it seems only SLES supports this my $repolist; - $repolist = get_profile_def_filename($customdir, "repolist"); + $repolist = imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "repolist"); if(!$repolist) { - $repolist = get_profile_def_filename($pathtofiles, "repolist"); + $repolist = imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "repolist"); } if ( -r "$repolist") { @@ -339,8 +344,8 @@ unless ($onlyinitrd) { #install packages from pkglist file my $pkgnames; if (!$imagename) { - $pkglist=get_profile_def_filename($customdir, "pkglist"); - if (!$pkglist) { $pkglist=get_profile_def_filename($pathtofiles, "pkglist"); } + $pkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "pkglist"); + if (!$pkglist) { $pkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "pkglist"); } } if (!$pkglist) { @@ -411,9 +416,9 @@ unlink "/tmp/genimage.$$.yum.conf"; #-- run postinstall script if (!$imagename) { - $postinstall_filename= get_profile_def_filename($customdir, "postinstall"); + $postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "postinstall"); if (!$postinstall_filename) { - $postinstall_filename= get_profile_def_filename($pathtofiles, "postinstall"); + $postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "postinstall"); } } @@ -1356,28 +1361,4 @@ sub include_file return join(',', @text); } -sub get_profile_def_filename { - my $base=shift; - my $ext=shift; - my $dotpos = rindex($osver, "."); - my $osbase = substr($osver, 0, $dotpos); - if (-r "$base/$profile.$osver.$arch.$ext") { - return "$base/$profile.$osver.$arch.$ext"; - } elsif (-r "$base/$profile.$osbase.$arch.$ext") { - return "$base/$profile.$osbase.$arch.$ext"; - } elsif (-r "$base/$profile.$arch.$ext") { - return "$base/$profile.$arch.$ext"; - } elsif (-r "$base/$profile.$osver.$ext") { - return "$base/$profile.$osver.$ext"; - } elsif (-r "$base/$profile.$osbase.$ext") { - return "$base/$profile.$osbase.$ext"; - } elsif (-r "$base/$profile.$ext") { - return "$base/$profile.$ext"; - } - - return ""; -} - - -