Created
March 15, 2011 22:47
-
-
Save viliampucik/871681 to your computer and use it in GitHub Desktop.
Perl script for printing all old (SRC) RPM packages from a specified directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# [2011-03-15] [email protected] | |
# Prints all old (SRC) RPM packages from specified directory. | |
# Assumed package format: name-version-release.distribution_optionalpatch.suffix.rpm | |
# | |
# Use case: | |
# | |
# $ ls test/ | |
# glibc-2.12-1.7.el6_0.3.src.rpm glibc-2.12-1.7.el6_0.4.src.rpm glibc-2.12-1.7.el6.src.rpm | |
# $ ./oldrpm.pl test/ | |
# glibc-2.12-1.7.el6.src.rpm glibc-2.12-1.7.el6_0.3.src.rpm | |
use strict; | |
use warnings; | |
if ( scalar @ARGV < 1 ) { | |
print "usage: oldrpm.pl <dir>\n"; | |
exit 1; | |
} | |
opendir my $dh, $ARGV[0] or die $!; | |
my @rpms = grep { /\.rpm$/ } readdir $dh; | |
close $dh; | |
my %names; | |
map { /([\w\-\+]+)-[^-]+-[\d\.]+/, push @{ $names{$1} }, $_ } @rpms; | |
for ( sort keys %names ) { | |
next if scalar @{ $names{$_} } < 2; | |
my $pkg = my $version = my $release = my $patch = undef; | |
for ( @{ $names{$_} } ) { | |
/[\w\-\+]+-([^-]+)-([\d\.]+)[^_]+_([\d\.]+)/; | |
my $_3 = ( defined $3 ) ? $3 : ''; | |
/[\w\-\+]+-([^-]+)-([\d\.]+)/; | |
if ( !defined $pkg | |
|| $version lt $1 | |
|| ( $version eq $1 && $release lt $2 ) | |
|| ( $version eq $1 && $release eq $2 && $patch lt $_3 ) ) { | |
$pkg = $_; | |
$version = $1; | |
$release = $2; | |
$patch = $_3; | |
} | |
} | |
# commented alternative output | |
#print "-"x20, "\n"; | |
for ( @{ $names{$_} } ) { | |
#print; | |
#print " *" if ( $_ eq $pkg ); | |
#print "\n"; | |
print "$_ " if $_ ne $pkg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment