pkg equivalent of "pkg_info -R"

R. Scott Evans freebsd-questions at rsle.net
Fri Mar 7 17:30:04 UTC 2014


On 03/07/14 11:15, Andrea Venturoli wrote:
> On 03/07/14 07:54, Matthew Seaman wrote:
>
>> Yes, being able to generate the entire dependency tree would be a
>> desirable option.
>
> Exactly.
>
> In the example I gave, the rationale was, after the vulnerabiliy in 
> gnutls, getting a list of services which needed restarting.
>
>> It's not particularly difficult, but it does require
>> implementing recursive behaviour for such lookups.  That just needs
>> someone to step up and code it...
>
> I was just surprised that some funcionality I very often use was gone.
> Perhaps I'm doing things in a peculiar ways?
> Are there so few people doing this, that it could be overlooked?
>
> Of course, getting back to the previous example, listing the binaries 
> which are linked against gnutls might be another route...
>
>> Until then, you'ld have to write a shell wrapper around pkg query to
>> achieve the same effect.
>
> Ok.
> I'd just hate do duplicate work...
>
>  bye
>     av.
Okay, you got a python solution but here's my bourne shell version (I 
dislike python  :-)

-scott

#!/bin/sh
# Show ALL ports required for a given port.
################################################################################

WORK=`pkg info -r $1 | grep -v ":"`

while [ "X$WORK" != "X" ]; do
         for word in $WORK; do
                 if [ "X$NEW" = "X" ]; then
                        NEW=$word
                 else
                         NEW="$NEW $word"
                 fi

                 CHECK=`pkg info -r $word | grep -v ":"`
                 for new in $CHECK; do
                         testN=`echo "$NEW" | grep -w $new`
                         testW=`echo "$WORK" | grep -w $new`
                         if [ "X$testN" = "X" ] && [ "X$testW" = "X" ]; then
                                 WORK="$WORK $new"
                         fi
                 done

                 WC=`echo $WORK | wc -w | cut -w -f 2`
                 if [ $WC = 1 ]; then
                         WORK=""
                 else
                         WORK=`echo $WORK | cut -d ' ' -f 2-$WC`
                 fi
         done
done

## PRINT ALL RESULTS ON ONE (LONG) LINE
#echo $NEW

## OR THE RESULTS, ONE ENTRY PER LINE (easier to sort)
for X in $NEW; do
         echo $X
done


More information about the freebsd-questions mailing list