2010-07-09 06:19:30 +00:00
|
|
|
#!/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";
|
|
|
|
|
2010-07-09 09:33:48 +00:00
|
|
|
use File::Basename;
|
|
|
|
use File::Path;
|
2011-05-10 21:14:25 +00:00
|
|
|
use Cwd qw(realpath);
|
2010-07-09 09:33:48 +00:00
|
|
|
|
2010-07-09 06:19:30 +00:00
|
|
|
sub get_profile_def_filename {
|
|
|
|
my $osver = shift;
|
|
|
|
my $profile = shift;
|
|
|
|
my $arch = shift;
|
2011-05-16 19:01:03 +00:00
|
|
|
|
|
|
|
my $tmp_base=shift;
|
|
|
|
my $base=realpath($tmp_base); #get the full path
|
|
|
|
if (!$base) { $base=$tmp_base;}
|
2010-07-09 06:19:30 +00:00
|
|
|
|
|
|
|
my $ext=shift;
|
2010-08-17 23:35:09 +00:00
|
|
|
|
|
|
|
my $dotpos;
|
|
|
|
|
|
|
|
# OS version on s390x can contain 'sp', e.g. sles11sp1
|
|
|
|
# If OS version contains 'sp', get the index of 'sp' instead of '.'
|
|
|
|
if ($osver =~ /sles/ && $osver =~ /sp/) {
|
|
|
|
$dotpos = rindex($osver, "sp");
|
|
|
|
} else {
|
|
|
|
$dotpos = rindex($osver, ".");
|
|
|
|
}
|
|
|
|
|
2010-07-09 06:19:30 +00:00
|
|
|
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 "";
|
|
|
|
}
|
|
|
|
|
2010-07-09 09:33:48 +00:00
|
|
|
sub include_file
|
|
|
|
{
|
|
|
|
my $file = shift;
|
|
|
|
my $idir = shift;
|
|
|
|
my @text = ();
|
|
|
|
unless ($file =~ /^\//) {
|
|
|
|
$file = $idir."/".$file;
|
|
|
|
}
|
|
|
|
|
2010-07-16 17:18:21 +00:00
|
|
|
open(INCLUDE,$file) ||
|
2010-07-09 09:33:48 +00:00
|
|
|
return "#INCLUDEBAD:cannot open $file#";
|
|
|
|
|
|
|
|
while(<INCLUDE>) {
|
|
|
|
chomp($_);
|
|
|
|
s/\s+$//; #remove trailing spaces
|
|
|
|
next if /^\s*$/; #-- skip empty lines
|
2012-08-06 07:07:50 +00:00
|
|
|
next
|
|
|
|
if ( /^\s*#/
|
|
|
|
&& !/^\s*#INCLUDE:[^#^\n]+#/
|
|
|
|
&& !/^\s*#NEW_INSTALL_LIST#/
|
|
|
|
&& !/^\s*#ENV:[^#^\n]+#/); #-- skip comments
|
2010-07-09 09:33:48 +00:00
|
|
|
push(@text, $_);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(INCLUDE);
|
|
|
|
|
|
|
|
return join(',', @text);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_package_names {
|
|
|
|
my $plist_file_name=shift;
|
|
|
|
my %pkgnames=();
|
|
|
|
my @tmp_array=();
|
|
|
|
|
|
|
|
|
2011-07-21 11:22:09 +00:00
|
|
|
if ($plist_file_name && -r $plist_file_name) {
|
2010-07-09 09:33:48 +00:00
|
|
|
my $pkgfile;
|
|
|
|
open($pkgfile,"<","$plist_file_name");
|
|
|
|
while (<$pkgfile>) {
|
|
|
|
chomp;
|
|
|
|
s/\s+$//; #remove trailing white spaces
|
|
|
|
next if /^\s*$/; #-- skip empty lines
|
2012-08-06 07:07:50 +00:00
|
|
|
next
|
|
|
|
if ( /^\s*#/
|
|
|
|
&& !/^\s*#INCLUDE:[^#^\n]+#/
|
|
|
|
&& !/^\s*#NEW_INSTALL_LIST#/
|
|
|
|
&& !/^\s*#ENV:[^#^\n]+#/); #-- skip comments
|
2010-07-09 09:33:48 +00:00
|
|
|
push(@tmp_array,$_);
|
|
|
|
}
|
|
|
|
close($pkgfile);
|
|
|
|
|
|
|
|
if ( @tmp_array > 0) {
|
|
|
|
my $pkgtext=join(',',@tmp_array);
|
|
|
|
#handle the #INLCUDE# tag recursively
|
|
|
|
my $idir = dirname($plist_file_name);
|
|
|
|
my $doneincludes=0;
|
|
|
|
while (not $doneincludes) {
|
|
|
|
$doneincludes=1;
|
|
|
|
if ($pkgtext =~ /#INCLUDE:[^#^\n]+#/) {
|
|
|
|
$doneincludes=0;
|
|
|
|
$pkgtext =~ s/#INCLUDE:([^#^\n]+)#/include_file($1,$idir)/eg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#print "pkgtext=$pkgtext\n";
|
|
|
|
my @tmp=split(',', $pkgtext);
|
|
|
|
my $pass=1;
|
|
|
|
foreach (@tmp) {
|
|
|
|
my $idir;
|
|
|
|
if (/^--/) {
|
|
|
|
$idir="POST_REMOVE"; #line starts with -- means the package should be removed after otherpkgs are installed
|
|
|
|
s/^--//;
|
|
|
|
} elsif (/^-/) {
|
|
|
|
$idir="PRE_REMOVE"; #line starts with single - means the package should be removed before otherpkgs are installed
|
|
|
|
s/^-//;
|
|
|
|
} elsif (/^#NEW_INSTALL_LIST#/) {
|
|
|
|
$pass++;
|
|
|
|
next;
|
2011-10-10 08:36:09 +00:00
|
|
|
} elsif (/^#ENV:([^#^\n]+)#/) {
|
2011-10-10 07:46:18 +00:00
|
|
|
my $pa=$pkgnames{$pass}{ENVLIST};
|
|
|
|
my $env = $1;
|
|
|
|
if (exists($pkgnames{$pass}{ENVLIST})){
|
|
|
|
push(@$pa,$env);
|
|
|
|
} else {
|
|
|
|
$pkgnames{$pass}{ENVLIST} = [$env];
|
|
|
|
}
|
|
|
|
next;
|
2010-07-09 09:33:48 +00:00
|
|
|
} elsif (/^#/) {
|
|
|
|
# ignore all other comment lines
|
|
|
|
next;
|
|
|
|
} else {
|
|
|
|
$idir=dirname($_);
|
|
|
|
}
|
|
|
|
my $fn=basename($_);
|
|
|
|
if (exists($pkgnames{$pass}{$idir})) {
|
|
|
|
my $pa=$pkgnames{$pass}{$idir};
|
|
|
|
push(@$pa, $fn);
|
|
|
|
} else {
|
|
|
|
$pkgnames{$pass}{$idir}=[$fn];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return %pkgnames;
|
|
|
|
}
|
|
|
|
|
2010-07-09 06:19:30 +00:00
|
|
|
1;
|