Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 09 Mar 2014 12:05:18 +0100
From:      Jan Henrik Sylvester <me@janh.de>
To:        "R. Scott Evans" <freebsd-questions@rsle.net>
Cc:        questions-list freebsd <freebsd-questions@freebsd.org>
Subject:   Re: pkg equivalent of "pkg_info -R"
Message-ID:  <531C4AEE.6030007@janh.de>
In-Reply-To: <531A0210.3070705@rsle.net>
References:  <53186ABC.5060601@netfence.it> <20140306184030.078a99cedac859b5c5b83e22@embarqmail.com> <53196D17.8000300@FreeBSD.org> <5319F0B7.3030200@netfence.it> <531A0210.3070705@rsle.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On 03/07/2014 18:29, R. Scott Evans wrote:

>> On 03/07/14 07:54, Matthew Seaman wrote:
>>
>>> Yes, being able to generate the entire dependency tree would be a
>>> desirable option.

> Okay, you got a python solution but here's my bourne shell version (I
> dislike python  :-)

Your script was a little bit slow for my taste, since it does many
external calls. As I needed a script for dependencies myself (not
reverse, which can be printed by pkg delete -Rn), I rewrote it using

- as few calls to pkg as possible, only as many as the depth of recursion,
- origins instead of names and versions,
- pkg query instead of pkg info,
- and no other external calls.

For gnutls on my system, your script needs 5s and mine .2s, while pkg
delete -Rn needs .07s, which is probably as fast as possible. The next
person should really patch pkg query itself.

Cheers,
Jan Henrik


#!/bin/sh
[ "$1" = "-h" ] && { echo "\
NAME: $0 -- pkg query recursive dependencies or reverse dependencies
SYNOPSIS: $0 [-r] [-gix] <pkg-name[s]|pattern>
OPTIONS: -r for reverse dependencies [-gix] is passed to pkg query\
" ; exit 0 ; }
[ "$1" = "-r" ] && { DEP=r ; shift ; } || DEP=d
[ "$1" != "${1#-}" ] && { OPTIONS=$1 ; shift ; } || OPTIONS=
## using %o temporarily is significantly fast than %n-%v directly ##
DEP_COMMAND="pkg query $OPTIONS %${DEP}o"
S='
'
LIST="$S$($DEP_COMMAND "$@")$S"
NEW=$LIST
while [ ${#NEW} -gt 2 ]
do
    TRY=$NEW
    NEW=$S
    for TRY in $($DEP_COMMAND $TRY)
    do
        if [ "$LIST" = "${LIST%%$S$TRY$S*}" ]
        then
            NEW="$NEW$TRY$S"
            LIST="$LIST$TRY$S"
        fi
    done
done
## for origins, use instead: printf %s "${LIST#$S}" ##
[ ${#LIST} -gt 2 ] && pkg query %n-%v $LIST




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?531C4AEE.6030007>