Edit: this script also now contains an "emerge depclean" that actually works, an "emerge prune" that actually looks at your dependencies, and a "qpkg -q" that isn't horribly broken!

A world file (/var/cache/edb/world) with lots of entries is no good for keeping your system clean and running smooth. Of course you need to go through it now and again to remove apps you don't want, but the job's easier if it contains as few 'extra' packages as possible i.e. packages that are actually deps on other packages.

Options:
-b, --no-build-time Omit dependencies needed solely to build PACKAGE
-o, --original-depends Calculate dependencies as when PACKAGE was merged
-a, --ask (default) For -[Pdw]: ask to perform action
-f, --force For -[Pdw]: perform action without asking
-p, --pretend For -[Pdw]: show what action would be taken

A package is unneeded if there is no installed package that depends on it.
An entry in the world file is redundant if there is another installed package
that depends on it.
When merging the new world file, the merging program used is sdiff(1).
Your world file is located at /var/lib/portage/world.

- You have package X in world and want it there.
- You install package Y which depends on X
- You run pruneworld which removes X as it is implied by Y
- You run emerge -c -C Y

Now you lost package X.

Should't is be possible to have an additional file (e. g. MyWorld) that holds packages you explicitly want to keep in the system. Your script could make shure to keep ale packages listed in theis file in world.

- You have package X in world and want it there.
- You install package Y which depends on X
- You run pruneworld which removes X as it is implied by Y
- You run emerge -c -C Y

Now you lost package X.

Imho this scenario is enough to not blindly follow the script recommandations. I've seen many such cases running the script where the Y depending on X was a package I may unmerge someday whereas X was really a must have (for instance, gphoto -> hotplug. I don't need gphoto anymore, and will probably unmerge it, but I really do need hotplug).

Also, the script is not completly safe regarding virtual packages I think. For instance:

If i remove this one, since nothing depends on the virtual, bittorent will probably get depcleaned. I think virtuals should only count if they are actually in the system class or depended on by another package.

iBormuth wrote:

Should't is be possible to have an additional file (e. g. MyWorld) that holds packages you explicitly want to keep in the system. Your script could make shure to keep ale packages listed in theis file in world.

You only move the issue to another file, but the whole problem remains to maintain such a file. Doing it completly automatically, based on emerge calls, is exactly what world is already. Doing it completly manually is not really realistic: count approx 300 entries for an average desktop system... you will always forget to add some stuff there, etc. Only a mix of automation and manual work seems really practical, and this is exactly the same as using only the world file with an occasional manual cleanup (which becomes easier with this script).

Side note: to keep your world file clean, don't forget the "--oneshot" emerge option. For instance, when you re-emerge a library because it is broken, adding the lib to the world file usually makes no sense. That's exactly what --oneshot is for.

I just cut and pasted this into scite and removed the leading spaces on each line. The script crashes with the error "Syntax Error: unexpected end of file" at line 192. Anything else I should do other than cutting and pasting?

I just cut and pasted this into scite and removed the leading spaces on each line. The script crashes with the error "Syntax Error: unexpected end of file" at line 192. Anything else I should do other than cutting and pasting?

I'm seeing exactly the same problem, although I simply cut and pasted it.

I just cut and pasted this into scite and removed the leading spaces on each line. The script crashes with the error "Syntax Error: unexpected end of file" at line 192. Anything else I should do other than cutting and pasting?

I'm seeing exactly the same problem, although I simply cut and pasted it.

This was solved by removing the trailing space after "END". I had to read the bash manual to find out about here documents.
I'm now seeing this error;

I have maintained my world file manually for over a year and I had a hard time believing that 1/3 of my world file entries were redundant. I moved the output to my world file (after a backup, of course) and emerge -pv depclean wanted to remove 39 packages. The script seems to ignore USE flags. Here's an example:

This makes emerge -pv depclean want to remove all of KDE! Has anyone else experienced this?_________________"Pulling together is the aim of despotism and tyranny. Free men pull in all kinds of directions."
Terry Pratchett, The Truth

I think you would have to put the system use flags into the environment variable USE...

Well that shouldn't be too hard. Thanks for the script ecatmur and keep up the good work. _________________"Pulling together is the aim of despotism and tyranny. Free men pull in all kinds of directions."
Terry Pratchett, The Truth

and both are removed from the world file. I think that it should leave gaim. It might be a problem with the dependencies of gaim and gaim-encryption, or I borked my world file, but it's something odd I noticed.