Newbie - Keeping a macport installation clean

J.A. Neitzel mp+u at v6shell.org
Mon Dec 29 00:53:04 PST 2008


Thomas Gommes <tgommes at gmail.com> wrote:

> after a couple of year using Gentoo Linux, I moved to Mac OS and was 
> very happy to discover Macport. I have been playing around with it since 
> a couple of days, installing and removing quite some stuff. I was now 
> wondering if there was a way to keep the macport installation clean.

I guess it depends on what exactly you mean by clean ;)

For example, since I keep a set of installed ports around long
enough, keeping my MacPorts installation clean means uninstalling
"inactive" ports while keeping everything up to date.

The following fills this need for me:

% sudo port selfupdate
% sudo port upgrade outdated
% sudo port uninstall inactive

> What I'm looking for is the equivalent of the Gentoo "emerge depclean" 
> and "revdep-rebuild" commands; the idea is that the installation of 
> package 1 also installs package 2 and package 3 as dependencies. 

[snip]

In the normal case, MacPorts does not allow you to uninstall a port
if other port(s) depend on it.  Fortunately, a little shell goes a
long way to determine what depends on what.  I translated an osh(1)
script that I use into sh(1) and inlined it below [1].

For example, when you uninstall something you can run this to see
if there are any ports left that have "no dependents".  These ports
are now at the end of the dependency chain.  If you do not need
them, then you can do a:

% sudo port uninstall <port(s)_in_question>

...
to uninstall them.

Welcome to Mac OS X and MacPorts.
-- 
J.A. Neitzel
V6 Thompson Shell Port - http://v6shell.org/

[1] (mpdepinfo):
#!/bin/sh -

# mpdepinfo - print 2 lists of dependents in the following forms
#	1) <port> depends on <port>
#	2) <port> has no dependents!

umask 0077

dir="/tmp/`basename $0`-$$"
fil="$dir/cmdfil"
trap 'rtn=$?; rm -rf $dir; exit $rtn' EXIT
trap 'exit $?' HUP INT QUIT TERM

mkdir "$dir" || exit 2

(
	IFS='
'
	for p in `port installed | sed '1d ; s/^  // ; s/ (active)$//'` ; do
		echo dependents "$p"
	done
) >"$fil"

port -F "$fil" | egrep -v '^$|no dependents' | sort
echo
port -F "$fil" | grep 'no dependents' | sort


More information about the macports-users mailing list