[lang]

Present Perfect

Personal
Projects
Packages
Patches
Presents
Linux

Picture Gallery
Present Perfect

rpm repositories

Filed under: Hacking — Thomas @ 8:02 pm

2007-7-1
8:02 pm

I wanted to clean up our work repositories a little, because I’m working on a platform deployment that is using something else than our venerable FC5 set of packages.

There’s two things I wanted to do.  First, I wanted something that would clean out old rpm’s from a directory – the ones that have been superseded by a newer version of a package.

Second, I wanted a script that could compare two directories (for two different base distros) and tell me which packages are of a different version between the two of them.  This tells me which packages I forgot to rebuild for either platform.

I’ve been googling for half an hour to find anything helpful, but it’s hard to use google when you’re not sure what you would call stuff like this.  In the end I caved in and wrote the first script in half an hour with the help of Paul Nasrat’s excellent introductory slides (which I need to go through pretty much any time I write any rpm-related code).

Anyway, maybe you know of the existence of a script that does the second thing I want ? If not, odds are I’m going to write it in the next day as time permits.

4 Comments »

  1. repomanage from yum-utils can do the first thing.

    Comment by Michael — 2007-7-1 @ 8:58 pm

  2. for the first case, in yum-utils theres a script called repomanage .. it have old package listing feature and several other features

    example of cleaning up old packages using repomanage
    cd /path/to/repo
    repomanage –old . |xargs rm -f

    for the second case .. I’m not very sure what can be used for it ..

    Here’s a small stupid script here which just came out of nowhere

    ls $DIR1 > dir1.tmp
    ls $DIR2 > dir2.tmp
    diff dir1.tmp dir2.tmp

    Comment by Izhar — 2007-7-1 @ 9:08 pm

  3. I once hacked together a perl script to do something similar. It prints all packages in a directory different than somewhere else.

    #!/usr/bin/perl

    # Compare a directory full of .RPMs to those currently installed,
    # print a list of what upgrades are availible. Works with a lot
    # less RAM than YUM!

    %ignore;
    # packages can be ignored by adding them to this hash
    $ignore{‘some-package’} = 1;

    sub load {
    my %packages;
    open(F, $_[0]);
    my $p = ;
    while ($p) {
    chomp($p);
    my ($n, $v) = split(/ /, $p);
    $packages{$n} = $v;
    $p = ;
    }

    return %packages;
    }

    # space can never occur in package name or version so can be a sep
    $q = ‘rpm -q –queryformat=\’%{name} %{version}-%{release}\n\”;
    # this could also be a directory like below
    `$q -a > /tmp/r.now`;
    %now = load(“/tmp/r.now”);
    `$q -pl /var/cache/yum/core/packages/[A-Z]*.rpm > /tmp/r.core`;
    `$q -pl /var/cache/yum/core/packages/[a-l]*.rpm >> /tmp/r.core`;
    `$q -pl /var/cache/yum/core/packages/[m-z]*.rpm >> /tmp/r.core`;
    %core = load(“/tmp/r.core”);

    foreach my $n (keys(%now)) {
    if (exists $ignore{$n}) {
    next;
    }
    if ((not exists $ignore{$n}) and (exists $core{$n})) {
    if ($now{$n} ne $core{$n}) {
    print “$n-$core{$n} : $now{$n}\n”;
    }
    }
    }

    Comment by Ben — 2007-7-2 @ 5:12 am

  4. Thomas,
    use repomanage it’ll handle what you want and from looking at your script you’ll be inadvertently nuking pkgs of the same n-e-v-r but different archs. So if you have any multilib boxes you just may have some killed some files you didn’t want to kill.

    For the second issues it sounds like you want to diff two repositories for changes. There’s a tool that james bowes (jbowes) had been working on to do that with repodata repositories. That might do it.
    -s

    Comment by seth vidal — 2007-7-2 @ 6:23 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

picture