Finding (and purging) orphaned packages
For a couple of releases Mandriva's package management tool, urpmi, has come with a feature that tracks and reports on orphaned packages. It does this by tracking which packages were installed as dependencies of others and then reporting back when the package that contained the dependency is no longer present (or it's dep has changed). This works pretty well, but sometimes you want something that is not based on a tracked state, and just looks at the packages available and those that are installed.
If you have kept the same install for several distro releases, with just upgrades rather than fresh installs, then chances are you will have quite a few old libraries installed on your system. The easiest way to purge all these no longer needed libraries is to compare the packages that are available via urpmi and what packages are installed. If you have packages that are installed but that are not available to install, chances are it's an orphan.
So I wrote a very simple script that compares the two outputs and I include it here so you can do your own spring cleaning! This is very similar to the yum orphan finding tool on Fedora (well I last tried it a while back, so it may have moved on since then!).
Hope it's useful to some people:
#!/bin/bash
TMP_AVAILABLE=$(mktemp /tmp/orphans.XXXXXX)
TMP_INSTALLED=$(mktemp /tmp/orphans.XXXXXX)
urpmq -fa . | sort -u >$TMP_AVAILABLE
rpm -qa --nosignature --nodigest --qf '%{name}-%{version}-%{release}.%{arch}\n' | sort -u >$TMP_INSTALLED
diff -u $TMP_AVAILABLE $TMP_INSTALLED | grep "^+[^+]" | cut -b2-
rm -f $TMP_AVAILABLE $TMP_INSTALLED

October 11th, 2009 - 14:30
Or just “urpmi_rpm-find-leaves -g” ?
October 11th, 2009 - 17:30
Nope. That gives completely different output.
e.g. one of the listed packages is libportaudio0 but this is still provided by the media and I have it installed.
[colin@jimmy ~]$ rpm -q libportaudio0
libportaudio0-18.1-11mdv2010.0
[colin@jimmy ~]$ urpmq -r libportaudio0
libportaudio0-18.1-11mdv2010.0
So.like I say, this is doing something different.
October 12th, 2009 - 08:24
I just tried adding it inside urpmq, and it speedups it a bit :
[pterjan@plop perl-install]$ time urpmq –not-available > /dev/null
2.36user 0.31system 0:03.31elapsed 80%CPU (0avgtext+0avgdata 0maxresident)k
152inputs+0outputs (1major+23031minor)pagefaults 0swaps
[pterjan@plop perl-install]$ time sh o.sh > /dev/null
5.82user 0.38system 0:07.71elapsed 80%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+1872outputs (0major+30996minor)pagefaults 0swaps
sub _search_not_available_packages {
my ($urpm) = @_;
my %available;
foreach my $p (@{$urpm->{depslist}}) {
$available{$p->name.”-”.$p->version.”-”.$p->release.”.”.$p->arch} = 1;
}
my $db = urpm::db_open_or_die_($urpm);
$db->traverse(sub {
my ($p) = @_;
my $s = $p->name.”-”.$p->version.”-”.$p->release.”.”.$p->arch;
$available{$s} || print “$s\n”;
});
}
October 12th, 2009 - 08:34
Nice work Pascal
Thanks for including this functionality (and turbocharging it) in urpmq!
October 13th, 2009 - 14:55
Great work Pascal! Can we expect this in next version of the urpmi package?
October 21st, 2009 - 17:28
You may know already, but teuf just added Pascal’s patch in urpmi 6.31 so it will go into Mandriva 2010 \o/
October 12th, 2009 - 08:43
All these methods give you hints on packages that might be orphans but I’d never go on and remove all orphan reported packages blindly. The provided script mostly reports rpm that where not installed from rpm media such as skype or other such softwares.
October 13th, 2009 - 10:59
That’s why this one is for urpmq, to give you the information, and not in urpme
October 14th, 2009 - 21:31
Hey ! I’ve just opened a bug report (wish) about this a while ago !! Thanks for addressing this ! https://qa.mandriva.com/show_bug.cgi?id=51418