#!/usr/bin/perl -w # # Copyright (c) 2005 Gormand Pty Ltd. All rights reserved. This program # is free software; you can redistribute it and/or modify it under the # same terms as Perl itself. # # $Id: update_rpms_dir,v 1.1.1.1 2005/09/15 23:55:09 gordonr Exp $ # # Update RPMS directory with the latest from a given list of directories use RPM2; use Getopt::Long; my $rpm_flags = RPM2->vsf_nodsa; # Deal with missing DSA keys GetOptions(\%opt, "verbose"); # XXX - FIXME - These will be command line options my $rpms_dir = "/builds/RPMS"; my @repositories = qw( /builds/rpms/RPMS/i386/ /builds/rpms/RPMS/noarch/ /mirrors/mitel/devel/repo/RPMS/ /mirrors/centos/4.1/updates/i386/RPMS/ /mirrors/centos/4.1/os/i386/CentOS/RPMS/ ); chdir $rpms_dir or die "Couldn't chdir $rpms_dir"; opendir RPMS, '.' or die "Couldn't opendir $rpms_dir"; for my $file ( sort grep { /.rpm$/ } readdir RPMS ) { warn "Checking $file:\n" if $opt{verbose}; my $rpm = RPM2->open_package($file, $rpm_flags); for my $dir ( @repositories ) { my $newest = find_newest($rpm, $dir); if ($newest) { # XXX - FIXME - Should we try other repos, or stop here? warn "cd $rpms_dir; rm $file; cp -p $dir/$newest .\n" } } } sub find_newest { my ($rpm, $dir) = @_; # XXX - FIXME - Need to cater for multiple architectures my $name = $rpm->name; $name =~ s/\+/\\+/g; # libstdc++ and friends opendir DIR, $dir or die "Couldn't opendir $dir"; my @rpms = grep { /^${name}-.*.rpm$/ } readdir DIR; closedir DIR; my $newest_file = undef; my $newest_hdr = undef; for my $file (@rpms) { my $candidate = RPM2->open_package("$dir/$file", $rpm_flags); if ($candidate->name ne $name) { warn "Ignoring $file - name doesn't match\n" if $opt{verbose}; next; } if ( ($candidate cmp $rpm) <= 0) { warn "Ignoring $file - older or same version\n" if $opt{verbose}; next; } if (not defined $newest_hdr or ($candidate cmp $newest_hdr) < 0) { warn "Newest is $file\n" if $opt{verbose}; $newest_file = $file; $newest_hdr = $candidate; } } return $newest_file; }