pkg equivalent of "pkg_info -R"
Jan Henrik Sylvester
me at janh.de
Sun Mar 9 11:05:40 UTC 2014
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
More information about the freebsd-questions
mailing list