You are not logged in.
This script, named orphans, checks for packages that were installed as a dependency for another package, but are not required by other packages anymore. It's simular to deborphan in Debian. Orphan packages can be removed without breaking anything.
#!/usr/bin/perl -w
# Scriptname: orphans
# Author: Speek
use strict;
if (@ARGV) {
my $pn = (split /\//, $0)[-1];
print "$pn checks for packages that were installed as a dependency for\n";
print "another package, but are not required by other packages anymore.\n";
print "Usage: $pn without arguments\n";
exit;
}
my $requiredby;
my $notrequired;
my $reason;
my $pkg;
chdir "/var/lib/pacman/local" or die "Cannot chdir to /var/lib/pacman/local: $!";
foreach $pkg (<*>) {
$requiredby = 0;
$notrequired = 0;
$reason = 0;
open DEPENDS, "$pkg/depends" or die "Cannot open $pkg/depends: $!";
while (<DEPENDS>) {
chomp;
if ($requiredby == 1) {
$notrequired = 1 if /^$/;
last;
}
if (/REQUIREDBY/) {
$requiredby = 1;
}
}
close DEPENDS;
if ($notrequired) {
open DESC, "$pkg/desc" or die "Cannot open $pkg/desc: $!";
while (<DESC>) {
chomp;
if ($reason == 1 and /1/) {
print "$pkg\n";
last;
}
$reason = 1 if /REASON/;
}
close DESC;
}
}
edit: fixed backslases
Last edited by Speek (2007-02-04 16:07:32)
Offline
Great!!!
Offline
$ pacman -Q --help
usage: pacman {-Q --query} [options] [package]
options:
-e, --orphans list all packages that were explicitly installed
and are not required by any other packages
What's the difference betweend this script and pacman -Qe ?
EDIT:
OK I now get it
pacman -Qe shows only "explicitly" installed and this script shows also(only?) packages installed as deps.
Offline
Works great, thanks!
Offline
Offline
What does the REASON variable (or section) mean in the desc file? It's value is either 0 or 1, I think.
The Perl script checks it for a value of 1 when deciding whether to print the package name.
"I know nothing except the fact of my ignorance."
- Socrates
Offline
what a nice app!!!... thank you very much
And where were all the sportsmen who always pulled you though?
They're all resting down in Cornwall
writing up their memoirs for a paper-back edition
of the Boy Scout Manual.
Offline
The first time i tried it worked ok. But after rebooting i get this
orphans.sh: line 4: use: command not found
orphans.sh: line 6: syntax error near unexpected token `{'
orphans.sh: line 6: ` if (@ARGV) { '
Offline
What does the REASON variable (or section) mean in the desc file? It's value is either 0 or 1, I think.
The Perl script checks it for a value of 1 when deciding whether to print the package name.
0 = explicitly installed
1 = installed as a dependency for another package
Offline
The first time i tried it worked ok. But after rebooting i get this
orphans.sh: line 4: use: command not found orphans.sh: line 6: syntax error near unexpected token `{' orphans.sh: line 6: ` if (@ARGV) { '
I'm not sure, but you have named the script "orphans.sh". The .sh extension is for shell scripts. This is a perl script. Try to name it just "orphans" and make it executable (chmod +x orphans).
Offline
Its OK now. Something had to do with copying/pasting in kwrite. Tried mcedit and it's all fine. Thanks for the script
Offline
Thanks... Finally I don't have to do the process manually anymore
Offline
Hmm. Just note that it doesn't necessarily list orphans that are unecessary. When I ran it, it listed cvs and stuff like that.
Now I DO know this is intentional, and it explicitly lists packages installed as a dep, but newbies should take notice of this.
Offline
I'm not sure, but you have named the script "orphans.sh". The .sh extension is for shell scripts. This is a perl script. Try to name it just "orphans" and make it executable (chmod +x orphans).
Just, as a sidenote, the file extension actually does nothing. You could just as well name it "orphans.blah.sh.pl.python.archrocks.really" and set it executable, and it'd do the same thing. Your shell looks at the shebang line (#!/usr/bin/perl -w) to decide what interpreter to send it to, not at the extension.
The suggestion box only accepts patches.
Offline
battra wrote:What does the REASON variable (or section) mean in the desc file? It's value is either 0 or 1, I think.
The Perl script checks it for a value of 1 when deciding whether to print the package name.
0 = explicitly installed
1 = installed as a dependency for another package
Thanks. Nice/useful script...
"I know nothing except the fact of my ignorance."
- Socrates
Offline
how do i run this? i get the same error as insane.. sh orphans??
Offline
how do i run this? i get the same error as insane.. sh orphans??
Did you, "Try to name it just "orphans" and make it executable (chmod +x orphans)."?
Then cd to dir and ./orphans.
/path/to/Truth
Offline
how do i run this? i get the same error as insane.. sh orphans??
Speaking this is a perl script and not a bash script, you'd have to do:
perl orphans
Offline
Great Script, indeed! It should be installed as a part of the package-managing system IMHO. But well, it's easy enough to use it seperately.
Todays mistakes are tomorrows catastrophes.
Offline
I threw this together a while back:
http://phraktured.net/config/bin/pacorphans
While it doesn't read the DB directly, it does something similar.
Offline
Did you, "Try to name it just "orphans" and make it executable (chmod +x orphans)."?
Then cd to dir and ./orphans.
yes, it didn't work
neither did # perl orphans
am i missing a package or something? i have perl..
Offline
I solved this problem by copying and pasting again the script in mcedit. I don't know what went wrong the first time in kwrite but after that worked fine.
Offline
I don't know what went wrong the first time in kwrite but after that worked fine.
You know, I've seen this kind of thing before although it was with gedit I think. I was trying to work with a script that kept giving me errors, and when I opened it in nano the darn thing had these odd symbols added where I think I had either used the spacebar or enter key while it was open in gedit.
/path/to/Truth
Offline
I made a patch for pacman.c that adds a new -t option in Query options
http://frukt.dyndns.org:4/stuff/orphans … srev.patch
http://frukt.dyndns.org:4/stuff/orphansrev/PKGBUILD
And the result:
$ pacman -Qt
gimp-print 4.2.7-5
libdrm 2.0.2-1
libsidplay 1.36.59-2
live-media 2006.03.03-1
mozilla-firefox 1.5.0.5-1
Offline
I made a patch for pacman.c that adds a new -t option in Query options
Good. Post it to phrakture. I'm not sure if he merged this already in pacman 3.
to live is to die
Offline