script that should be able to compare installed rpms with some reference
tree of rpms, some day
This commit is contained in:
parent
ce99256868
commit
f0e8507f56
1 changed files with 189 additions and 0 deletions
189
rpm_compare/rpm_compare
Executable file
189
rpm_compare/rpm_compare
Executable file
|
|
@ -0,0 +1,189 @@
|
|||
#!/usr/local/bin/perl -w
|
||||
|
||||
# $Id$
|
||||
# $Source$
|
||||
|
||||
use strict;
|
||||
use Getopt::Std;
|
||||
use RPM::Perlonly;
|
||||
use Data::Dumper;
|
||||
|
||||
my @RPMPATHS=(
|
||||
"/home/ward/REDHAT73/ftp.nluug.nl/pub/os/Linux/distr/RedHat/ftp/pub/redhat/linux/7.3/en/os/i386/RedHat/RPMS",
|
||||
"/home/ward/REDHAT73/ftp.nluug.nl/pub/os/Linux/distr/RedHat/ftp/pub/redhat/linux/updates/7.3/en/os/i386",
|
||||
"/home/ward/REDHAT73/ftp.nluug.nl/pub/os/Linux/distr/RedHat/ftp/pub/redhat/linux/updates/7.3/en/os/i686",
|
||||
"/home/ward/REDHAT73/ftp.nluug.nl/pub/os/Linux/distr/RedHat/ftp/pub/redhat/linux/updates/7.3/en/os/noarch",
|
||||
);
|
||||
|
||||
my $SSH="/usr/bin/ssh";
|
||||
|
||||
my %option = ();
|
||||
getopts("f:ho:pqs:", \%option);
|
||||
|
||||
if ( $option{h} ) { &help; }
|
||||
if ( $option{f} && ( ! $option{p} ) && ( ! $option{s} ) ) {
|
||||
my %refrpms = &fileread($option{f});
|
||||
} elsif ( $option{p} && ( ! $option{f} ) && ( ! $option{s} ) ) {
|
||||
my %refrpms = &pathread;
|
||||
if ( $option{o} ) {
|
||||
open(FH, ">$option{o}") or die "Couldn't open $option{o}: $!";
|
||||
print FH Dumper(\%refrpms);
|
||||
close(FH);
|
||||
}
|
||||
} elsif ( $option{s} && ( ! $option{f} ) && ( ! $option{p} ) ) {
|
||||
&serverread($option{s});
|
||||
} else {
|
||||
&help;
|
||||
}
|
||||
|
||||
# Met pathread en RPM-Perlonly-1.0.1 moet het mogelijk zijn te bepalen
|
||||
# welke RPM de nieuwste is. Hierna is het (denk ik) relatief eenvoudig
|
||||
# te bepalen op welke systemen er dus packages geupdate moeten worden...
|
||||
|
||||
sub pathread {
|
||||
my %allrpms = ();
|
||||
my %entry = ();
|
||||
my ( $line, $prefix );
|
||||
foreach $prefix ( @RPMPATHS ) {
|
||||
opendir DH, $prefix;
|
||||
while ($line = readdir DH) {
|
||||
if ($line =~ /\.rpm$/ ) {
|
||||
# &splitname($line);
|
||||
tie my %rpm, "RPM::Perlonly", "$prefix/$line" or die "Problem, could not open $line: $!";
|
||||
#foreach ( sort keys %rpm ) {
|
||||
# print "$_ -> $rpm{$_}\n";
|
||||
#}
|
||||
#print "Fullname $line\n";
|
||||
#print " NAME: $rpm{'NAME'}\n";
|
||||
#print " VERSION: $rpm{'VERSION'}\n";
|
||||
#print " RELEASE: $rpm{'RELEASE'}\n";
|
||||
if ( ! exists( $rpm{'EPOCH'} ) ) {
|
||||
$rpm{'EPOCH'} = 0;
|
||||
}
|
||||
#print " ARCH: $rpm{'ARCH'}\n";
|
||||
push @{$allrpms{$rpm{'NAME'}}}, ( {
|
||||
'NAME', $rpm{'NAME'},
|
||||
'BUILDTIME', $rpm{'BUILDTIME'},
|
||||
'VERSION', $rpm{'VERSION'},
|
||||
'RELEASE', $rpm{'RELEASE'},
|
||||
'EPOCH', $rpm{'EPOCH'},
|
||||
'ARCH', $rpm{'ARCH'},
|
||||
'FILENAME', $line
|
||||
} );
|
||||
untie(%rpm);
|
||||
}
|
||||
#print "$line\n";
|
||||
}
|
||||
closedir DH;
|
||||
}
|
||||
|
||||
return %allrpms;
|
||||
}
|
||||
|
||||
sub fileread($) {
|
||||
my $file = shift;
|
||||
my $VAR1;
|
||||
open FH, "<$file" or die "Couldn't open $file: $!";
|
||||
my $data = do { local $/; <FH>; };
|
||||
close FH;
|
||||
eval $data;
|
||||
my %allrpms = %{$VAR1};
|
||||
&outputnewest(%allrpms);
|
||||
return %allrpms;
|
||||
}
|
||||
|
||||
sub serverread($) {
|
||||
my $server = shift;
|
||||
# open .... or die "Couldn't execute ....: $!";
|
||||
|
||||
# close ....;
|
||||
}
|
||||
|
||||
sub outputnewest(@) {
|
||||
my %allrpms = @_;
|
||||
if ( $option{q} ) { return; }
|
||||
foreach ( sort keys %allrpms) {
|
||||
# print scalar( @{$allrpms{$_}} ) . " $_\n";
|
||||
if ( scalar( @{$allrpms{$_}} ) > 1 ) {
|
||||
@{$allrpms{$_}} = sort buildtimesort @{$allrpms{$_}};
|
||||
# foreach my $rpm ( sort buildtimesort @{$allrpms{$_}} ) {
|
||||
# print " " . %{$rpm}->{'BUILDTIME'} . " " . %{$rpm}->{'FILENAME'} . "\n";
|
||||
# }
|
||||
}
|
||||
print @{$allrpms{$_}}[0]->{'FILENAME'}."\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub buildtimesort {
|
||||
my $a = %{$a}->{'BUILDTIME'};
|
||||
my $b = %{$b}->{'BUILDTIME'};
|
||||
if ( $a > $b ) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub splitname($$) {
|
||||
my $fullname = shift;
|
||||
my $packagename;
|
||||
my $version;
|
||||
my $build;
|
||||
my $arch;
|
||||
|
||||
if ( $fullname =~ /(.*?)-([^-]*)-([^-]*)\.(i[36]86|noarch)(\.rpm)?$/ ) {
|
||||
$packagename = $1;
|
||||
$version = $2;
|
||||
$build =$3;
|
||||
$arch = $4;
|
||||
print "Fullname $fullname\n";
|
||||
print " PACKAGE: $packagename\n";
|
||||
print " VERSION: $version\n";
|
||||
print " BUILD: $build\n";
|
||||
print " ARCH: $arch\n";
|
||||
return ( $packagename, $version, $build, $arch );
|
||||
} else {
|
||||
print "The magic don't work for $fullname\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub help() {
|
||||
print << "EOT";
|
||||
|
||||
Usage: $0 [option]
|
||||
|
||||
-f <file> Read reference rpms from file
|
||||
-h Display this help
|
||||
-l Read installed rpms from localhost
|
||||
-o <file> Write reference rpms to file, only useful in combination with -p
|
||||
-p Read rpms from build in mirror paths
|
||||
-q Quiet down a bit
|
||||
-s <server> Read rpms from server
|
||||
|
||||
Usually you'll want to run this program like
|
||||
$0 -p -o <file>
|
||||
to build an index to compare you're systems to and then proceed
|
||||
with something like
|
||||
$0 -f <file> -s <server>
|
||||
for each server which you want to check the status of.
|
||||
|
||||
EOT
|
||||
exit;
|
||||
}
|
||||
|
||||
# sorteer routine die "menselijk" sorteerd; bijv.:
|
||||
# boneym100 elvis1 elvis2 elvis10
|
||||
#sub wardsort {
|
||||
# my @a = split(/([0-9]+)/,$a);
|
||||
# my @b = split(/([0-9]+)/,$b);
|
||||
#
|
||||
# foreach my $x (@a)
|
||||
# {
|
||||
# my $y = shift @b;
|
||||
# my $r = ($x =~ /^[0-9]+$/ && $y =~ /^[0-9]+$/) ?
|
||||
# ($x <=> $y) : ($x cmp $y);
|
||||
# $r && return $r;
|
||||
# }
|
||||
# return -1 if (@b);
|
||||
# 0;
|
||||
#}
|
||||
Loading…
Add table
Add a link
Reference in a new issue