On Fri, Nov 6, 2009 at 2:42 AM, <[email protected]> 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
>
>
I made a patch to streamline a few things (such as using cat when the
command accepting its output can take a file argument anyway) and put
the rm commands onto one line. Here it is, in unified format:
--- pkg_estimate.orig.sh Fri Nov 06 11:59:58 2009
+++ pkg_estimate.sh Fri Nov 06 12:02:52 2009
@@ -2,6 +2,7 @@
# Find the full depency list for a given package
# in cmd. line
# Assumes one is in a dir with all packages
+# or PKG_PATH is available
# Temporary files
tmp_file_1=$(mktemp)
@@ -14,7 +15,7 @@
over=0
while [ $over -ne 1 ]
do
- cat $tmp_file_1 | fgrep -v -f $tmp_file_3 \
+ fgrep -v -f $tmp_file_3 $tmp_file_1 \
| xargs -I % pkg_info -f % \
| fgrep @depend | cut -d : -f 3 \
| grep -v '^$' | sort \
@@ -26,31 +27,28 @@
over=1
fi
cat $tmp_file_1 >> $tmp_file_3
- cat $tmp_file_2 > $tmp_file_1
+ cp -f $tmp_file_2 $tmp_file_1
ctr=$(( ctr+1 ))
done
-cat $tmp_file_2 | sort | uniq > /tmp/$1-dependencies
+sort $tmp_file_2 | 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'`
+count=`sort $tmp_file_2 | 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 % \
+sort $tmp_file_2 | 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
+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
\ No newline at end of file
+rm -rf $tmp_file_1 $tmp_file_2 $tmp_file_3
\ No newline at end of file
--
Aaron Mason - Programmer, open source addict
I've taken my software vows - for beta or for worse