Saturday, March 06, 2004

Removing Packages with pkg_cutleaves

You may have read Dru Lavigne's article on Cleaning and Customizing Your Ports. She mentioned used portsclean to remove working directories and distfiles with 'portsclean -CDD':

orr:/root# portsclean -CDD
Cleaning out /usr/ports/*/*/work...
Delete /usr/ports/sysutils/gkrellm2/work
Delete /usr/ports/net/netmap/work
Delete /usr/ports/graphics/graphviz/work
Detecting unreferenced distfiles...
Delete /usr/ports/distfiles/graphviz-1.10.tar.gz
Delete /usr/ports/distfiles/legacy_132beta4_src.tar.gz
Delete /usr/ports/distfiles/netmap-0.1.2b.tar.gz

I learned of another housekeeping tool called pkg_cutleaves. It looks at installed packages and notifies the user of packages upon which no other package depends. These "leaf packages" might be candidates for removal. When you run the tool, pkg_cutleaves asks if you want to keep or deinstall each leaf package:

Package 1 of 108:
OpenSSH-askpass- - Graphical password applet for entering SSH passphrase
OpenSSH-askpass- - [keep]/(d)elete/(f)lush marked pkgs/(a)bort?
** Keeping OpenSSH-askpass-

Package 2 of 108:
XFree86-documents-4.3.0 - XFree86-4 documentation
XFree86-documents-4.3.0 - [keep]/(d)elete/(f)lush marked pkgs/(a)bort?
** Keeping XFree86-documents-4.3.0.


Package 9 of 108:
asclock-1.0 - Afterstep clock with some language extentions
asclock-1.0 - [keep]/(d)elete/(f)lush marked pkgs/(a)bort? d
** Marking asclock-1.0 for removal.


Deleting asclock-1.0 (package 1 of 8).
[Updating the pkgdb in /var/db/pkg ... - 269 packages found (-0 +4) .... done]
---> Deinstalling 'asclock-1.0'
[Updating the pkgdb in /var/db/pkg ... - 268 packages found (-1 +0) (...) done]

When done with the first round of deletions, pkg_cutleaves checks again to see if any of the deletions created new leaf packages. If so, the user is asked to keep or delete those. When totally done, pkg_cutleaves informs the user of all packages it deleted.