diff --git a/xCAT-buildkit/bin/buildkit b/xCAT-buildkit/bin/buildkit index c574d7c37..9034ef63a 100755 --- a/xCAT-buildkit/bin/buildkit +++ b/xCAT-buildkit/bin/buildkit @@ -33,7 +33,7 @@ cleantar - deletes the Kit deployment directory and Kit cleanall - equivalent to buildkit cleanrepo all and buildkit cleantar - addpkgs -p [-k|--kitversion ] [-r|--kitrelease ] + addpkgs -p - used by customer to add external product packages when they are not built into the shipped kit tar file @@ -76,12 +76,10 @@ use File::Basename; $::progname = "buildkit"; $::buildkit_conf = "buildkit.conf"; $::kit_conf = "kit.conf"; -$::current_dir = cwd(); -$::workdir = $::current_dir; +$::workdir = cwd(); $::full_buildkit_conf = $::workdir."/".$::buildkit_conf; $::build_dir = $::workdir."/build"; $::deploy_dir = $::build_dir; #kitname appended by validate_bldkitconf routine -$::base_repodir = $::build_dir."/kit_repodir"; %::buildkit_def = ( kit => { basename => { description=>'The kit base name (e.g., kit-lsf)', @@ -98,11 +96,6 @@ $::base_repodir = $::build_dir."/kit_repodir"; value_desc=>'Must be: Generic Name String', mandatory=>1, cp_to_kitconfig=>1}, - release => { - description=>'The kit release (e.g., 1)', - value_desc=>'Must be: Generic Name String', - mandatory=>0, - cp_to_kitconfig=>1}, ostype => { description=>'The kit OS type (e.g., Linux)', value_desc=>'Must be: OS Type String', @@ -172,12 +165,12 @@ $::base_repodir = $::build_dir."/kit_repodir"; version => { description=>'The component version (e.g., 9.0). It is used as the meta-package version.', value_desc=>'any string', - mandatory=>0, + mandatory=>1, cp_to_kitconfig=>1}, release => { description=>'The component release number (e.g., 1). It is used as the meta-package release number.', value_desc=>'any string', - mandatory=>0, + mandatory=>1, cp_to_kitconfig=>1}, serverroles => { description=>'tbd', @@ -317,8 +310,6 @@ if ( 'v|version' => \$::VERSION, 'V|verbose' => \$::VERBOSE, 'p|pkgdir=s' => \$::PKGDIR, - 'k|kitversion=s' => \$::KITVERSION, - 'r|kitrelease=s' => \$::KITRELEASE, ) ) { @@ -336,11 +327,7 @@ if ($::HELP) # display the version statement if -v or --version is specified if ($::VERSION) { - if ( system("rpm -q --qf \"%{NAME}: %{VERSION}-%{RELEASE} \n\" xCAT-buildkit") ) { - # non-zero return from system call - print "Error quering xCAT-buildkit rpm. Version info is not available. \n"; - exit 1; - } + print "The version option is not supported for this command. Query the xCAT-buildkit rpm for version information. \n"; exit 0; } @@ -350,12 +337,6 @@ if ( ! $arg ) { exit (0); } -my $debianflag = 0; -my $tempstring = xCAT::BuildKitUtils->osver(); -if ( $tempstring =~ /debian/ || $tempstring =~ /ubuntu/ ){ - $debianflag = 1; -} - while ($arg) { my $command = $arg; $command =~ tr/A-Z/a-z/; # convert to lowercase @@ -604,17 +585,15 @@ sub kit_buildrepo1 my $rc = 0; my $repoid = shift; $repoid =~ s/\s+//g; - my $repodir = $::base_repodir; + my $repodir = $::build_dir."/kit_repodir"; my $srcdir = $::workdir."/source_packages/"; my $basedir = $repodir; - my $repo; # find the repo my $found = 0; foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { if ( $kr->{kitrepoid} eq $repoid ) { $found = 1; - $repo = $kr; if ( &validate_os($kr)) { print "The buildrepo operation will continue, but errors may occur. You may need to run this command on a host with the same OS.\n"; } @@ -668,13 +647,9 @@ sub kit_buildrepo1 } + if ($::VERBOSE) { print "building kitpackage $kp->{filename} \n";} # determine build method - if ($kp->{isexternalpkg} eq 'yes') { - if ($::VERBOSE) { print "skipping build of external kitpackage $kp->{filename} \n";} - next; - } else { - if ($::VERBOSE) { print "building kitpackage $kp->{filename} \n";} - } + if ($kp->{isexternalpkg} eq 'yes') { next; } if (defined($kp->{rpm_prebuiltdir})) { # simply copy the file to the build directory my $full_prebuiltrpm = $srcdir.$kp->{rpm_prebuiltdir}."/".$kp->{filename}; @@ -713,55 +688,31 @@ sub kit_buildrepo1 } # Build kitcomponent metapackages - if ( $debianflag ){ - foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - if ($repoid ne $kc->{kitrepoid}) { next; } - my $debname = "$repodir/".&comppkgname($kc); - if (-r $debname) { next; } - if ($::VERBOSE) { print "building kitcomponent metapackage for $kc->{basename} \n";} - if (&build_kitcomp_debian($kc)) { - print "Error building kitcomponent metapackage for $kc->{basename} \n"; - return 1; - } - } - if ( system("dpkg-scanpackages $repodir > $repodir/Packages") ) { - print "Error building the repository meta-data with the dpkg-scanpackages command \n"; - return 1; - } - } - else{ - foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - # Check if this kitcomponent is in the requested repo - if ($repoid ne $kc->{kitrepoid}) { next; } + foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { + # Check if this kitcomponent is in the requested repo + if ($repoid ne $kc->{kitrepoid}) { next; } - # Check if already built - my $rpm = "$repodir/".&comppkgname($kc); - if (-r $rpm) { next; } + # Check if already built + my $rpm = "$repodir/".&comppkgname($kc); + if (-r $rpm) { next; } - # Build it - if ($::VERBOSE) { print "building kitcomponent metapackage for $kc->{basename} \n";} - if (&build_kitcomp($kc)) { - print "Error building kitcomponent metapackage for $kc->{basename} \n"; - return 1; - } - } - - # run createrepo - my $cr_opts = ''; - if (( $repo->{osbasename} =~ m/rh|RH/ ) && - ( $repo->{osmajorversion} eq '5') ) { - $cr_opts = '-s md5'; - } - if ( system("createrepo $cr_opts $repodir") ) { - print "Error building the repository meta-data with the createrepo command \n"; + # Build it + if ($::VERBOSE) { print "building kitcomponent metapackage for $kc->{basename} \n";} + if (&build_kitcomp($kc)) { + print "Error building kitcomponent metapackage for $kc->{basename} \n"; return 1; } } + + # run createrepo + if ( system("createrepo $repodir") ) { + print "Error building the repository meta-data with the createrepo command \n"; + return 1; + } + return 0; } - - #----------------------------------------------------------------------------- =head3 kit_listrepo @@ -803,18 +754,17 @@ sub kit_cleanrepo my $tmp_repoid = $repoid; $tmp_repoid =~ tr/A-Z/a-z/; # convert to lowercase - if (($tmp_repoid eq 'all') && - -d $::base_repodir ) { - if ( system("rm -Rf $::base_repodir ") ) { - print "Error removing contents of $::base_repodir \n"; + if (($tmp_repoid eq 'all') ) { + if ( system("rm -Rf $::build_dir/kit_repodir/* ") ) { + print "Error removing contents of $::build_dir/kit_repodir \n"; return 1; } else { - print "Contents of $::base_repodir has been successfully removed. \n"; + print "Contents of $::build_dir/kit_repodir has been successfully removed. \n"; } } else { foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { if ($repoid eq $kr->{kitrepoid}) { - my $repodir = $::base_repodir.'/'.$kr->{kitreponame}; + my $repodir = $::build_dir.'/kit_repodir/'.$kr->{kitreponame}; if ( -d $repodir ){ if ( system("rm -Rf $repodir ") ) { print "Error removing directory $repodir \n"; @@ -835,9 +785,6 @@ sub kit_cleanrepo if ( -d "$::workdir/tmp" ) { system("rm -Rf $::workdir/tmp "); } - if ( -d "$::workdir/debbuild" ){ - system("rm -Rf $::workdir/debbuild"); - } return 0; } @@ -855,6 +802,7 @@ sub kit_cleanrepo sub kit_buildtar { + foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { if (&validate_repo($kr)) { print "Kit Repository $kr->{kitrepoid} not built. Run: \n"; @@ -867,42 +815,33 @@ sub kit_buildtar return 1; } - if ($::HAVE_EXTERNAL_PKG or $::HAVE_NON_NATIVE_PKGS) { - if (&create_PARTIAL_builddir) { - print "Error creating PARTIAL kit build directory contents \n"; - return 1; - } - } else { - if (&create_builddir) { - print "Error creating kit build directory contents \n"; - return 1; - } + if (&create_builddir) { + print "Error creating kit build directory contents \n"; + return 1; } if (! -d "$::deploy_dir/repos") { symlink "$::build_dir/kit_repodir","$::deploy_dir/repos"; } + #Copy rpm spec to kit in case kitcomponent meta rpm is not built because of external non_native_pkgs + + # build the tarfile my $extpkgs = ''; - if ($::HAVE_EXTERNAL_PKG or $::HAVE_NON_NATIVE_PKGS) { - $extpkgs = '.NEED_PRODUCT_PKGS'; - } + if ($::HAVE_EXTERNAL_PKG or $::HAVE_NON_NATIVE_PKGS) { $extpkgs = '.NEED_PRODUCT_PKGS'; } my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; my $kitfilename = $kitname; if ( defined($::bldkit_config->{kit}{entries}[0]->{kittarfilename}) ) { $kitfilename = $::bldkit_config->{kit}{entries}[0]->{kittarfilename}; $kitfilename =~ s/tar\.bz2\s*$//; } - $kitfilename = $kitfilename.$extpkgs.".tar.bz2"; - my $tarfile = $::deploy_dir."/".$kitfilename; - if ( system("cd $::deploy_dir; cd ..; tar -cjhf $tarfile $kitname/*") ) { + my $tarfile = $::build_dir."/".$kitfilename.$extpkgs.".tar.bz2"; + if ( system("cd $::build_dir; tar -cjhf $tarfile $kitname/*") ) { print "Error building tarfile $tarfile \n"; return 1; } - system("mv $tarfile $::current_dir"); - print "Kit tar file $kitfilename successfully built \n"; - return 0; + print "Kit tar file $tarfile successfully built \n"; } @@ -925,7 +864,7 @@ sub kit_cleantar $kitfilename = $::bldkit_config->{kit}{entries}[0]->{kittarfilename}; $kitfilename =~ s/tar\.bz2\s*$//; } - my $tarfile = `find $::current_dir -name $kitfilename.*tar.bz2`; + my $tarfile = `find $::build_dir -name $kitfilename.*tar.bz2`; chomp ($tarfile); if ( -r $tarfile ) { if ( system("rm -f $tarfile ") ) { @@ -947,9 +886,6 @@ sub kit_cleantar if ( -d "$::workdir/tmp" ) { system("rm -Rf $::workdir/tmp "); } - if ( -d "$::workdir/debbuild" ){ - system("rm -Rf $::workdir/debbuild"); - } } @@ -983,9 +919,6 @@ sub kit_cleanall if ( -d "$::workdir/tmp" ) { system("rm -Rf $::workdir/tmp "); } - if ( -d "$::workdir/debbuild" ){ - system("rm -Rf $::workdir/debbuild"); - } } @@ -1034,9 +967,6 @@ sub edit_bldkitconf s/<<>>/$osminorversion/; s/<<>>/$osarch/; s/<<>>/$kitcomponent_basename/; - if ($debianflag){ - s/(filename=.*?)\-(.*)\.noarch\.rpm/$1_$2_all.deb/; - } } # Write the buildkit.conf back out @@ -1123,7 +1053,7 @@ sub load_bldkitconf $val =~ s/\s*$//; if ( defined( $::buildkit_def{$current_section}{$attr} ) ) { - if ( $val ne '') { $current_entry{$attr} = $val; } + $current_entry{$attr} = $val; } else { if ( $current_section eq 'no section' ) { $syntax_error = "No section specified for attribute $attr."; @@ -1215,9 +1145,6 @@ sub validate_bldkitconf my $kitname = $::bldkit_config->{kit}{entries}[0]->{basename}; my $full_kitname = $kitname; $full_kitname .= '-'.$::bldkit_config->{kit}{entries}[0]->{version}; - if (defined($::bldkit_config->{kit}{entries}[0]->{release})) { - $full_kitname .= '-'.$::bldkit_config->{kit}{entries}[0]->{release}; - } $full_kitname .= '-'.$::bldkit_config->{kit}{entries}[0]->{ostype}; $::bldkit_config->{kit}{entries}[0]->{kitname} = $full_kitname; $::deploy_dir .= "/".$full_kitname; @@ -1259,23 +1186,6 @@ sub validate_bldkitconf } } - # Kitcomponent version/release are now optional - - # default to kit version/release - foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - if (! defined($kc->{version})) { - $kc->{version} = $::bldkit_config->{kit}{entries}[0]->{version}; - } - if (! defined($kc->{release})) { - if (! defined($::bldkit_config->{kit}{entries}[0]->{release})) { - print "Kitcomponent $kc->{basename} does not have a release specified and there is no Kit release value set to use as a default. \n"; - return 1; - } else { - $kc->{release} = $::bldkit_config->{kit}{entries}[0]->{release}; - } - } - - } - # Make sure each kitcomponent has unique basename/repoid # If same basename, make sure version/release are same, too my $kc_count = scalar @{$::bldkit_config->{kitcomponent}{entries}}; @@ -1320,12 +1230,6 @@ sub validate_bldkitconf # Make sure all kitcomponent kitrepoids are defined my $found = 0; my %repo; - if ($debianflag){ - if ($kc->{basename} =~ /_/){ - print "Kit Component basename can not contain underscore.\n"; - return 1; - } - } foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { if ($kc->{kitrepoid} eq $kr->{kitrepoid}) { $found = 1; @@ -1468,12 +1372,6 @@ sub validate_bldkitconf } } } - if (defined($kc->{non_native_pkgs})){ - if ($kc->{non_native_pkgs} =~ /EXTERNALPKGS/) { - $::NON_NATIVE_PKGS->{$kc->{kitcompname}} = 1; - $::HAVE_NON_NATIVE_PKGS = 1; - } - } } # Kitpackage checks @@ -1555,50 +1453,48 @@ sub validate_bldkitconf } } $kp->{kitreponame} =~ s/^,//; - if (!$::NEW_PARTIAL_KIT) { - # Make sure files exist - if (defined($kp->{rpm_spec})){ - my $ck_file = $::workdir."/source_packages/".$kp->{rpm_spec}; - if (! -r $ck_file ) { - print "RPM spec file $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; - return 1; - } - } - if (defined($kp->{rpm_srcdir})){ - my $ck_dir = $::workdir."/source_packages/".$kp->{rpm_srcdir}; - if (! -d $ck_dir ) { - print "RPM source directory $ck_dir defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; - return 1; - } - } - if (defined($kp->{rpm_srctarball})){ - my $ck_file = $::workdir."/source_packages/".$kp->{rpm_srctarball}; - if (! -r $ck_file ) { - print "RPM source tarfile $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; - return 1; - } - } - if (defined($kp->{rpm_srpm})){ - my $ck_file = $::workdir."/source_packages/".$kp->{rpm_srpm}; - if (! -r $ck_file ) { - print "Source RPM $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; - return 1; - } - } - if (defined($kp->{rpm_prebuiltdir})){ - my $ck_dir = $::workdir."/source_packages/".$kp->{rpm_prebuiltdir}; - if (! -d $ck_dir ) { - print "Pre-built RPM directory $ck_dir defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; - return 1; - } - my $ck_file = $ck_dir."/".$kp->{filename}; - if ( system("ls $ck_file > /dev/null") ) { -# if (! -r $ck_file ) { - print "Pre-built rpm $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; - return 1; - } - } + # Make sure files exist + if (defined($kp->{rpm_spec})){ + my $ck_file = $::workdir."/source_packages/".$kp->{rpm_spec}; + if (! -r $ck_file ) { + print "RPM spec file $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; } + } + if (defined($kp->{rpm_srcdir})){ + my $ck_dir = $::workdir."/source_packages/".$kp->{rpm_srcdir}; + if (! -d $ck_dir ) { + print "RPM source directory $ck_dir defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kp->{rpm_srctarball})){ + my $ck_file = $::workdir."/source_packages/".$kp->{rpm_srctarball}; + if (! -r $ck_file ) { + print "RPM source tarfile $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kp->{rpm_srpm})){ + my $ck_file = $::workdir."/source_packages/".$kp->{rpm_srpm}; + if (! -r $ck_file ) { + print "Source RPM $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } + if (defined($kp->{rpm_prebuiltdir})){ + my $ck_dir = $::workdir."/source_packages/".$kp->{rpm_prebuiltdir}; + if (! -d $ck_dir ) { + print "Pre-built RPM directory $ck_dir defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + my $ck_file = $ck_dir."/".$kp->{filename}; + if ( system("ls $ck_file > /dev/null") ) { +# if (! -r $ck_file ) { + print "Pre-built rpm $ck_file defined in Kit Package \"$kp->{filename}\" does not exist or is not readable\n"; + return 1; + } + } } #use Data::Dumper; #print Dumper($::bldkit_config->{kitrepo}); @@ -1624,16 +1520,9 @@ sub comppkgname # my $repo = shift; my $pkgname = $comp->{basename}; - if ($debianflag) { - $pkgname .= '_'.$comp->{version}; - $pkgname .= '-'.$comp->{release}; - $pkgname .= '_all.deb'; - } - else{ - $pkgname .= '-'.$comp->{version}; - $pkgname .= '-'.$comp->{release}; - $pkgname .= '.noarch.rpm'; - } + $pkgname .= '-'.$comp->{version}; + $pkgname .= '-'.$comp->{release}; + $pkgname .= '.noarch.rpm'; # $pkgname .= '-'.$repo->{osmajorversion}; # if (defined($repo->{osminorversion})) { # $pkgname .= '.'.$repo->{osminorversion}; @@ -1665,7 +1554,7 @@ sub validate_repo { my $repo = shift; - my $repodir = $::base_repodir."/".$repo->{kitreponame}; + my $repodir = $::build_dir."/kit_repodir/".$repo->{kitreponame}; if ( ! -d $repodir ) { if ($::VERBOSE) { print "\n$repodir does not exist. No rpms have been built for this kitrepo. \n"; @@ -1673,28 +1562,29 @@ sub validate_repo return 1; } - # Make sure each repo pkg exists foreach my $pkg (@{$repo->{packages}}){ - # skip check for kit component meta rpm if it includes - # external non-native pkgs - my $skip_check = 0; foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { if ($repo->{kitrepoid} eq $kc->{kitrepoid}) { my $kitpkgname = comppkgname($kc); - if (($kitpkgname eq $pkg) && - ($::NON_NATIVE_PKGS->{$kc->{kitcompname}}) ) { - $skip_check = 1; - last; + if ($kitpkgname ne $pkg) { + next; } - } - } - if ( ! $skip_check ) { - my $pkg_filename = $repodir.'/'.$pkg; - if ( system("ls $pkg_filename > /dev/null") ) { - if ($::VERBOSE) { - print "\nFile $pkg in directory $repodir does not exist or is not readable. \n"; + if ($kc->{non_native_pkgs} =~ /EXTERNALPKGS/) { + $::NON_NATIVE_PKG->{$kc->{kitcompname}} = 1; + last; } - return 1; + + my $pkg_filename = $repodir.'/'.$pkg; + + if ( system("ls $pkg_filename > /dev/null") ) { + + if ($::VERBOSE) { + print "\nFile $pkg in directory $repodir does not exist or is not readable. \n"; + } + return 1; + } + + } } } @@ -1806,19 +1696,7 @@ sub build_kitcomp my %repo; my $rpmbuild_dir = $::workdir."/rpmbuild"; my $tmpdir = $::workdir."/tmp/$comp->{kitcompname}"; - my $kcmetaname = comppkgname($comp); - # If this kitcomponent has external non-native pkgs, - # skip the meta rpm build - if ( defined($::NON_NATIVE_PKGS) && - defined($::NON_NATIVE_PKGS->{$comp->{kitcompname}}) && - $::NON_NATIVE_PKGS->{$comp->{kitcompname}} ) { - if ($::VERBOSE) { - print "Kit component $comp->{kitcompname} has external non-native packages. Skipping rpm build for $kcmetaname. \n"; - } - return 0; - } - # find the kitrepo hash for this component foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { if ($comp->{kitrepoid} eq $kr->{kitrepoid}) { @@ -1826,12 +1704,6 @@ sub build_kitcomp last; } } - my $repodir = $::base_repodir."/".$repo{kitreponame}; - - # Fix the kitpkgdeps value for this kitcomponent - # For any kitpkgdep that has an rpm file in the repo, - # specifically reference it's version-release - if ( &update_kitcomp_kitpkgdeps($comp,$repodir) ) { return 1; } # Create spec file for this kit component if ( &gen_kitcomp_spec($comp,\%repo) ) { return 1; } @@ -1853,6 +1725,7 @@ sub build_kitcomp # Read the kit component meta rpm name + my $kcmetaname = comppkgname($comp); my $specfile = $::workdir."/tmp/$comp->{kitcompname}.spec"; my $rpmbuild_cmd = "rpmbuild --define \"_topdir $rpmbuild_dir\" -ba $specfile"; @@ -1863,11 +1736,14 @@ sub build_kitcomp mkpath("$rpmbuild_dir/SOURCES"); my $sourcedir = $::workdir."/source_packages"; + if ($comp->{non_native_pkgs} =~ /EXTERNALPKGS/) { + $::NON_NATIVE_PKGS->{$comp->{kitcompname}}{$kcmetaname} = 1; + } foreach my $pkgfile (split(/,/, $comp->{non_native_pkgs})) { my $pkg_file; my ($key,$value) = split /:/,$pkgfile; if ("$key" =~ /EXTERNALPKGS/) { - $pkg_file = $value; + next; } else { $pkg_file = $key; } @@ -1878,92 +1754,36 @@ sub build_kitcomp return 1; } } - $cmd = "cd $tmpdir/..;mv $comp->{kitcompname} $comp->{basename}; tar -czf $rpmbuild_dir/SOURCES/$comp->{basename}.tar.gz $comp->{basename};mv $comp->{basename} $comp->{kitcompname}"; - if ( system($cmd) ) { - print "Error creating tarfile $rpmbuild_dir/SOURCES/$comp->{kitreponame}-$comp->{kitcompname}.tar from $sourcedir/*"; - return 1; + if ( !$::NON_NATIVE_PKGS->{$comp->{kitcompname}}{$kcmetaname} ) { + $cmd = "cd $tmpdir/..;mv $comp->{kitcompname} $comp->{basename}; tar -czf $rpmbuild_dir/SOURCES/$comp->{basename}.tar.gz $comp->{basename};mv $comp->{basename} $comp->{kitcompname}"; + if ( system($cmd) ) { + print "Error creating tarfile $rpmbuild_dir/SOURCES/$comp->{kitreponame}-$comp->{kitcompname}.tar from $sourcedir/*"; + return 1; + } } } if (!$::VERBOSE) { $rpmbuild_cmd .= ' --quiet '; } - if ( system($rpmbuild_cmd) ) { - print "Error running rpmbuild command for kit component $comp->{kitcompname} meta package\n"; - return 1; - } - my @built_rpms = `find $rpmbuild_dir/RPMS -name *.rpm`; - foreach my $rpm (@built_rpms) { - chomp($rpm); - if ( system ("cp -fp $rpm $repodir") ) { - print "Error copying rpm $rpm to build repo directory $repodir \n"; + if ( !$::NON_NATIVE_PKGS->{$comp->{kitcompname}}{$kcmetaname} ) { + if ( system($rpmbuild_cmd) ) { + print "Error running rpmbuild command for kit component $comp->{kitcompname} meta package\n"; return 1; } - } - - return 0; -} - -#----------------------------------------------------------------------------- - -=head3 update_kitcomp_kitpkgdeps - - Update the kitcomponent kitpkgdeps string - For any kitpkgdep that does not explicitly specify a version-release - comparison string and for which an rpm exists in the repo, - query the rpm for its version-release info and set an explicit - comparison string. - Reason we need to do all this: We need to force yum/zypper to update - the product rpms. A simple package name in the kitcomponent meta rpm - REQUIRES entry will not cause the product to get updated if an older - version is already installed. Need to explicitly require this version - and release of the product package. - input: kitcomponent hash - kitrepo directory - -=cut - -#----------------------------------------------------------------------------- - -sub update_kitcomp_kitpkgdeps - -{ - my $comp = shift; - my $repodir = shift; - - if (defined($comp->{kitpkgdeps})) { - my $new_kitpkgdeps = ''; - foreach my $d (split(/,/, $comp->{kitpkgdeps})) { - $d =~ s/\s+//g; - my $d_short = $d; - $d_short =~ s/^([\w\.\-]+)[<>=]*.*$/$1/; - if ( $d_short eq $d ) { - # no version-release comparisons specified for this kitpkgdep - # do we have an rpm file in the repo? - my $cmd = "rpm -q --qf \"%{NAME} >= %{VERSION}-%{RELEASE},\" -p $repodir/$d-*.rpm 2>/dev/null"; - if ($::VERBOSE) { - print "running rpm query to get version-release info: \n $cmd \n"; + my $repodir = $::build_dir."/kit_repodir/".$repo{kitreponame}; + my @built_rpms = `find $rpmbuild_dir/RPMS -name *.rpm`; + foreach my $rpm (@built_rpms) { + chomp($rpm); + if ( system ("cp -fp $rpm $repodir") ) { + print "Error copying rpm $rpm to build repo directory $repodir \n"; + return 1; } - my $new_d = `$cmd`; - chomp($new_d); - if ($::VERBOSE) { - print "output: \n \'$new_d\' \n"; - } - if ( $new_d ne '' ) { - $new_kitpkgdeps .= "$new_d,"; - } else { - $new_kitpkgdeps .= "$d,"; - } - } else { - $new_kitpkgdeps .= "$d,"; } - } - $new_kitpkgdeps =~ s/(\,)*$//; - $comp->{kitpkgdeps} = $new_kitpkgdeps; } + return 0; } - #----------------------------------------------------------------------------- =head3 gen_kitcomp_spec @@ -2068,207 +1888,6 @@ sub gen_kitcomp_spec return 0; } -#----------------------------------------------------------------------------- - -=head3 build_kitcomp_debian - - - -=cut - -#----------------------------------------------------------------------------- -sub build_kitcomp_debian{ - my $comp = shift; - my %repo; - my $debbuilddir = $::workdir."/debbuild/".$comp->{kitcompname}; - - # find the kitrepo hash for this component - foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { - if ($comp->{kitrepoid} eq $kr->{kitrepoid}) { - %repo = %{$kr}; - last; - } - } - - #run the dpkg-buildpackage command - my $curdir = $::workdir; - my $cmd = "rm -Rf $debbuilddir"; - system($cmd); - mkpath($debbuilddir); - - #Create debian directory for this kit component - if ( &gen_kitcomp_debdir($comp,\%repo) ) { return 1; } - - my $kcmetaname = comppkgname($comp); - - if (defined($comp->{non_native_pkgs}) ) { - my $sourcedir = $::workdir."/source_packages"; - - if ($comp->{non_native_pkgs} =~ /EXTERNALPKGS/) { - $::NON_NATIVE_PKGS->{$comp->{kitcompname}} = 1; - } - foreach my $pkgfile (split(/,/, $comp->{non_native_pkgs})) { - my $pkg_file; - my ($key,$value) = split /:/,$pkgfile; - if ("$key" =~ /EXTERNALPKGS/) { - next; - } else { - $pkg_file = $key; - } - - $cmd = "cp -p $sourcedir/$pkg_file $debbuilddir"; - if ( system($cmd) ) { - print "Error copying non-native package file $sourcedir/$pkg_file to debbuilddir\n"; - return 1; - } - } - } - my $compversion = $comp->{version} . "-" . $comp->{release}; - my $buildstring = "Kit component build package."; - my $debianbuildcmd = "cd $debbuilddir;dch -v $compversion -b -c debian/changelog $buildstring;dpkg-buildpackage -uc -us"; - if ( !$::NON_NATIVE_PKGS->{$comp->{kitcompname}} ) { - if ( system($debianbuildcmd) ) { - print "Error running \"dpkg-buildpackage -uc -us\" command for kit component $comp->{kitcompname} meta package\n"; - return 1; - } - my $repodir = $::base_repodir."/".$repo{kitreponame}; - my @builtdebs = `find $::workdir/debbuild -maxdepth 1 -name *.deb`; - foreach my $deb (@builtdebs) { - chomp($deb); - if ( system ("cp -fp $deb $repodir") ) { - print "Error copying package $deb to build repo directory $repodir \n"; - return 1; - } - } - } - return 0; -} - -#----------------------------------------------------------------------------- - -=head3 gen_kitcomp_debdir - - - -=cut - -#----------------------------------------------------------------------------- -sub gen_kitcomp_debdir{ - my $comp = shift; - my $repo = shift; - my $scriptdir = $::workdir."/scripts/"; - my $combuilddir = $::workdir."/debbuild/".$comp->{kitcompname}; - - #copy the debian dir template to the build path - mkpath("$combuilddir/debian"); - my $cmd = "cp -Rf " . $::XCATSHARE . "/kits/debian_template/* $combuilddir/debian/"; - system($cmd); - - my $kitname = $::bldkit_config->{kit}{entries}[0]->{basename}; - my $kitcompname = $comp->{kitcompname}; - my $upgradeflag = $comp->{basename} . ".tmp"; - - my ($prescript,$postscript,$preupscript,$postupscript,$preunscript,$postunscript,$nonnativepkgs) = ''; - if (defined($comp->{preinstall})) { - $prescript = &load_script("$scriptdir$comp->{preinstall}"); - } - if (defined($comp->{postinstall})) { - $postscript = &load_script("$scriptdir$comp->{postinstall}"); - } - if (defined($comp->{preupgrade})) { - $preupscript = &load_script("$scriptdir$comp->{preupgrade}"); - } - if (defined($comp->{postupgrade})) { - $postupscript = &load_script("$scriptdir$comp->{postupgrade}"); - } - if (defined($comp->{preuninstall})) { - $preunscript = &load_script("$scriptdir$comp->{preuninstall}"); - } - if (defined($comp->{postuninstall})) { - $postunscript = &load_script("$scriptdir$comp->{postuninstall}"); - } - if (defined($comp->{non_native_pkgs})) { - $nonnativepkgs = '\n'; - $nonnativepkgs .= "mkdir -p \$RPM_BUILD_ROOT/opt/xcat/kits/$kitname/$kitcompname \n"; - $nonnativepkgs .= "cp -a * \$RPM_BUILD_ROOT/opt/xcat/kits/$kitname/$kitcompname \n"; - } - - #replace all special sub string in all files under debian - unless (opendir(DH, "${combuilddir}/debian/")){ - print "Can not open the xCAT Kit Component debian dir: ${combuilddir}/debian/"; - return 1; - } - - foreach (readdir(DH)){ - my $file = "${combuilddir}/debian/$_"; - if ( -d $file){ - next; - } - - unless ( open ( FH, "<", $file )){ - print "Error attempting to open the xCAT Kit Component ${kitcompname}'s debian template file $file.\n"; - close(DH); - return 1; - } - - if ($::VERBOSE){ - print "Reading the xCAT Kit Component ${kitcompname}'s debian template file $file. \n"; - } - my @lines = ; - close(FH); - for(@lines) { - chomp; - s/<<>>/$comp->{basename}/; - s/<<>>/$comp->{ospkgdeps}/; - s/<<>>/$comp->{kitpkgdeps}/; - s/<<>>/$comp->{kitcompdeps}/; - s/<<>>/$comp->{description}/; - s/<<>>/$upgradeflag/; - s/<<>>/$prescript/; - s/<<>>/$postscript/; - s/<<>>/$preupscript/; - s/<<>>/$postupscript/; - s/<<>>/$preunscript/; - s/<<>>/$postunscript/; - } - my $joined_lines = join("\n", @lines); - @lines = split(/\\n/,$joined_lines); - - open (FH, ">", $file); - if ($::VERBOSE){ - print "Created kitcomponent ${kitcompname}'s build file under debian dir $file"; - } - print FH @lines; - close(FH); - } - closedir(DH); - - if (defined($comp->{non_native_pkgs})) { - unless (open (FH, ">", "${combuilddir}/debian/dir")) { - print "Error attempting to open the xCAT Kit Component ${kitcompname}'s debian file dir.\n"; - return 1; - } - print FH "opt/xcat/kits/$kitname/$kitcompname/"; - close (FH); - - unless ( open (FH, ">", "${combuilddir}/debian/install") ){ - print "Error attempting to open the xCAT Kit Component ${kitcompname}'s debian file dir.\n"; - return 1; - } - foreach my $pkgfile (split(/,/, $comp->{non_native_pkgs})) { - my $pkgname = ''; - my ($key,$value) = split /:/,$pkgfile; - if ("$key" =~ /EXTERNALPKGS/) { - $pkgname = $value; - } else { - $pkgname = $key; - } - print FH "$pkgname opt/xcat/kits/$kitname/$kitcompname/ \n"; - } - close(FH); - } - return 0; -} #----------------------------------------------------------------------------- @@ -2337,17 +1956,14 @@ sub create_kitconf $d =~ s/^([\w\.\-]+)[<>=]*.*$/$1/; $value .= "$d,"; } - $value =~ s/(\,)*$//; + $value =~ s/,$//; $se->{$a} = $value; } } $::kit_config->{$s}{entries}[$li]->{$a} = $se->{$a}; } - # cp_to_kitconfig=2 means copy the file to the new kit - # but only do the copy if this is a final kit build if (( $::buildkit_def{$s}{$a}->{cp_to_kitconfig} eq '2' ) && - ( defined ($se->{$a}) ) && - !$::HAVE_EXTERNAL_PKG && !$::HAVE_NON_NATIVE_PKGS ) { + ( defined ($se->{$a}) ) ) { my $prefix = "$kitname"; if ( $s eq 'kitcomponent' ) { $prefix = "$::bldkit_config->{$s}{entries}[$li]->{kitcompname}"; @@ -2355,19 +1971,14 @@ sub create_kitconf ($a eq 'genimage_postinstall')) { $prefix = "KIT_".$prefix; } - if ( !($::kit_config->{$s}{entries}[$li]->{$a} = - &cp_to_builddir($a,$se->{$a},$::workdir.'/'.$::buildkit_def{$s}{$a}->{base_dir},$prefix, $::bldkit_config->{$s}{entries}[$li])) ) { - return 1; - } - } else { - if ( !($::kit_config->{$s}{entries}[$li]->{$a} = + } + if ( !($::kit_config->{$s}{entries}[$li]->{$a} = &cp_to_builddir($a,$se->{$a},$::workdir.'/'.$::buildkit_def{$s}{$a}->{base_dir},$prefix)) ) { - return 1; - } + return 1; } } } - # Handle special attrs, these 3 attributes did not defined in the buildkit.conf, special cases. + # Handle special attrs if ( $s eq 'kitrepo' ) { $::kit_config->{$s}{entries}[$li]->{kitreponame} = $se->{kitreponame}; @@ -2396,21 +2007,19 @@ sub create_kitconf # Handle non_native_pkgs foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - if ($::NON_NATIVE_PKGS->{$kc->{kitcompname}}) { - my @nativefiles; + if ($kc->{non_native_pkgs} =~ /EXTERNALPKGS/) { foreach my $pkgfile (split(/,/, $kc->{non_native_pkgs})) { my ($key,$value) = split /:/,$pkgfile; if ("$key" =~ /EXTERNALPKGS/) { - push (@nativefiles, $value); + $::HAVE_NON_NATIVE_PKGS = 1; + my %current_entry; + $current_entry{filename} = $value; + $current_entry{kitcompname} = $kc->{kitcompname}; + $current_entry{basename} = $kc->{basename}; + $current_entry{kitreponame} = $kc->{kitreponame}; + push ( @{ $::kit_config->{NONNATIVEPKGS}{'entries'} }, {%current_entry}); } } - - my %current_entry; - $current_entry{filename} = join ',', @nativefiles; - $current_entry{kitcompname} = $kc->{kitcompname}; - $current_entry{basename} = $kc->{basename}; - $current_entry{kitreponame} = $kc->{kitreponame}; - push ( @{ $::kit_config->{NONNATIVEPKGS}{'entries'} }, {%current_entry}); } } @@ -2419,9 +2028,7 @@ sub create_kitconf my @lines; my $li=0; $lines[$li++] = "# Kit Configuration File for $kitname generated by buildkit\n"; - my $xCAT_buildkit_version = `rpm -q --qf \"%{VERSION}-%{RELEASE}\" xCAT-buildkit`; - $lines[$li++] = "# kit_built_by_xCAT_version: $xCAT_buildkit_version \n"; - $lines[$li++] = "# kit_built_on: ".localtime()."\n"; + $lines[$li++] = "# ".localtime()."\n"; foreach my $s ('kit','kitrepo','kitcomponent','EXTERNALPKG', 'NONNATIVEPKGS') { foreach my $se (@{$::kit_config->{$s}{entries}}) { $lines[$li++] = "$s: \n"; @@ -2457,7 +2064,6 @@ sub create_kitconf =head3 cp_to_builddir Copy specified files into the build directory renaming as indicated - and substituting strings if needed =cut @@ -2471,7 +2077,6 @@ sub cp_to_builddir my $files = shift; my $from_dir = shift; my $prefix = shift; - my $kitcomp = shift; my $copied_files; my $other_files = $::deploy_dir."/other_files"; @@ -2485,42 +2090,14 @@ sub cp_to_builddir my $from_file_base = basename($file); my $to_file_base = $prefix."_".$from_file_base; my $to_file = $other_files."/".$to_file_base; - - # Read in the file - my $FF; - unless ( open( $FF, "<", $from_file ) ) { - print "The Kit file $from_file could not be read. \n"; - return 1; - } - my @lines = <$FF>; - for (@lines) { - s/<<>>/$::bldkit_config->{kit}{entries}[0]->{kitname}/g; - s/<<>>/$::bldkit_config->{kit}{entries}[0]->{basename}/g; - s/<<>>/$::bldkit_config->{kit}{entries}[0]->{version}/g; - s/<<>>/$::bldkit_config->{kit}{entries}[0]->{release}/g; - if ( defined ($kitcomp) ) { - s/<<>>/$kitcomp->{kitcompname}/g; - s/<<>>/$kitcomp->{basename}/g; - s/<<>>/$kitcomp->{version}/g; - s/<<>>/$kitcomp->{release}/g; - } - } - # Write the file back out - my $TF; - unless ( open( $TF, ">$to_file" ) ) { + if ( system("cp -fp $from_file $to_file") ) { + # non-zero return from system call print "Error copying file $from_file to build directory $other_files \n"; - return 1; - } - if ($::VERBOSE) { - print "Copied $from_file to $to_file replacing kit and kitcomponent strings as needed. \n"; - } - print $TF @lines; - close($TF); - + return; + } $copied_files .= ",$to_file_base"; - if (($type eq 'postbootscripts') || - ($type eq 'genimage_postinstall')) { + if ($type eq 'postbootscripts') { system("chmod 755 $to_file"); } } @@ -2587,148 +2164,27 @@ sub create_builddir if (&edit_deployparams($kd_file)) { return 1;} } - if ($::HAVE_EXTERNAL_PKG or $::HAVE_NON_NATIVE_PKGS) { - # Copy the kitcomponent meta rpm spec if there is external non_native_pkgs. - if ( $debianflag ) { - foreach my $comp (keys %{$::NON_NATIVE_PKGS}) { - my $kitrepo; - foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - if ($comp eq $kc->{kitcompname}) { - $kitrepo = $kc->{kitreponame} - } - } - mkpath("$::deploy_dir/tmp/"); - my $cmd = "cp -fRP $::workdir/debbuild/$comp $::deploy_dir/tmp/$comp"; - if ( system("$cmd") ) { - print "Error copying kitcomponent meta debian build file $::workdir/debbuild/$comp to build directory $::deploy_dir \n"; - return 1; - } - } - } - - # Copy over the original buildkit.conf file and input files - # to help make addpkgs processing easier later - mkpath("$::deploy_dir/build_input/"); - if ( system("cp -fp $::full_buildkit_conf $::deploy_dir/build_input") ) { - # non-zero return from system call - print "Error copying buildkit config file $::full_buildkit_conf to build directory $::deploy_dir/build_input \n"; - return 1; - } - if ( system("cp -fpR $::full_buildkit_conf $::deploy_dir/build_input") ) { - # non-zero return from system call - print "Error copying buildkit config file $::full_buildkit_conf to build directory $::deploy_dir/build_input \n"; - return 1; - } - } - - return 0; - -} - - -#----------------------------------------------------------------------------- - -=head3 create_PARTIAL_builddir - - Create the build directory for a PARTIAL kit (needs external pkgs) - and copy in all required files for building the kit tar file. - This includes most build input without editting files since - they will need to be generated at addpkgs time. - -=cut - -#----------------------------------------------------------------------------- - -sub create_PARTIAL_builddir - -{ - my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; - - # Note: - # - repos already created and validated - # - kit.conf file already created - # - exlists, postbootscripts, and deployparams already copied - - # copy docs to build dir - if ( -d "$::workdir/docs" ) { - if ( system("cp -fRp $::workdir/docs $::deploy_dir") ) { - # non-zero return from system call - print "Error copying doc files $::workdir/docs to build directory $::deploy_dir \n"; - return 1; - } - } - # Copy the kitcomponent meta rpm spec if there is external non_native_pkgs. - if ( $debianflag ) { - foreach my $comp (keys %{$::NON_NATIVE_PKGS}) { - my $kitrepo; - foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - if ($comp eq $kc->{kitcompname}) { - $kitrepo = $kc->{kitreponame} - } - } - mkpath("$::deploy_dir/tmp/"); - my $cmd = "cp -fRP $::workdir/debbuild/$comp $::deploy_dir/tmp/$comp"; - if ( system("$cmd") ) { - print "Error copying kitcomponent meta debian build file $::workdir/debbuild/$comp to build directory $::deploy_dir \n"; - return 1; + foreach my $comp (keys %{$::NON_NATIVE_PKG}) { + my $kitrepo; + foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { + if ($comp eq $kc->{kitcompname}) { + $kitrepo = $kc->{kitreponame} } } + mkpath("$::deploy_dir/tmp/"); + my $cmd = "cp -fRp $::workdir/tmp/$comp.spec $::deploy_dir/tmp/$comp.spec"; + if ( system("$cmd") ) { + print "Error copying kitcomponent spec $::workdir/tmp/$kitrepo-$comp.spec to build directory $::deploy_dir \n"; + return 1; + } + $cmd = "cp -fRp $::workdir/tmp/$comp $::deploy_dir/tmp/$comp"; + if ( system("$cmd") ) { + print "Error copying kitcomponent meta rpm build file $::workdir/tmp/$kitrepo-$comp to build directory $::deploy_dir \n"; + return 1; + } } - # Copy over the original buildkit.conf file and input files - # to help make addpkgs processing easier later - mkpath("$::deploy_dir/build_input/"); - if ( system("cp -fp $::full_buildkit_conf $::deploy_dir/build_input") ) { - # non-zero return from system call - print "Error copying buildkit config file $::full_buildkit_conf to build directory $::deploy_dir/build_input \n"; - return 1; - } - if ( -d "$::workdir/other_files" ) { - if ( system("cp -fpR $::workdir/other_files $::deploy_dir/build_input") ) { - # non-zero return from system call - print "Error copying $::workdir/otherfiles to build directory $::deploy_dir/build_input \n"; - return 1; - } - } - if ( -d "$::workdir/plugins" ) { - if ( system("cp -fpR $::workdir/plugins $::deploy_dir/build_input") ) { - # non-zero return from system call - print "Error copying $::workdir/plugins to build directory $::deploy_dir/build_input \n"; - return 1; - } - } - if ( -d "$::workdir/scripts" ) { - if ( system("cp -fpR $::workdir/scripts $::deploy_dir/build_input") ) { - # non-zero return from system call - print "Error copying $::workdir/scripts to build directory $::deploy_dir/build_input \n"; - return 1; - } - } - # Copy over any provided non-native packages - my $to_source_dir = "$::deploy_dir/build_input/source_packages"; - mkpath("$to_source_dir"); - foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - if (defined($kc->{non_native_pkgs}) ) { - my $sourcedir = $::workdir."/source_packages"; - foreach my $pkgfile (split(/,/, $kc->{non_native_pkgs})) { - my $pkg_file; - my ($key,$value) = split /:/,$pkgfile; - if ("$key" =~ /EXTERNALPKGS/) { - next; - } else { - $pkg_file = $key; - } - - my $cmd = "cp -p $sourcedir/$pkg_file $to_source_dir"; - if ( system($cmd) ) { - print "Error copying non-native package file $sourcedir/$pkg_file to $to_source_dir \n"; - return 1; - } - } - } - } - return 0; @@ -2838,10 +2294,6 @@ sub edit_plugin { my $file = shift; my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; - # convert dashes to underscore since the kitname is used as perl pkg names - # in the plugin and this causes perl syntax errors - $kitname =~ s/\-/\_/g; - $kitname =~ s/\./\_/g; # read in the file my $PF; @@ -2890,9 +2342,7 @@ sub kit_addpkgs my $kitbfname = basename($kittarfile); $kitbfname =~ s/.tar.bz2$//; $kitbfname =~ s/.NEED_PRODUCT_PKGS$//; - my $tmpdir_base = "/tmp/buildkit_workdir/$kitbfname"; - # Cleanup - system ("rm -Rf /tmp/buildkit_workdir/$kitbfname"); + my $tmpdir = "/tmp/buildkit_workdir/$kitbfname"; if ( !(-r $kittarfile) ) { print "The Kit tar file $kittarfile could not be read. \n"; @@ -2905,32 +2355,20 @@ sub kit_addpkgs } # Create work directory - if ( (! -d $tmpdir_base) && (! mkpath($tmpdir_base)) ) { - print "Error creating temporary work directory $tmpdir_base\n"; + if ( (! -d $tmpdir) && (! mkpath($tmpdir)) ) { + print "Error creating temporary work directory $tmpdir\n"; return 1; } - if ( system("cd $tmpdir_base; tar -jxf $kittarfile ") ) { + if ( system("cd $tmpdir; tar -jxf $kittarfile ") ) { print "Error extracting tarfile $kittarfile \n"; # Cleanup system ("rm -Rf /tmp/buildkit_workdir"); return 1; } - my $tmp_kit_conf = `find $tmpdir_base -name kit.conf`; + + my $tmp_kit_conf = `find $tmpdir -name kit.conf`; chomp($tmp_kit_conf); - my $tmpdir = dirname($tmp_kit_conf); - - ### Check if this is a new partial kit built with xCAT 2.8.1 or newer - if (-d "$tmpdir/build_input") { - system ("mv $tmpdir/build_input $tmpdir_base"); - return &NEW_kit_addpkgs($tmpdir_base,$tmpdir); - } - - if (defined($::KITVERSION) || defined($::KITRELEASE)) { - print "kitversion and kitrelease substitution is not supported for this incomplete kit. Run \"buildkit addpkgs\" without the \"-k|--kitversion\" and \"-r| --kitrelease\" options. \n"; - exit 1; - } - # read in the file my $CKF; unless ( open( $CKF, "<", $tmp_kit_conf ) ) { @@ -3017,7 +2455,7 @@ sub kit_addpkgs return 1; } foreach my $repo (split(/,/, $ext_reponames)) { - my $repodir = $tmpdir."/repos/".$repo; + my $repodir = $tmpdir."/".$kitname."/repos/".$repo; if ( ! -d ($repodir) && (! mkpath($repodir)) ) { print "Error creating repository directory $repodir\n"; # Cleanup @@ -3052,8 +2490,14 @@ sub kit_addpkgs && ($non_native_kitcompname ne '') && ($non_native_basename ne '') && ($non_native_kitreponame ne '')) { - #find out the useful dir - my $tdir = $tmpdir."/tmp/"; + my $fromfile = $rpmdir."/".$non_native_filename; + if ( system("ls $fromfile > /dev/null") ){ + print "The product package file $non_native_filename could not be read from the package directory $rpmdir. \n"; + system ("rm -Rf /tmp/buildkit_workdir"); + return 1; + } + + my $tdir = $tmpdir."/".$kitname."/tmp/"; my $source_dir = "$tdir/$non_native_kitcompname"; my $spec = "$tdir/$non_native_kitcompname.spec"; if (!-d "$tdir" or !-d "$source_dir") { @@ -3063,88 +2507,60 @@ sub kit_addpkgs return 1; } - #copy the nan_native_pkgs to the source dir - foreach my $tepmfilename (split(/,/, $non_native_filename)){ - #the $non_native_filename may contain several pkgs, can check and copy at the same time - my $fromfile = $rpmdir."/".$tepmfilename; - if ( system("ls $fromfile > /dev/null") ){ - print "The product package file $non_native_filename could not be read from the package directory $rpmdir. \n"; - system ("rm -Rf /tmp/buildkit_workdir"); - return 1; - } - if (system("cp -fp $fromfile $tdir/$non_native_kitcompname")) { - print "Error copying package file $fromfile to $tdir/$non_native_kitcompname \n"; - # Cleanup - system ("rm -Rf /tmp/buildkit_workdir"); - return 1; - } + if (!-r "$spec") { + print "Error open kitcomponent rpm build spec $tdir/$non_native_kitcompname.spec \n"; + # Cleanup + system ("rm -Rf /tmp/buildkit_workdir"); + return 1; } - #for debian/ubuntu - my $repodir = $tmpdir . "/repos/".$non_native_kitreponame; - if ( $debianflag ){ - my $debbuildcmd = "cd $source_dir;dpkg-buildpackage -uc -us"; - if ( system($debbuildcmd) ){ - print "error running debian build cmd for kit component $non_native_basename meta package.\n"; - return 1; - } - my @debs = `find $tdir -maxdepth 1 -name *.deb`; - foreach my $debname (@debs){ - chomp($debname); - if ( system("mv -f $debname $repodir") ){ - print "Error copying package $debname to build repo directory $repodir. \n"; - return 1; - } - } + if (system("cp -fp $fromfile $tdir/$non_native_kitcompname")) { + print "Error copying package file $fromfile to $tdir/$non_native_kitcompname \n"; + # Cleanup + system ("rm -Rf /tmp/buildkit_workdir"); + return 1; } - else{ - if (!-r "$spec") { - print "Error open kitcomponent rpm build spec $tdir/$non_native_kitcompname.spec \n"; - # Cleanup - system ("rm -Rf /tmp/buildkit_workdir"); - return 1; - } - my $rpmbuild_dir = $tmpdir."/rpmbuild"; - my $cmd = "rm -Rf $rpmbuild_dir"; - system($cmd); + my $rpmbuild_dir = $tmpdir."/".$kitname."/rpmbuild"; + my $cmd = "rm -Rf $rpmbuild_dir"; + system($cmd); - my $avoiderr = $rpmbuild_dir."/BUILDROOT/"; - mkpath($avoiderr); - $avoiderr = $rpmbuild_dir."/BUILD/"; - mkpath($avoiderr); - $avoiderr = $rpmbuild_dir."/SRPMS/"; - mkpath($avoiderr); - $avoiderr = $rpmbuild_dir."/RPMS/noarch/"; - mkpath($avoiderr); - - unless ( open( SF, "<", $spec ) ) { - print "Error attempting to open spec $spec of kitcomponent $non_native_basename. \n"; - return 1; - } + my $avoiderr = $rpmbuild_dir."/BUILDROOT/"; + mkpath($avoiderr); + $avoiderr = $rpmbuild_dir."/BUILD/"; + mkpath($avoiderr); + $avoiderr = $rpmbuild_dir."/SRPMS/"; + mkpath($avoiderr); + $avoiderr = $rpmbuild_dir."/RPMS/noarch/"; + mkpath($avoiderr); + + unless ( open( SF, "<", $spec ) ) { + print "Error attempting to open spec $spec of kitcomponent $non_native_basename. \n"; + return 1; + } - mkpath("$rpmbuild_dir/SOURCES"); - $cmd = "cd $source_dir/..;mv $non_native_kitcompname $non_native_basename; tar -czf $rpmbuild_dir/SOURCES/$non_native_basename.tar.gz $non_native_basename;mv $non_native_basename $non_native_kitcompname;"; - if ( system($cmd) ) { - print "Error creating tarfile $rpmbuild_dir/SOURCES/$non_native_basename.tar from $source_dir/*"; - return 1; - } - my $rpmbuild_cmd = "rpmbuild --define \"_topdir $rpmbuild_dir\" -ba $spec"; - if (!$::VERBOSE) { - $rpmbuild_cmd .= ' --quiet '; - } - if ( system($rpmbuild_cmd) ) { - print "Error running rpmbuild command for kit component $non_native_basename meta package\n"; - return 1; - } + mkpath("$rpmbuild_dir/SOURCES"); + $cmd = "cd $source_dir/..;mv $non_native_kitcompname $non_native_basename; tar -czf $rpmbuild_dir/SOURCES/$non_native_basename.tar.gz $non_native_basename;mv $non_native_basename $non_native_kitcompname;"; + if ( system($cmd) ) { + print "Error creating tarfile $rpmbuild_dir/SOURCES/$non_native_basename.tar from $source_dir/*"; + return 1; + } + my $rpmbuild_cmd = "rpmbuild --define \"_topdir $rpmbuild_dir\" -ba $spec"; + if (!$::VERBOSE) { + $rpmbuild_cmd .= ' --quiet '; + } + if ( system($rpmbuild_cmd) ) { + print "Error running rpmbuild command for kit component $non_native_basename meta package\n"; + return 1; + } - # Copy the built meta rpm to repo - my @built_rpms = `find $rpmbuild_dir/RPMS -name *.rpm`; - foreach my $rpm (@built_rpms) { - chomp($rpm); - if ( system ("cp -fp $rpm $repodir") ) { - print "Error copying rpm $rpm to build repo directory $repodir \n"; - return 1; - } - } + # Copy the built meta rpm to repo + my $repodir = $tmpdir."/".$kitname."/repos/".$non_native_kitreponame; + my @built_rpms = `find $rpmbuild_dir/RPMS -name *.rpm`; + foreach my $rpm (@built_rpms) { + chomp($rpm); + if ( system ("cp -fp $rpm $repodir") ) { + print "Error copying rpm $rpm to build repo directory $repodir \n"; + return 1; + } } $create_repodata_list{$repodir}=1; } @@ -3165,24 +2581,15 @@ sub kit_addpkgs close($NCF); # Clean up RPMBUILD and tmp in kit directory - my $cmd = "rm -Rf $tmpdir/tmp"; + my $cmd = "rm -Rf $tmpdir/$kitname/tmp"; + system("$cmd"); + $cmd = "rm -Rf $tmpdir/$kitname/rpmbuild"; system("$cmd"); - unless ( $debianflag ){ - $cmd = "rm -Rf $tmpdir/rpmbuild"; - system("$cmd"); - } # Run createrepo for each updated directory foreach my $repo (keys(%create_repodata_list)) { - my $createrepocmd = ''; - if ( $debianflag ){ - $createrepocmd = "cd $repo;dpkg-scanpackages . > Packages"; - } - else{ - $createrepocmd = "createrepo $repo"; - } - if (system( $createrepocmd )) { - print "Error running $createrepocmd. \n"; + if (system("createrepo $repo")) { + print "Error running createrpo command for $repo \n"; # Cleanup system ("rm -Rf /tmp/buildkit_workdir"); return 1; @@ -3191,7 +2598,7 @@ sub kit_addpkgs # Create new tar file in current directory my $new_tarfile = $::workdir.'/'.$kitbfname.'.tar.bz2'; - if ( system("cd $tmpdir; cd ..; tar -cjhf $new_tarfile $kitname/*") ) { + if ( system("cd $tmpdir; tar -cjhf $new_tarfile $kitname/*") ) { print "Error building tarfile $new_tarfile \n"; # Cleanup system ("rm -Rf /tmp/buildkit_workdir"); @@ -3200,163 +2607,7 @@ sub kit_addpkgs print "Kit tar file $new_tarfile successfully built \n"; # Cleanup -# system ("rm -Rf /tmp/buildkit_workdir"); - -} - - - - -#----------------------------------------------------------------------------- - -=head3 NEW_kit_addpkgs - - buildkit addpkgs - -=cut - -#----------------------------------------------------------------------------- - -sub NEW_kit_addpkgs - -{ - # add RPM pkgs to an existing kit tarfile - my $tmpdir_base = shift; - my $tmpdir = shift; - my $rpmdir = $::PKGDIR; - - $::NEW_PARTIAL_KIT = 1; - $::workdir = "$tmpdir_base/build_input"; - $::full_buildkit_conf = $::workdir."/".$::buildkit_conf; - $::deploy_dir = $tmpdir_base; #kitname appended by validate_bldkitconf routine - - my $tmp_buildkit_conf = `find $tmpdir_base -name $::buildkit_conf`; - chomp($tmp_buildkit_conf); - if ($tmp_buildkit_conf ne $::full_buildkit_conf) { - print "$tmp_buildkit_conf should match $::full_buildkit_conf .... error??? \n"; - } - my $loadrc = &load_bldkitconf($tmp_buildkit_conf); - if ( $loadrc != 0 ) { - print "Error reading buildkit config file $tmp_buildkit_conf \n"; - return 1; - } - - if ( defined($::KITVERSION) ) { - $::bldkit_config->{kit}{entries}[0]->{version} = $::KITVERSION; - } - if ( defined($::KITRELEASE) ) { - $::bldkit_config->{kit}{entries}[0]->{release} = $::KITRELEASE; - } - - my $chkrc = &validate_bldkitconf(); - if ( $chkrc != 0 ) { - print "Error validating buildkit config file $tmp_buildkit_conf \n"; - return 1; - } - if ($tmpdir ne $::deploy_dir) { - if (system ("mv $tmpdir $::deploy_dir ") ) { - print "Error moving $tmpdir to $::deploy_dir \n"; - return 1; - } - } - $::build_dir = $::deploy_dir; - $::base_repodir = "$::deploy_dir/repos"; - my $kitname = $::bldkit_config->{kit}{entries}[0]->{kitname}; - - - # Handle external packages - if ($::HAVE_EXTERNAL_PKG) { - foreach my $kp (@{$::bldkit_config->{kitpackage}{entries}}) { - if ($kp->{isexternalpkg} eq 'yes') { - my $ext_filename = $kp->{filename}; - my $ext_reponames = $kp->{kitreponame}; - my $fromfile = $rpmdir."/".$ext_filename; - if ( system("ls $fromfile > /dev/null") ){ - print "The product package file $ext_filename could not be read from the package directory $rpmdir. \n"; - # Cleanup - system ("rm -Rf /tmp/buildkit_workdir"); - return 1; - } - foreach my $repo (split(/,/, $ext_reponames)) { - my $repodir = $::base_repodir."/".$repo; - if ( ! -d ($repodir) && (! mkpath($repodir)) ) { - print "Error creating repository directory $repodir\n"; - # Cleanup - system ("rm -Rf /tmp/buildkit_workdir"); - return 1; - } - if (system("cp -fp $fromfile $repodir")) { - print "Error copying package file $fromfile to $repodir \n"; - # Cleanup - system ("rm -Rf /tmp/buildkit_workdir"); - return 1; - } - } - } - } - } - - # Handle non_native_pkgs - my $to_source_dir = "$::workdir/source_packages"; - mkpath("$to_source_dir"); - foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - if ($::NON_NATIVE_PKGS->{$kc->{kitcompname}}) { - my @nativefiles; - foreach my $pkgfile (split(/,/, $kc->{non_native_pkgs})) { - my ($key,$value) = split /:/,$pkgfile; - if ("$key" =~ /EXTERNALPKGS/) { - #the $non_native_filename may contain several pkgs, can check and copy at the same time - foreach my $nnpkg (split(/,/, $value)){ - - my $fromfile = $rpmdir."/".$nnpkg; - if ( system("ls $fromfile > /dev/null") ){ - print "The product package file $nnpkg could not be read from the package directory $rpmdir. \n"; - return 1; - } - if (system("cp -fp $fromfile $to_source_dir")) { - print "Error copying package file $fromfile to $to_source_dir \n"; - return 1; - } - } - } - } - } - } - - # Turn off external pkg flags and build the kit component meta pkgs - $::HAVE_EXTERNAL_PKG = ''; - $::HAVE_NON_NATIVE_PKGS = ''; - $::NON_NATIVE_PKGS = {}; - foreach my $kc (@{$::bldkit_config->{kitcomponent}{entries}}) { - if (&build_kitcomp($kc )) { - print "Error building kitcomponent metapackage for $kc->{basename} \n"; - return 1; - } - } - # run createrepo - foreach my $kr (@{$::bldkit_config->{kitrepo}{entries}}) { - my $repodir = "$::base_repodir/$kr->{kitreponame}"; - if ( -d $repodir ) { - my $cr_opts = ''; - if (( $kr->{osbasename} =~ m/rh|RH/ ) && - ( $kr->{osmajorversion} eq '5') ) { - $cr_opts = '-s md5'; - } - if ( system("createrepo $cr_opts $repodir") ) { - print "Error building the repository meta-data with the createrepo command \n"; - return 1; - } - } - } - - - # Build the full kit tar file - my $buildtar_rc = &kit_buildtar; - if ($buildtar_rc) { - print "Error building full kit tarfile \n"; - return 1; - } - + system ("rm -Rf /tmp/buildkit_workdir"); }