Add ENV support for xcat otherpkgs.pkglist/pkglist

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10725 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
ellen56 2011-10-10 07:46:18 +00:00
parent eeca4d7dfc
commit e504131e8c
6 changed files with 129 additions and 69 deletions

View File

@ -538,6 +538,11 @@ sub makescript
if ($ospkglist)
{
my $pkgtext = get_pkglist_tex($ospkglist);
my ($envlist,$pkgtext) = get_envlist($pkgtext);
if ($envlist) {
push @scriptd, "ENVLIST='".$envlist."'\n";
push @scriptd, "export ENVLIST\n";
}
if ($pkgtext)
{
push @scriptd, "OSPKGS='".$pkgtext."'\n";
@ -555,7 +560,13 @@ sub makescript
foreach (@sublists)
{
$sl_index++;
push @scriptd, "OTHERPKGS$sl_index='".$_."'\n";
my $tmp = $_;
my ($envlist, $tmp) = get_envlist($tmp);
if ($envlist) {
push @scriptd, "ENVLIST$sl_index='".$envlist."'\n";
push @scriptd, "export ENVLIST$sl_index\n";
}
push @scriptd, "OTHERPKGS$sl_index='".$tmp."'\n";
push @scriptd, "export OTHERPKGS$sl_index\n";
}
if ($sl_index > 0)
@ -788,6 +799,22 @@ sub makescript
#----------------------------------------------------------------------------
=head3 get_envlist
extract environment variables list from pkglist text.
=cut
#-----------------------------------------------------------------------------
sub get_envlist
{
my $envlist;
my $pkgtext = shift;
$envlist = join ' ', ($pkgtext =~ /#ENV:([^#^\n]+)#/g);
$pkgtext =~ s/#ENV:[^#^\n]+#,?//g;
return ($envlist, $pkgtext);
}
#----------------------------------------------------------------------------
=head3 get_pkglist_text
read the pkglist file, expand it and return the content.
@ -810,7 +837,8 @@ sub get_pkglist_tex
next
if ( /^\s*#/
&& !/^\s*#INCLUDE:[^#^\n]+#/
&& !/^\s*#NEW_INSTALL_LIST#/); #-- skip comments
&& !/^\s*#NEW_INSTALL_LIST#/
&& !/^\s*#ENV:[^#^\n]+#/); #-- skip comments
if (/^@(.*)/)
{ #for groups that has space in name
my $save = $1;

View File

@ -92,7 +92,6 @@ sub get_package_names {
if ( @tmp_array > 0) {
my $pkgtext=join(',',@tmp_array);
#handle the #INLCUDE# tag recursively
my $idir = dirname($plist_file_name);
my $doneincludes=0;
@ -118,6 +117,15 @@ sub get_package_names {
} elsif (/^#NEW_INSTALL_LIST#/) {
$pass++;
next;
} elsif (/#ENV:([^#^\n]+)#/) {
my $pa=$pkgnames{$pass}{ENVLIST};
my $env = $1;
if (exists($pkgnames{$pass}{ENVLIST})){
push(@$pa,$env);
} else {
$pkgnames{$pass}{ENVLIST} = [$env];
}
next;
} elsif (/^#/) {
# ignore all other comment lines
next;

View File

@ -234,7 +234,7 @@ unless ($onlyinitrd) {
foreach $pass (sort (keys(%pkg_hash))) {
my $pkgnames = "";
foreach (keys(%{$pkg_hash{$pass}})) {
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE") || ($_ eq "ENVLIST")) { next;}
my $pa=$pkg_hash{$pass}{$_};
my @npa = ();
# replace the kernel package with the name has the specific version
@ -269,9 +269,13 @@ unless ($onlyinitrd) {
}
$pkgnames .= " " . join(' ', @npa);
}
my $envlist;
if(exists $pkg_hash{$pass}{ENVLIST}){
$envlist = join(' ', @{$pkg_hash{$pass}{ENVLIST}});
}
print "$yumcmd install $pkgnames\n";
my $rc = system("$yumcmd install $pkgnames");
print "$envlist $yumcmd install $pkgnames\n";
my $rc = system("$envlist $yumcmd install $pkgnames");
if ($rc) {
print "yum invocation failed\n";
exit 1;
@ -295,7 +299,7 @@ unless ($onlyinitrd) {
my $index=1;
foreach $pass (sort (keys(%extra_hash))) {
foreach (keys(%{$extra_hash{$pass}})) {
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE") || ($_ eq "ENVLIST")) { next;}
print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=file://$srcdir_otherpkgs/$_\ngpgpcheck=0\n\n";
$index++;
my $pa=$extra_hash{$pass}{$_};
@ -313,14 +317,18 @@ unless ($onlyinitrd) {
}
foreach $pass (sort (keys(%extra_hash))) {
my $envlist;
if(exists($extra_hash{$pass}{ENVLIST})){
$envlist = join(' ', @{$extra_hash{$pass}{ENVLIST}});
}
# remove the packages that are specified in the otherpkgs.list files with leading '-'
my $yumcmd_remove= "$yumcmd erase ";
if (exists ($extra_hash{$pass}{'PRE_REMOVE'})) {
my $pa=$extra_hash{$pass}{'PRE_REMOVE'};
my $rm_packges= join(' ', @$pa);
if ($rm_packges) {
print "$yumcmd_remove $rm_packges\n";
$rc = system("$yumcmd_remove $rm_packges");
print "$envlist $yumcmd_remove $rm_packges\n";
$rc = system("$envlist $yumcmd_remove $rm_packges");
}
}
@ -338,8 +346,9 @@ unless ($onlyinitrd) {
#print "yumcmd=$yumcmd\n";
#my $repo=`cat /tmp/genimage.$$.yum.conf`;
#print "repo=$repo";
my $rc = system($yumcmd);
print "$envlist $yumcmd\n";
my $rc = system("$envlist $yumcmd");
if ($rc) {
print "yum invocation failed\n";
exit 1;
@ -350,10 +359,11 @@ unless ($onlyinitrd) {
my $pa=$extra_hash{$pass}{'POST_REMOVE'};
my $rm_packges= join(' ', @$pa);
if ($rm_packges) {
print "$yumcmd_remove $rm_packges\n";
$rc = system("$yumcmd_remove $rm_packges");
print "$envlist $yumcmd_remove $rm_packges\n";
$rc = system("$envlist $yumcmd_remove $rm_packges");
}
}
$yumcmd = $yumcmd_base;
}
}

View File

@ -280,7 +280,7 @@ unless ($onlyinitrd) {
my $pass;
foreach $pass (sort (keys(%extra_hash))) {
foreach (keys(%{$extra_hash{$pass}})) {
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE") || ($_ eq "ENVLIST")) { next;}
my $whole_path="$srcdir_otherpkgs/$_";
if (-r "$srcdir_otherpkgs/$_/repodata/repomd.xml") {
if($osver_host == 11) {
@ -355,7 +355,7 @@ unless ($onlyinitrd) {
$pkgnames = "";
$group_pkgnames = "";
foreach (keys(%{$pkg_hash{$pass}})) {
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE") || ($_ eq "ENVLIST")) { next;}
my $pa=$pkg_hash{$pass}{$_};
# replace the kernel package with the name has the specific version
my @npa = ();
@ -400,10 +400,16 @@ unless ($onlyinitrd) {
$pkgnames .= " " . join(' ', @npa);
$group_pkgnames .= " " . join(' ', @npa_group);
}
my $envlist;
if(exists $pkg_hash{$pass}{ENVLIST}){
$envlist = join(' ', @{$pkg_hash{$pass}{ENVLIST}});
}
if($pkgnames ne ' ')
{
print "$yumcmd $pkgnames\n";
my $rc = system("$yumcmd $pkgnames");
print "$envlist $yumcmd $pkgnames\n";
my $rc = system("$envlist $yumcmd $pkgnames");
$rc = $rc >> 8;
if (($rc) && ($rc != '104')) {
print "zypper invocation failed with rc: $rc\n";
@ -412,8 +418,8 @@ unless ($onlyinitrd) {
}
if($group_pkgnames ne ' ')
{
print "$yumcmd -t pattern $group_pkgnames\n";
$rc = system("$yumcmd -t pattern $group_pkgnames");
print "$envlist $yumcmd -t pattern $group_pkgnames\n";
$rc = system("$envlist $yumcmd -t pattern $group_pkgnames");
$rc = $rc >> 8;
if (($rc) && ($rc != '104')) {
print "zypper invocation failed with rc: $rc\n";
@ -424,20 +430,26 @@ unless ($onlyinitrd) {
foreach $pass (sort (keys(%extra_hash))) {
#remove the packages that are specified in the otherpkgs.list files with leading '-'
my $envlist;
if(exists $extra_hash{$pass}{ENVLIST}){
$envlist = join(' ', @{$extra_hash{$pass}{ENVLIST}});
}
my $yumcmd_remove= "zypper -R $rootimg_dir --non-interactive --no-gpg-checks remove ";
if (exists ($extra_hash{$pass}{'PRE_REMOVE'})) {
my $pa=$extra_hash{$pass}{'PRE_REMOVE'};
my $rm_packges= join(' ', @$pa);
if ($rm_packges) {
$rc = system("$yumcmd_remove $rm_packges");
print "$envlist $yumcmd_remove $rm_packges";
$rc = system("$envlist $yumcmd_remove $rm_packges");
}
}
#add extra packages in the list
if ($extrapkgnames{$pass}) {
print "$yumcmd $extrapkgnames{$pass}\n";
$rc = system("$yumcmd $extrapkgnames{$pass}");
print "$envlist yumcmd $extrapkgnames{$pass}\n";
$rc = system("$envlist $yumcmd $extrapkgnames{$pass}");
$rc = $rc >> 8;
if (($rc) && ($rc != '104')) {
print "zypper invocation failed with rc: $rc\n";
@ -450,7 +462,8 @@ unless ($onlyinitrd) {
my $pa=$extra_hash{$pass}{'POST_REMOVE'};
my $rm_packges= join(' ', @$pa);
if ($rm_packges) {
$rc = system("$yumcmd_remove $rm_packges");
print "$envlist $yumcmd_remove $rm_packges";
$rc = system("$envlist $yumcmd_remove $rm_packges");
}
}
}

View File

@ -199,8 +199,8 @@ if ( pmatch "$OSVER" "sles10*" ); then
#install the new patterns if any
if [ -n "$groups" ]; then
cmd="rug install -y --agree-to-third-party-licences -t pattern $groups"
result=`$cmd 2>&1`
cmd="$ENVLIST rug install -y --agree-to-third-party-licences -t pattern $groups"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd\n $result"
echo "ospkgs: $cmd"
@ -215,8 +215,8 @@ if ( pmatch "$OSVER" "sles10*" ); then
#install new rpms if any
if [ -n "$pkgs" ]; then
cmd="rug install -y --agree-to-third-party-licences $pkgs"
result=`$cmd 2>&1`
cmd="$ENVLIST rug install -y --agree-to-third-party-licences $pkgs"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd\n $result"
echo "ospkgs: $cmd"
@ -231,8 +231,8 @@ if ( pmatch "$OSVER" "sles10*" ); then
#remove some packages if specified
if [ -n "$pkgs_d" ]; then
cmd="rug remove -y $pkgs_d"
result=`$cmd 2>&1`
cmd="$ENVLIST rug remove -y $pkgs_d"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd\n $result"
echo "ospkgs: $cmd"
@ -295,8 +295,8 @@ elif ( pmatch "$OSVER" "sles11*" ); then
#install the new patterns if any
if [ -n "$groups" ]; then
cmd="zypper install -y --auto-agree-with-licenses -t pattern $groups"
result=`$cmd 2>&1`
cmd="$ENVLIST zypper install -y --auto-agree-with-licenses -t pattern $groups"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd\n $result"
echo "ospkgs: $cmd"
@ -311,8 +311,8 @@ elif ( pmatch "$OSVER" "sles11*" ); then
#install new rpms if any
if [ -n "$pkgs" ]; then
cmd="zypper install -y --auto-agree-with-licenses $pkgs"
result=`$cmd 2>&1`
cmd="$ENVLIST zypper install -y --auto-agree-with-licenses $pkgs"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd $result"
echo "ospkgs: $cmd"
@ -327,8 +327,8 @@ elif ( pmatch "$OSVER" "sles11*" ); then
#remove some packages if specified
if [ -n "$pkgs_d" ]; then
cmd="zypper remove -y $pkgs_d"
result=`$cmd 2>&1`
cmd="$ENVLIST zypper remove -y $pkgs_d"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd $result"
echo "ospkgs: $cmd"
@ -368,23 +368,23 @@ elif ( pmatch "$OSVER" "ubuntu*" ); then
# but keeping this here doesn't really hurt. Anything that looks like a group will
# be installed as though it were a package.)
if [ -n "$groups" ]; then
command="apt-get -q -y --force-yes install $groups"
command="$ENVLIST apt-get -q -y --force-yes install $groups"
echo "=== $command"
$command
eval $command
fi
# install packages
if [ -n "$pkgs" ]; then
command="apt-get -q -y --force-yes install $pkgs"
command="$ENVLIST apt-get -q -y --force-yes install $pkgs"
echo "=== $command"
$command
eval $command
fi
# remove packages
if [ -n "$pkgs_d" ]; then
command="apt-get -y remove $pkgs_d"
command="$ENVLIST apt-get -y remove $pkgs_d"
echo "=== $command"
$command
eval $command
fi
else
#check if yum is installed
@ -434,8 +434,8 @@ else
#install new groups if any
if [ -n "$groups" ]; then
cmd="echo $groups| xargs yum -y groupinstall"
result=`echo $groups | xargs yum -y groupinstall 2>&1`
cmd="echo $groups| $ENVLIST xargs yum -y groupinstall"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd\n $result"
echo "ospkgs: $cmd"
@ -450,8 +450,8 @@ else
#install new rpms if any
if [ -n "$pkgs" ]; then
cmd="yum -y install $pkgs"
result=`$cmd 2>&1`
cmd="$ENVLIST yum -y install $pkgs"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd\n $result"
echo "ospkgs: $cmd"
@ -466,8 +466,8 @@ else
#remove some rpms if specified
if [ -n "$pkgs_d" ]; then
cmd="yum -y remove $pkgs_d"
result=`$cmd 2>&1`
cmd="$ENVLIST yum -y remove $pkgs_d"
result=`eval $cmd 2>&1`
if [ $? -ne 0 ]; then
logger -t xcat "ospkgs: $cmd\n $result"
echo "ospkgs: $cmd"

View File

@ -294,6 +294,7 @@ op_index=1
#echo "OTHERPKGS_INDEX = $OTHERPKGS_INDEX"
while [ $op_index -le $OTHERPKGS_INDEX ]; do
eval pkglist=\$OTHERPKGS$op_index
eval envlist=\$ENVLIST$op_index
#echo "pkglist = $pkglist"
if [ $hasyum -eq 1 ]; then
mkdir -p /etc/yum.repos.d
@ -492,16 +493,16 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
#Now we have parsed the input, let's remove rpms if is specified with -
if [ "$repo_pkgs_preremove" != "" ]; then
if [ $hasyum -eq 1 ]; then
echo "yum -y remove $repo_pkgs_preremove"
result=`yum -y remove $repo_pkgs_preremove 2>&1`
echo "eval $envlist yum -y remove $repo_pkgs_preremove"
result=`eval $envlist yum -y remove $repo_pkgs_preremove 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs: $result"
fi
echo "$result"
elif [ $haszypper -eq 1 ]; then
echo "zypper remove -y $repo_pkgs_preremove"
result=`zypper remove -y $repo_pkgs_preremove 2>&1`
echo "eval $envlist zypper remove -y $repo_pkgs_preremove"
result=`eval $envlist zypper remove -y $repo_pkgs_preremove 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs: $result"
@ -520,8 +521,8 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
fi
if [ "$plain_pkgs_preremove" != "" ]; then
echo "$sremovecommand $plain_pkgs_preremove"
result=`$sremovecommand $plain_pkgs_preremove 2>&1`
echo "eval $envlist $sremovecommand $plain_pkgs_preremove"
result=`eval $envlist $sremovecommand $plain_pkgs_preremove 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs $result"
@ -533,16 +534,16 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
#installation using yum or zypper
if [ "$repo_pkgs" != "" ]; then
if [ $hasyum -eq 1 ]; then
echo "yum -y install $repo_pkgs"
result=`yum -y install $repo_pkgs 2>&1`
echo "eval $envlist yum -y install $repo_pkgs"
result=`eval $envlist yum -y install $repo_pkgs 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs: $result"
fi
echo "$result"
elif [ $haszypper -eq 1 ]; then
echo "zypper install -y $repo_pkgs"
result=`zypper install -y $repo_pkgs 2>&1`
echo "eval $envlist zypper install -y $repo_pkgs"
result=`eval $envlist zypper install -y $repo_pkgs 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs: $result"
@ -556,8 +557,8 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
#done
elif [ $hasapt -eq 1 ]; then
apt_get_update_if_repos_changed $REPOFILE
echo "apt-get -q -y --force-yes install $repo_pkgs"
result=`apt-get -q -y --force-yes install $repo_pkgs 2>&1`
echo "eval $envlist apt-get -q -y --force-yes install $repo_pkgs"
result=`eval $envlist apt-get -q -y --force-yes install $repo_pkgs 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs: $result"
@ -588,8 +589,8 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
cd $OTHERPKGDIR
fi
echo "$supdatecommand $plain_pkgs"
result=`$supdatecommand $plain_pkgs 2>&1`
echo "eval $envlist $supdatecommand $plain_pkgs"
result=`eval $envlist $supdatecommand $plain_pkgs 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs $result"
@ -607,16 +608,16 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
#remove more rpms if specified with --
if [ "$repo_pkgs_postremove" != "" ]; then
if [ $hasyum -eq 1 ]; then
echo "yum -y remove $repo_pkgs_postremove"
result=`yum -y remove $repo_pkgs_postremove 2>&1`
echo "eval $envlist yum -y remove $repo_pkgs_postremove"
result=`eval $envlist yum -y remove $repo_pkgs_postremove 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs: $result"
fi
echo "$result"
elif [ $haszypper -eq 1 ]; then
echo "zypper remove -y $repo_pkgs_postremove"
result=`zypper remove -y $repo_pkgs_postremove 2>&1`
echo "eval $envlist zypper remove -y $repo_pkgs_postremove"
result=`eval $envlist zypper remove -y $repo_pkgs_postremove 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs: $result"
@ -624,8 +625,8 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
echo "$result"
elif [ $hasapt -eq 1 ]; then
apt_get_update_if_repos_changed $REPOFILE
echo "apt-get -y remove $repo_pkgs_postremove"
result=`apt-get -y remove $repo_pkgs_postremove 2>&1`
echo "eval $envlist apt-get -y remove $repo_pkgs_postremove"
result=`eval $envlist apt-get -y remove $repo_pkgs_postremove 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs: $result"
@ -635,8 +636,8 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
fi
if [ "$plain_pkgs_postremove" != "" ]; then
echo "$sremovecommand $plain_pkgs_postremove"
result=`$sremovecommand $plain_pkgs_postremove 2>&1`
echo "eval $envlist $sremovecommand $plain_pkgs_postremove"
result=`eval $envlist $sremovecommand $plain_pkgs_postremove 2>&1`
logger -t xcat "$result"
if [ $? -ne 0 ]; then
logger -t xcat "otherpkgs $result"