Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Script that will list package deps. that can be removed
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Wed Jul 17, 2002 3:46 am    Post subject: Script that will list package deps. that can be removed Reply with quote

When you uninstall a package in emerge, there is currently no way to tell:
a. what packages were installed because of this package
b. if you could list items in a., which ones could you remove without breaking dependencies in other packages.

The following script does this.

(Updated with minor clean-up)
7/24/02: minor fix-up to "echo Usage" based on feedback from Dolio below.
Code:

#!/bin/bash

#
# Finds out dependencies of a package that CAN be removed when a package is
# uninstalled.  Basic procedure is as follows:
# a. construct a list of dependencies for the package using emerge -pe.  This
#    is the list of items that will tentatively be removed
# b. go through the list of installed packages and create a list with these
#    packages minus the list of dependencies and masked packages
# c. construct a list of dependencies for the list from step b.
# d. construct list of dependencies from a. that can be removed, based on
#    checks against c and world packages
#
# NB.
# a. Make sure you go through the list it suggests and cull any dubious items
# b. Versions are stripped out of all checks.  So it may be over conservative
#    in suggesting removals.  This is good :)

if [ $# == 0 ]; then
        echo -e 'Usage: '$0' [package...]'
        echo -e 'where package is a full or partial name of an installed package'
        exit
fi

# Need recent version of portage in order to test for masked packages.
# One could root through the masked package list, but that would be too hard :)
pv=(`emerge --version|sed 's/Portage \([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)/\1 \2 \3/g'`)
if (( ${pv[0]} < 2 || (( ${pv[0]} == 2 && ${pv[1]} == 0 && ${pv[2]} < 13 )) )); then
        echo -e 'Incorrect portage version'
        echo -e 'Need 2.0.13 or greater'
        exit
fi

# useful sed strings
ebuild_strip='s/^\[ebuild[^]]*\] \([^ ]*\) .*/\1/g'
hdr_del='1,4d'
last_del='$d'
rev_strip='s/-r[0-9]\+$//'
ver_strip='s/-[0-9][^-]*$//'
mask_strip='s/^.\{20\}\(.*\).\{27\}$/\1/g'

# dependencies of the package that will be removed
contents=`emerge -pe $@ | sed -e "$ebuild_strip" -e "$hdr_del" -e "$last_del" -e "$rev_strip" -e "$ver_strip"`

# masked packages
masked=`emerge -s "." | grep Masked | sed -e "$mask_strip"`

# look through installed packages to build a list with following exceptions
# a. packages whose ebuilds are not in portage
# b. packages that are dependencies of the package to be uninstalled
# c. packages that are masked
for instpkg in `/usr/lib/portage/bin/pkglist | sed -e "$rev_strip" -e "$ver_strip"`; do
        for chk in $contents $masked; do
                if [ $instpkg == $chk ]; then
                        continue 2
                fi
        done
        if [ -e /usr/portage/$instpkg ]; then
                allinst="$allinst $instpkg"
        else
                # for packages that have been moved, use the package name alone
                # build the list separately in case package is really gone
                instpkg=`echo $instpkg | sed 's:^[^/]*/::g'`
                allneeded="$allneeded `emerge -pe $instpkg | sed -e "$ebuild_strip" -e "$hdr_del" -e "$last_del" -e "$rev_strip" -e "$ver_strip"`"
        fi
done

# generate list of dependencies of 'all' installed packages
allneeded="$allneeded `emerge -pe $allinst | sed -e "$ebuild_strip" -e "$hdr_del" -e "$last_del" -e "$rev_strip" -e "$ver_strip"`"

# top level packages that should not be removed
world=`emerge -pe --nodeps world | sed -e "$ebuild_strip" -e "$hdr_del" -e "$last_del" -e "$rev_strip" -e "$ver_strip"`

# finally, packages can be removed only if they are not in the world
# or needed lists
{
        for pkg in $contents; do
                for need in $allneeded $world; do
                        if [ $pkg == $need ]; then
                                continue 2
                        fi
                done
                echo $pkg
        done
} | sort | uniq


Last edited by Naan Yaar on Wed Jul 24, 2002 11:30 am; edited 3 times in total
Back to top
View user's profile Send private message
BonezTheGoon
Bodhisattva
Bodhisattva


Joined: 14 Jun 2002
Posts: 1379
Location: Albuquerque, NM -- birthplace of Microsoft and Gentoo

PostPosted: Wed Jul 17, 2002 1:08 pm    Post subject: Reply with quote

Wow, thanks!!! That is surely impressive, I will have to run some tests on this--but it looks really good! Nice job, maybe we can get this added into portage at some point?? You might consider asking to have this moved from tips and tricks to suggestions. Very slick!!

Thanks again,
BonezTheGoon
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Wed Jul 17, 2002 3:27 pm    Post subject: Reply with quote

Thanks. Let me know if you find any issues with this.

I believe that portage will implement "backward" dependencies sometime soon. I just couldn't wait till then :)
Back to top
View user's profile Send private message
Black666
n00b
n00b


Joined: 15 Jul 2002
Posts: 61
Location: Vienna (Austria)

PostPosted: Wed Jul 17, 2002 4:22 pm    Post subject: Reply with quote

Nice!! The only feature I was missing in portage so far.
Back to top
View user's profile Send private message
niyogi
Apprentice
Apprentice


Joined: 10 Apr 2002
Posts: 199
Location: Austin, TX

PostPosted: Wed Jul 24, 2002 4:52 am    Post subject: Reply with quote

anybody know whether this is in Portage's "to-do" list?

-S
Back to top
View user's profile Send private message
Dolio
l33t
l33t


Joined: 17 Jun 2002
Posts: 650

PostPosted: Wed Jul 24, 2002 6:33 am    Post subject: Usage Reply with quote

One little thing (not a big deal). On the usage, you used single quotes on the "echo '$0 ...'" so it actually prints out $0 instead of the first argument. Not sure if that's what you wanted.
_________________
They don't have a good bathroom to do coke in.
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Wed Jul 24, 2002 11:31 am    Post subject: Re: Usage Reply with quote

Thanks. Wasn't meant to do that :) I have actually seen it spew out $0 while testing without really having it register!
Dolio wrote:
One little thing (not a big deal). On the usage, you used single quotes on the "echo '$0 ...'" so it actually prints out $0 instead of the first argument. Not sure if that's what you wanted.
Back to top
View user's profile Send private message
shoot2kill
n00b
n00b


Joined: 07 Jun 2002
Posts: 9

PostPosted: Wed Jul 24, 2002 7:36 pm    Post subject: Reply with quote

Now I know the list of packages which can be removed safely. How do I remove them? This can be done all at once at a time or one package at a time?
Back to top
View user's profile Send private message
niyogi
Apprentice
Apprentice


Joined: 10 Apr 2002
Posts: 199
Location: Austin, TX

PostPosted: Wed Jul 24, 2002 7:48 pm    Post subject: Reply with quote

it looks like this script executes silently... you have no idea what it's doing and then it brings you back to the prompt.

perhaps a "-v" parameter that lets you see what's happening behind the scenes.

also, usually what can happen is somebody will unmerge a package and then say "oh man. what dependencies were there?" but this script can't handle that... it can only handle those that are still installed and want to be uninstalled along with any orphaned dependencies.

still a great script to keep your system streamlined! :)

