Subject: Re: finding the leaf packages
To: Geert Hendrickx <ghen@NetBSD.org>
From: Johnny Lam <jlam@pkgsrc.org>
List: pkgsrc-users
Date: 06/16/2006 10:49:06
Geert Hendrickx wrote:
> On Fri, Jun 16, 2006 at 10:09:30AM -0400, Johnny Lam wrote:
>> Steven M. Bellovin wrote:
>>> Is there some simple way to get a list of all leaf packages, in the form
>>> of, say, pkg_tools/pkgdepgrah.  (I use that as a non-random example, since
>>> it obviously knows how to do that, but I haven't figured out the options
>>> to do it in any way other than as input to graphviz.)
>> Metadata-wise, it's the list of all directories in ${PKG_DBDIR} 
>> (/var/db/pkg) that do not have a +REQUIRED_BY file, [...]
> 
> ... or an empty one.  

The following small change (using "test -s" instead of "test -f") should 
cover this possibility:

#!/bin/sh

: ${PKG_DBDIR=/var/db/pkg}

cd ${PKG_DBDIR}
for dir in *; do
         test -d "$dir" || continue
         test -s "$dir/+REQUIRED_BY" || echo "$dir"
done

	Cheers,

	-- Johnny Lam <jlam@pkgsrc.org>