Add ENV support for xcat otherpkgs.pkglist/pkglist
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.6@10778 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -178,8 +178,8 @@ if [[ $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"
|
||||
@@ -194,8 +194,8 @@ if [[ $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"
|
||||
@@ -210,8 +210,8 @@ if [[ $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"
|
||||
@@ -272,8 +272,8 @@ elif [[ $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"
|
||||
@@ -288,8 +288,8 @@ elif [[ $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"
|
||||
@@ -304,8 +304,8 @@ elif [[ $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"
|
||||
@@ -364,8 +364,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"
|
||||
@@ -380,8 +380,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"
|
||||
@@ -396,8 +396,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"
|
||||
|
||||
+19
-18
@@ -96,6 +96,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
|
||||
@@ -258,16 +259,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 "$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 "$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"
|
||||
@@ -277,8 +278,8 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
|
||||
fi
|
||||
|
||||
if [ "$plain_pkgs_preremove" != "" ]; then
|
||||
echo "rpm -ev $plain_pkgs_preremove"
|
||||
result=`rpm -ev $plain_pkgs_preremove 2>&1`
|
||||
echo "$envlist rpm -ev $plain_pkgs_preremove"
|
||||
result=`eval $envlist rpm -ev $plain_pkgs_preremove 2>&1`
|
||||
logger -t xcat "$result"
|
||||
if [ $? -ne 0 ]; then
|
||||
logger -t xcat "otherpkgs $result"
|
||||
@@ -290,16 +291,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 "$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 "$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"
|
||||
@@ -336,8 +337,8 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
|
||||
cd $OTHERPKGDIR
|
||||
fi
|
||||
|
||||
echo "rpm -Uvh --replacepkgs $plain_pkgs"
|
||||
result=`rpm -Uvh --replacepkgs $plain_pkgs 2>&1`
|
||||
echo "$envlist rpm -Uvh --replacepkgs $plain_pkgs"
|
||||
result=`eval $envlist rpm -Uvh --replacepkgs $plain_pkgs 2>&1`
|
||||
#result=`rpm -Fvh $plain_pkgs 2>&1`
|
||||
logger -t xcat "$result"
|
||||
if [ $? -ne 0 ]; then
|
||||
@@ -356,16 +357,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 removel $repo_pkgs_postremove"
|
||||
result=`yum -y remove $repo_pkgs_postremove 2>&1`
|
||||
echo "$envlist yum -y removel $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 "$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"
|
||||
@@ -375,8 +376,8 @@ while [ $op_index -le $OTHERPKGS_INDEX ]; do
|
||||
fi
|
||||
|
||||
if [ "$plain_pkgs_postremove" != "" ]; then
|
||||
echo "rpm -ev $plain_pkgs_postremove"
|
||||
result=`rpm -ev $plain_pkgs_postremove 2>&1`
|
||||
echo "$envlist rpm -ev $plain_pkgs_postremove"
|
||||
result=`eval $envlist rpm -ev $plain_pkgs_postremove 2>&1`
|
||||
logger -t xcat "$result"
|
||||
if [ $? -ne 0 ]; then
|
||||
logger -t xcat "otherpkgs $result"
|
||||
|
||||
Reference in New Issue
Block a user