#!/usr/bin/perl -w # # $Id: rpm-legacy.pl,v 1.7 2003/01/13 05:28:43 jmates Exp $ # # Copyright (c) 2002, Jeremy Mates. This script is free software; # you can redistribute it and/or modify it under the same terms as # Perl itself. # # Run perldoc(1) on this file for additional documentation. # ###################################################################### # # REQUIREMENTS require 5; use strict; ###################################################################### # # MODULES use Carp; # better error reporting use Getopt::Std; # command line option processing ###################################################################### # # VARIABLES my $VERSION; ($VERSION = '$Revision: 1.7 $ ') =~ s/[^0-9.]//g; my (%opts, $cur, $old); ###################################################################### # # MAIN # parse command-line options getopts('h?om', \%opts); help() if exists $opts{'h'} or exists $opts{'?'}; # read from STDIN if no args left chomp(@ARGV = ) unless @ARGV; # and flag the help text if nothing from STDIN help() unless @ARGV; for (sort @ARGV) { my ($name, $version, $revision, $arch, $ext) = m/^ (.+)- ([^-]+)- (.+)\. ([^.]+)\. ([^.]+) $/x; die "problem parsing: $_\n" unless defined $name and defined $version and defined $revision and defined $arch and defined $ext; unless (exists $cur->{"$name.$arch"}) { $cur->{"$name.$arch"} = { name => $name, version => $version, revision => $revision, arch => $arch, ext => $ext, }; if (exists $opts{'m'}) { print 'new ', rpm2str($cur->{"$name.$arch"}), "\n"; } } else { # assumption: a "regular" sort will always place more up-to-date # version and local revision numbers ahead of older ones. my @temp = sort { length $b->{'version'} <=> length $a->{'version'} || $b->{'version'} cmp $a->{'version'} || length $b->{'revision'} <=> length $a->{'revision'} || $b->{'revision'} cmp $a->{'revision'} } ( $cur->{"$name.$arch"}, { name => $name, version => $version, revision => $revision, arch => $arch, ext => $ext, } ); $cur->{"$name.$arch"} = $temp[0]; push @$old, $temp[1]; if (exists $opts{'m'}) { print 'ugd ', rpm2str($cur->{"$name.$arch"}), "\n"; } } } unless (exists $opts{'m'}) { if (exists $opts{'o'}) { for (@$old) { print rpm2str($_), "\n"; } } else { for (sort keys %$cur) { print rpm2str($cur->{$_}), "\n"; } } } exit; ###################################################################### # # SUBROUTINES # takes hashref, returns rpm as proper filename sub rpm2str { return $_[0]->{'name'} . '-' . $_[0]->{'version'} . '-' . $_[0]->{'revision'} . '.' . $_[0]->{'arch'} . '.' . $_[0]->{'ext'}; } # a generic help blarb sub help { print <<"HELP"; Usage: $0 [opts] [rpm-files] Aids with differentiation of legacy vs. current RPMs. Options for version $VERSION: -h/-? Display this message -o Display outdated RPMs instead of newest ones. -m Display mixed list as parse RPMs. Run perldoc(1) on this script for additional documentation. HELP exit; } ###################################################################### # # DOCUMENTATION =head1 NAME rpm-legacy.pl - aids with differentiation of legacy vs. current RPMs =head1 SYNOPSIS To list most up-to-date RPMs: $ rpm-legacy.pl *.rpm To list out-of-date RPMs: $ rpm-legacy.pl -o *.rpm =head1 DESCRIPTION =head2 Overview Certain RedHat RPM mirrors include all the various update RPMs available in their listings, including older ones that have been supplemented by a different RPM. Using C to mass-upgrade from a directory does not work, as RPM currently appears not to throw out the older ones, leading to conflicts and dependancy warnings. This script works by sorting on the version and release fields of the RPM filenames, and labeling the highest values as the latest RPM. The names of the requested files (current or old) will be printed to STDOUT for use by other scripts. =head2 Normal Usage $ rpm-legacy.pl [options] [rpm-files] See L<"OPTIONS"> for details on the command line switches supported. If the list of RPMs is ommited from the command line, the script will try to read them in from STDIN. =head1 OPTIONS This script currently supports the following command line switches: =over 4 =item B<-h>, B<-?> Prints a brief usage note about the script. =item B<-o> Display outdated RPMs instead of newest ones. =item B<-m> Display mixed list as parse RPMs. Good for reviewing script's choices. =back =head1 BUGS =head2 Reporting Bugs Newer versions of this script may be available from: http://sial.org/code/perl/ If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome. =head2 Known Issues No known bugs. =head1 SEE ALSO perl(1) =head1 AUTHOR Jeremy Mates, http://sial.org/contact/ =head1 COPYRIGHT Copyright (c) 2002, Jeremy Mates. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 VERSION $Id: rpm-legacy.pl,v 1.7 2003/01/13 05:28:43 jmates Exp $ =cut