-niyogi
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Wed Jul 24, 2002 8:33 pm    Post subject: Reply with quote

In the grand old Unix tradition :) Seriously, I don't like colored and pretty formatted output that cannot be turned off since you have to do gory sed/awk hacks to strip the crud off. The -v option is a good idea - I was thinking about it too.
Quote:
it looks like this script executes silently... you have no idea what it's doing and then it brings you back to the prompt.
perhaps a "-v" parameter that lets you see what's happening behind the scenes.


I think this should be handled correctly. I tested it with packages that have not been installed yet. For example, I do emerge -pu wampager (which I don't have installed). It gave me wampager and a few other packages. When I do <script> wampager, it did give me what could have been cleanly removed if wampager was installed and then uninstalled (it does emerge -pe to get the dependenices of the specified package - it does not really matter whether it is installed).
Quote:

also, usually what can happen is somebody will unmerge a package and then say "oh man. what dependencies were there?" but this script can't handle that... it can only handle those that are still installed and want to be uninstalled along with any orphaned dependencies.


Thanks. :) It is a bit of a fudge, but still useful.
Quote:

still a great script to keep your system streamlined! :)

-niyogi
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Wed Jul 24, 2002 8:36 pm    Post subject: Reply with quote

Code:

emerge unmerge <package_names>


Can do more than one at a time.

shoot2kill wrote:
Now I know the list of packages which can be removed safely. How do I remove them? This can be done all at once at a time or one package at a time?
Back to top
View user's profile Send private message
shoot2kill
n00b
n00b


Joined: 07 Jun 2002
Posts: 9

PostPosted: Wed Jul 24, 2002 10:33 pm    Post subject: Reply with quote

Why is that the packages that i have already unmerged, are still showing from the list when using the scripts to check.
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Wed Jul 24, 2002 10:59 pm    Post subject: Reply with quote

Can you provide more details? Could be different versions.
Quote:

Why is that the packages that i have already unmerged, are still showing from the list when using the scripts to check.
Back to top
View user's profile Send private message
shoot2kill
n00b
n00b


Joined: 07 Jun 2002
Posts: 9

PostPosted: Wed Jul 24, 2002 11:03 pm    Post subject: Reply with quote

I am trying to remove the kde3 packages, I have removed most of the packages but stilll showing from the list when again using the script to check.
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Wed Jul 24, 2002 11:32 pm    Post subject: Reply with quote

Yes. It assumes that the package is installed fully (since it does an "emerge -pe"). If you can't see it not installed in emerge you are OK.

