Package Cleanup - Leaves and Orphans

Posted by Bill McGonigle Tue, 30 Sep 2008 18:12:00 GMT

On an RPM-based system, yum-utils provides a utility called ‘package-cleanup’. It has two useful options:

–orphans shows RPM packages that do not belong to any currently-configured repositories, and:

–leaves shows RPM packages for which there are no dependencies; that is removing them won’t trigger the removal of other packages. By default it’s concerned with libraries, but –all removes that restriction.

So, ideally you’d like to run:

package-cleanup –orphans –leaves –all

to get a list of all the packages you might want to consider for cleanup, say before or after an upgrade. But package-cleanup doesn’t support that.

So, here’s a little perl script, called leavesorphans.pl on my system that will run package-cleanup twice and print for you the intersection of the two sets:

#!/usr/bin/perl -w
          use strict;
          use warnings FATAL=>'all';
          
          use Data::Dumper;
          
          my @orphans = `package-cleanup --orphans`;
          my @leaves = `package-cleanup --leaves --all`;
          
          my (%orphans,%leaves);
          foreach my $orphan (@orphans) {
              $orphans{$orphan} = 1;
          }
          foreach my $leaf (@leaves) {
              $leaves{$leaf} = 1;
          }
          
          my (@matches);
          foreach my $orphan (keys %orphans) {
              foreach my $leaf (keys %leaves) {
                  if ($orphan eq $leaf) {
                      push (@matches,$orphan);
                      delete $leaves{$leaf};
                  }
              }
          }
          
          
          foreach my $match (@matches) {
              if ($match !~  m/Setting up yum/) {
                  print $match;
              }
          }
          
          

I recently ran it and found a few packages that were lingering on my system since Fedora Core 4, just wasting system resources. If all of your proper packages belong to a repository you can simply pipe the output of the command to xargs rpm -e. I’m not quite that slick, so I manually reviewed the list and kept the packages I had installed by hand.

del.icio.us:Package Cleanup - Leaves and Orphans digg:Package Cleanup - Leaves and Orphans reddit:Package Cleanup - Leaves and Orphans spurl:Package Cleanup - Leaves and Orphans wists:Package Cleanup - Leaves and Orphans simpy:Package Cleanup - Leaves and Orphans newsvine:Package Cleanup - Leaves and Orphans blinklist:Package Cleanup - Leaves and Orphans furl:Package Cleanup - Leaves and Orphans fark:Package Cleanup - Leaves and Orphans blogmarks:Package Cleanup - Leaves and Orphans Y!:Package Cleanup - Leaves and Orphans smarking:Package Cleanup - Leaves and Orphans magnolia:Package Cleanup - Leaves and Orphans segnalo:Package Cleanup - Leaves and Orphans
Trackbacks

Use the following link to trackback from your own site:
http://blog.bfccomputing.com/articles/trackback/4785

Comments

Leave a response

Comments