#!/usr/bin/perl # # repobuild - Given a repository of RPMS and SRPMS, list the source # packages that will need to be built. # # Copyright (C) 1999-2005 Martin K. Petersen # Released under the terms of the GNU General Public License v2. # # If no matching binary packages are found we print the SRPM name for # feeding to rpmbuild. Note that we don't complain if some # subpackages are missing. That's because Red Hat's spec files suffer # from bit rot and sometimes list phantom packages. Since an rpmbuild # is transactional we assume that if one file is found, the rest of # the binary RPMS were written as well. use File::Basename; use File::Spec; use Getopt::Std; sub main::HELP_MESSAGE () { print STDERR "Usage: repocheck [-v] [-t] [-a ] \n"; print STDERR " -v verbose\n"; print STDERR " -t thorough checking\n"; print STDERR " -a \n"; print STDERR " repodir must contain RPMS and SRPMS dirs\n"; } $main::VERSION = "$Id: repobuild,v 1.16 2006/04/07 23:42:53 mkp Exp $\\n" . "Copyright 1999-2006 Martin K. Petersen \n"; $Getopt::Std::STANDARD_HELP_VERSION = true; my $verbose = 0; my $thorough = 0; # Find out which arch we are running on $arch = `arch`; chomp $arch; $arch =~ s/i.86/i386/; getopts('vtha:'); $verbose = 1 if ($opt_v); $thorough = 1 if ($opt_t); $arch = $opt_a if ($opt_a); $repo = File::Spec->rel2abs(shift); die "Must specify repository to analyze" unless -d "$repo"; die "Repository doesn't contain an RPMS dir" unless -d "$repo/RPMS"; die "Repository doesn't contain an SRPMS dir" unless -d "$repo/SRPMS"; # Get list of source RPMS open SRPMS, "ls -1 $repo/SRPMS/*.rpm|" or die "Can't ls $repo/SRPMS/*.rpm"; PACKAGE: while () { # Skip autogenerated packages next if /rpmdb/; next if /comps/; # Split $file = $_; chomp $file; ($pkg, $path, $suffix) = fileparse($file, '.src.rpm'); $found = 0; # Let's try the trivial case unless -t was given... if ($thorough == 0 && -f "$repo/RPMS/$pkg.$arch.rpm") { print STDERR "SKIP_RPM $pkg.$arch.rpm\n" if $verbose; $found++; goto skip; } # Otherwise use srpm2bin to extract a package list open PKGLIST, "srpm2bin -a $arch 2>/dev/null $file|" or die "Can't run srpm2bin $file"; $subs = 0; while () { chomp; $subpkg = $_; $subs++; if (-f "$repo/RPMS/$subpkg") { print STDERR "FOUND $subpkg\n" if $verbose; $found++; } else { print STDERR "MISSING $subpkg\n" if $verbose; } } # Empty package list - not supported on this arch if ($subs == 0) { print STDERR "SKIP_ARCH $pkg\n" if $verbose; next; } close PKGLIST; skip: if ($found == 0) { print STDERR "BUILD $pkg.src.rpm\n" if $verbose; print STDOUT "$file\n"; } } close SRPMS; # EOF