I was doing this to enable testing.
Back to top
View user's profile Send private message
shippy
n00b
n00b


Joined: 29 Sep 2002
Posts: 9

PostPosted: Wed Oct 09, 2002 4:06 pm    Post subject: Doesn't work for me Reply with quote

Unfortunately, this script doesn't work for me. I'm using Portage 2.0.36 under Gentoo 1.4_rc1. Whenever I run it, I get:

Code:

/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments


And this goes on forever (as far as I can tell).
_________________
Jeff Shipman
shippy@nmt.edu
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Thu Oct 10, 2002 2:58 am    Post subject: Re: Doesn't work for me Reply with quote

shippy wrote:
Unfortunately, this script doesn't work for me. I'm using Portage 2.0.36 under Gentoo 1.4_rc1. Whenever I run it, I get:

Code:

/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments
/usr/bin/unmerge_list: [: too many arguments


And this goes on forever (as far as I can tell).


yeah, I just tested it, and it does the same thing for me.
I'm using Portage 2.0.38, myself.

EDIT: gcc 2.95, if that even matters :) It shouldn't but I'm posting it to counter the last post saying gentoo 1.4_rc1.
Back to top
View user's profile Send private message
Hypnos
Advocate
Advocate


Joined: 18 Jul 2002
Posts: 2889
Location: Omnipresent

PostPosted: Sun Oct 20, 2002 11:08 am    Post subject: Reply with quote

Works nicely ... I used it to remove GNOME since I'm a Fluxbox devotee now.

Good job!

It'll be cool when the functionality is incorporated in the stock emerge.
Back to top
View user's profile Send private message
digitalnick
Apprentice
Apprentice


Joined: 30 Jun 2002
Posts: 243
Location: Lawrence KS USA

PostPosted: Tue Oct 22, 2002 1:49 am    Post subject: Reply with quote

i get same error on mine too many argumensts ... anyone know whats goin on?
Back to top
View user's profile Send private message
craftyc
Guru
Guru


Joined: 23 May 2002
Posts: 443
Location: Behind You.

PostPosted: Tue Oct 22, 2002 10:30 pm    Post subject: Reply with quote

When I run the script, it wants to remove baselayout! What went wrong?
_________________
Postcount ++
Back to top
View user's profile Send private message
H-Pi
Apprentice
Apprentice


Joined: 26 Jun 2002
Posts: 175
Location: Delft (NL)

PostPosted: Tue Oct 22, 2002 11:26 pm    Post subject: OK.. Reply with quote

craftyc wrote:
When I run the script, it wants to remove baselayout! What went wrong?


depends on which parameters you gave (whcih package you want to remove)

you do <script> <package>, so if you choose a package of which baselayout is a dep and it's no dep for other programs, the script says it can be removet

( think it's something like this, I must say I haven't studied the script too much :))
Back to top
View user's profile Send private message
y0el
n00b
n00b


Joined: 01 Aug 2002
Posts: 40
Location: Sweden

PostPosted: Wed Oct 30, 2002 2:25 pm    Post subject: Reply with quote

Umm... Forget my post... I got a little error in the script when I pasted it. :oops:
The script works great! Good job!
Something similar built into portage would make Gentoo even better...
Back to top
View user's profile Send private message
holek
Tux's lil' helper
Tux's lil' helper


Joined: 12 Jan 2003
Posts: 90
Location: Wroclaw, Poland

PostPosted: Sat Apr 05, 2003 3:27 am    Post subject: Reply with quote

I have a problem with this script.
When i run it i get no output at all :/
it's doing something cause my cpu usage is going to 99%
It does it for a while then stops, scripts ends without errors, but there is nothing on the console.
I f somebody could help me i would appriciate it very much.
_________________
... and the aliens sent an android down to earth, to slow down mankind's development ... and they named it Bill Gates.
Back to top
View user's profile Send private message
Crazor
Tux's lil' helper
Tux's lil' helper


Joined: 23 Apr 2003
Posts: 131

PostPosted: Sun Apr 27, 2003 9:42 pm    Post subject: Reply with quote

Can't help, but this script seems to do some weird stuff.
For example, running it on dev-java\sun-jdk-1.4.1.02-r1 gives some strange output:
Code:
"sun-jdk-1.4.1.02-r1".
are
ebuilds
emerge:
masked
no
satisfy
there
unmasked

also, it is running for quite a long time before outputting anything. is it normal that it is that slow?

[edit]been too fast with complaining. this strange output is only happening with the sun-jdk. with other packages, it works fine[/edit]
Back to top
View user's profile Send private message
garo
Bodhisattva
Bodhisattva


Joined: 15 Jul 2002
Posts: 860
Location: Edegem,BELGIUM

PostPosted: Mon Apr 28, 2003 7:06 am    Post subject: Reply with quote

Why do you need this script when you have "emerge depclean" ?
_________________
My favorite links this month:
- Surf Random
- Web-based SSH
- Stop Spam
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum