You are not logged in.

#1 2006-06-14 15:03:47

Speek
Member
Registered: 2005-04-07
Posts: 36

orphans

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

#2 2006-06-14 16:55:49

drakosha
Member
Registered: 2006-01-03
Posts: 253
Website

Re: orphans

Great!!!

Offline

#3 2006-06-14 18:06:13

MAC!EK
Member
Registered: 2005-09-27
Posts: 267

Re: orphans

$ 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 smile
pacman -Qe shows only "explicitly" installed and this script shows also(only?) packages installed as deps.

Offline

#4 2006-06-14 18:20:47

barebones
Member
Registered: 2006-04-30
Posts: 235

Re: orphans

Works great, thanks!

Offline

#5 2006-06-14 19:47:57

z4ziggy
Member
From: Israel
Registered: 2004-03-29
Posts: 573
Website

Re: orphans

thanks man. i just deleted 12 orphan packages...

Offline

#6 2006-06-14 20:29:18

battra
Member
From: Earth.US.Illinois.Chicago
Registered: 2006-05-12
Posts: 71

Re: orphans

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

#7 2006-06-14 20:58:26

kakabaratruskia
Member
From: Santiago, Chile
Registered: 2003-08-24
Posts: 596

Re: orphans

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

#8 2006-06-14 21:00:22

insane
Member
Registered: 2006-06-04
Posts: 106

Re: orphans

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

#9 2006-06-14 21:15:15

Speek
Member
Registered: 2005-04-07
Posts: 36

Re: orphans

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

Offline

#10 2006-06-14 21:18:16

Speek
Member
Registered: 2005-04-07
Posts: 36

Re: orphans

insane wrote:

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

#11 2006-06-14 21:36:00

insane
Member
Registered: 2006-06-04
Posts: 106

Re: orphans

Its OK now. Something had to do with copying/pasting in kwrite. Tried mcedit and it's all fine. Thanks for the script  smile

Offline

#12 2006-06-14 22:16:16

jaboua
Member
Registered: 2005-11-05
Posts: 634

Re: orphans

Thanks... Finally I don't have to do the process manually anymore  tongue

Offline

#13 2006-06-14 22:35:30

postlogic
Member
Registered: 2005-02-24
Posts: 410
Website

Re: orphans

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

#14 2006-06-14 23:54:33

neotuli
Lazy Developer
From: London, UK
Registered: 2004-07-06
Posts: 1,204
Website

Re: orphans

Speek wrote:

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

#15 2006-06-15 05:41:06

battra
Member
From: Earth.US.Illinois.Chicago
Registered: 2006-05-12
Posts: 71

Re: orphans

Speek wrote:
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

#16 2006-06-29 00:33:22

gizmo
Member
From: Norway
Registered: 2006-02-22
Posts: 27

Re: orphans

how do i run this? i get the same error as insane.. sh orphans??

Offline

#17 2006-06-29 04:53:20

McQueen
Member
From: Arizona
Registered: 2006-03-20
Posts: 387

Re: orphans

gizmo wrote:

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

#18 2006-06-29 06:04:52

twiistedkaos
Member
Registered: 2006-05-20
Posts: 666

Re: orphans

gizmo wrote:

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

#19 2006-06-29 07:05:24

mucknert
Member
From: Berlin // Germany
Registered: 2006-06-27
Posts: 510

Re: orphans

Great Script, indeed! smile 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

#20 2006-06-29 15:38:45

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: orphans

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

#21 2006-06-29 18:43:59

gizmo
Member
From: Norway
Registered: 2006-02-22
Posts: 27

Re: orphans

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

#22 2006-06-29 19:04:32

insane
Member
Registered: 2006-06-04
Posts: 106

Re: orphans

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

#23 2006-06-29 20:41:09

McQueen
Member
From: Arizona
Registered: 2006-03-20
Posts: 387

Re: orphans

insane wrote:

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

#24 2006-07-31 02:29:08

meow
Member
Registered: 2006-07-31
Posts: 7

Re: orphans

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

#25 2006-10-15 12:08:44

Romashka
Forum Fellow
Registered: 2005-12-07
Posts: 1,054

Re: orphans

meow wrote:

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

Board footer

Powered by FluxBB