On Fri, Nov 6, 2009 at 2:42 AM,  <srikant....@gmail.com> wrote:
> Hi
>
> Just wanted to share a script with fellow OpenBSD
> desktop users who like to keep minimal non-base
> software on the machine and prefer to use lighter
> alternatives whenever possible.
>
> This script will help you estimate the total space
> which will be used by a given package as well as
> all the dependencies (recursively).
>
> It has to be run inside a directory with your
> mirror of all packages. The o/p is a text file
> in /tmp directory.
>
> This was made quickly for myself long time back.
> Please consider the quality as such. Works for me.
> Hope it can come in handy to someone.
>
> Take care.
>
> Srikant.
>
> ---------
>
> #!/bin/sh
> # Find the full depency list for a given package
> # in cmd. line
> # Assumes one is in a dir with all packages
>
> # Temporary files
> tmp_file_1=$(mktemp)
> tmp_file_2=$(mktemp)
> tmp_file_3=$(mktemp)
>
> echo $1 > $tmp_file_1
>
> ctr=0
> over=0
> while [ $over -ne 1 ]
> do
>        cat $tmp_file_1 | fgrep -v -f $tmp_file_3 \
>                | xargs -I % pkg_info -f % \
>                | fgrep @depend | cut -d : -f 3 \
>                | grep -v '^$' | sort \
>                | uniq >> $tmp_file_2
>
>        md5_old=`cat $tmp_file_1 | md5`
>        md5_new=`cat $tmp_file_2 | md5`
>        if [ `echo $md5_new | fgrep -xc $md5_old` -eq 1 ]; then
>                over=1
>        fi
>        cat $tmp_file_1 >> $tmp_file_3
>        cat $tmp_file_2 > $tmp_file_1
>        ctr=$(( ctr+1 ))
> done
>
> cat $tmp_file_2 | sort | uniq > /tmp/$1-dependencies
> echo "-----" >> /tmp/$1-dependencies
> ctr=$(( ctr-2 ))
> echo "No. of levels of dependencies : $ctr" \
>        >> /tmp/$1-dependencies
> count=`cat $tmp_file_2 | sort | uniq | wc -l | sed 's/ //g'`
> echo "No. of dependencies : $count" \
>        >> /tmp/$1-dependencies
>
> cat $tmp_file_2 | sort | uniq | xargs -I % pkg_info -s % \
>        | fgrep Size: | awk '{ print $2 }' > $tmp_file_3
> siz=0
> {
> while read rline
> do
>        siz=$(( siz+rline ))
> done
> } < $tmp_file_3
> echo "Estimated total size of dependencies: $siz" \
>        >> /tmp/$1-dependencies
>
> rm -rf $tmp_file_1
> rm -rf $tmp_file_2
> rm -rf $tmp_file_3
>
>

It works great, by the way.  Tested on 4.6 release.  I'd probably also
cat the contents of /tmp/$1-dependencies, but that's just me.

--
Aaron Mason - Programmer, open source addict
I've taken my software vows - for beta or for worse

Reply via email to