From e261973c053c5611433917322aaed0fd6165dbd1 Mon Sep 17 00:00:00 2001 From: immarvin Date: Thu, 9 Nov 2017 05:00:33 -0500 Subject: [PATCH] Support http repos for otherpkgs #4042 --- .../references/man5/linuximage.5.rst | 2 +- perl-xCAT/xCAT/Schema.pm | 2 +- xCAT-server/share/xcat/netboot/rh/genimage | 35 ++++++++++++++++--- xCAT/postscripts/otherpkgs | 33 +++++++++++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man5/linuximage.5.rst b/docs/source/guides/admin-guides/references/man5/linuximage.5.rst index 1ecae0842..532eafc1b 100644 --- a/docs/source/guides/admin-guides/references/man5/linuximage.5.rst +++ b/docs/source/guides/admin-guides/references/man5/linuximage.5.rst @@ -80,7 +80,7 @@ linuximage Attributes: \ **otherpkgdir**\ - The base directory where the non-distro packages are stored. Only 1 local directory supported at present. + The base directory and urls of internet repos from which the non-distro packages are retrived. Only 1 local directory is supported at present. The entries should be delimited with comma ",". Currently, the internet repos are only supported on Ubuntu and Redhat. diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index f01edfd98..cf2f6a014 100755 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -803,7 +803,7 @@ passed as argument rather than by table value', pkglist => 'The fully qualified name of the file that stores the distro packages list that will be included in the image. Make sure that if the pkgs in the pkglist have dependency pkgs, the dependency pkgs should be found in one of the pkgdir', pkgdir => 'The name of the directory where the distro packages are stored. It could be set to multiple paths. The multiple paths must be separated by ",". The first path in the value of osimage.pkgdir must be the OS base pkg dir path, such as pkgdir=/install/rhels6.2/x86_64,/install/updates . In the os base pkg path, there are default repository data. And in the other pkg path(s), the users should make sure there are repository data. If not, use "createrepo" command to create them. For ubuntu, multiple mirrors can be specified in the pkgdir attribute, the mirrors must be prefixed by the protocol(http/ssh) and delimited with "," between each other.', otherpkglist => 'The fully qualified name of the file that stores non-distro package lists that will be included in the image. It could be set to multiple paths. The multiple paths must be separated by ",".', - otherpkgdir => 'The base directory where the non-distro packages are stored. Only 1 local directory supported at present.', + otherpkgdir => 'The base directory and urls of internet repos from which the non-distro packages are retrived. Only 1 local directory is supported at present. The entries should be delimited with comma ",". Currently, the internet repos are only supported on Ubuntu and Redhat.', exlist => 'The fully qualified name of the file that stores the file names and directory names that will be excluded from the image during packimage command. It is used for diskless image only.', postinstall => 'Supported in diskless image only. The fully qualified name of the scripts running in non-chroot mode after the package installation but before initrd generation during genimage. If multiple scripts are specified, they should be seperated with comma ",". A set of osimage attributes are exported as the environment variables to be used in the postinstall scripts: diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 9a7e5d9e5..2b535fea6 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -455,7 +455,30 @@ unless ($onlyinitrd) { } my %extrapkgnames; my %repohash; + + + if (keys(%extra_hash) > 0) { + my @otherpkgdir_url; + my @otherpkgdir_local; + foreach my $tmpdir (split ',', $srcdir_otherpkgs){ + if($tmpdir =~ /^http:.*/){ + push @otherpkgdir_url, $tmpdir; + }else{ + push @otherpkgdir_local,$tmpdir; + } + } + + if(scalar @otherpkgdir_local >1){ + print "genimage: at most only 1 local dir in otherpkgdir is supported.\n"; + exit 1; + } + + my $srcdir_otherpkgs_local; + if(scalar @otherpkgdir_local == 1){ + $srcdir_otherpkgs_local=$otherpkgdir_local[0]; + } + open($yumconfig, ">>", "/tmp/genimage.$$.yum.conf"); my $index = 1; foreach $pass (sort { $a <=> $b } (keys(%extra_hash))) { @@ -468,7 +491,13 @@ unless ($onlyinitrd) { } 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"; + foreach(@otherpkgdir_url){ + print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=$_\ngpgpcheck=0\n\n"; + $repohash{$pass}{$index} = 1; + $index++; + } + + print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=file://$srcdir_otherpkgs_local/$_\ngpgpcheck=0\n\n"; $repohash{$pass}{$index} = 1; $index++; my $pa = $extra_hash{$pass}{$_}; @@ -488,10 +517,6 @@ unless ($onlyinitrd) { $yumcmd_base .= "--enablerepo=$osver-$arch-$_ "; } - # for (1..$index) { - # $yumcmd .= "--enablerepo=otherpkgs$_ "; - # } - # Hack uname when deal otherpkgs use_hackuname($arch, $kernelver); use_devnull(); diff --git a/xCAT/postscripts/otherpkgs b/xCAT/postscripts/otherpkgs index aa2a21684..eb17aae10 100755 --- a/xCAT/postscripts/otherpkgs +++ b/xCAT/postscripts/otherpkgs @@ -775,6 +775,39 @@ EOF` fi done + #add repo for url repos in otherpkgdir + if [ -n "OTHERPKGDIR_INTERNET" ];then + OIFS=$IFS + IFS=',' + OTHERPKGDIRLIST_INTERNET=($OTHERPKGDIR_INTERNET) + + index=$(array_get_size repo_path) + for url in ${OTHERPKGDIRLIST_INTERNET[@]} + do + if [ $hasyum -eq 1 ] || [ $haszypper -eq 1 ] ; then + REPOFILE="$repo_base/xCAT-otherpkgs$index.repo" + echo "[xcat-otherpkgs$index]" > $REPOFILE + echo "name=xcat-otherpkgs$index" >> $REPOFILE + echo "baseurl=$url" >> $REPOFILE + echo "enabled=1" >> $REPOFILE + echo "gpgcheck=0" >> $REPOFILE + index=$[index+1] + fi + done + + IFS=$OIFS + if [ $hasyum -eq 1 ]; then + yum clean all + fi + if [ $haszypper -eq 1 ]; then + result=`zypper --non-interactive refresh 2>&1` + if [ $VERBOSE ]; then + echo "otherpkgs: zypper --non-interactive refresh" + echo " $result" + fi + fi + fi + #now update all the existing rpms if [ $hasyum -eq 1 ]; then if [ $VERBOSE ]; then