How to modify Perl script to move packets in diffrent directory based on version? [migrated]
- by Peter Penzov
I have this Perl script which is used to soft packages based on packet version:
#!/usr/bin/perl -w
#
# Compare versions of all *.rpm files against the
# latest packages installed (if installed)
#
# Usage:
# rpmver.pl
# This script looks for all *.rpm files.
#
use strict;
use RPM2;
my $rpm_db = RPM2->open_rpm_db();
for my $filename (<*.rpm>) {
my $h = RPM2->open_package( $filename );
# Ensure we compare against the newest
# package of the given name.
my ($installed) =
sort { $b <=> $a } $rpm_db->find_by_name($h->name);
if (not $installed) {
printf "Package %s not installed.\n", $h->as_nvre;
} else {
my ($result) = ($h <=> $installed);
if ($result < 0) {
printf "Installed package %s newer than file %s\n",
$installed->as_nvre,
$h->as_nvre;
} else {
printf "File %s newer than installed package %s\n",
$h->as_nvre,
$installed->as_nvre;
}
}
}
I have a Linux repository with SRPMs. I want to move the packages with the latest into different directory for example latest_lackages. How the script must be modified?