There's probably a nice base system tool for this, and definitely a better way to script this, but I wrote a little script to get information about ports from the ports tree (dependencies, compile time options, pkg-descriptions, etc.)
I hope someone will find it useful!
I'm just beginning to learn shell scripting, so any suggestions, comments, etc, are very welcome.
I hope someone will find it useful!
I'm just beginning to learn shell scripting, so any suggestions, comments, etc, are very welcome.
Code:
#!/bin/sh
###########################################################################
# This script will allow user to search the ports tree and display port
# categories, port names, port descriptions and dependency information.
###########################################################################
# set ports tree directory
pdir="/usr/ports"
# This is the help function which is called in case of wrong usage or the -h option.
help() {
echo "usage:
`basename $0` [-a "string"] - print name, path, info, and dependencies for given string
`basename $0` [-b port-name] - print build dependencies for given port
`basename $0` [-d port-name] - print ALL dependencies for given port(s) recursively
`basename $0` [-h] - print this help
`basename $0` [-c category-name] - list category contents
`basename $0` [-C] - list all categories in ports
`basename $0` [-m port-name] - print missing dependencies for given port
`basename $0` [-n port-name] - display pkg-descr contents for given port
`basename $0` [-o port-name] - print compile-time options for given port
`basename $0` [-s "string"] - search for given port
`basename $0` [-S "string"] - search all "pkg-descr" files for given string
`basename $0` [-r port-name] - print runtime dependencies for given port"
}
# This is what is run if no command line argument is given
if [ -z "$1" ]
then
help
exit 1
fi
# These are the main commands to be run for a given option.
while getopts "a:b:c:Cd:hm:n:o:s:S:r:" opt; do
case "$opt" in
a) cd $pdir && make search name=$2 ;;
b) make -C $pdir/*/$2 build-depends-list | sed s:$pdir/:: | sort -d | column ;;
c) ls -d $pdir/$2/*/ | sed s:$pdir/$2/:: | column ;;
C) ls -d $pdir/*/ | sed s:$pdir/:: | column ;;
d) make -C $pdir/*/$2 all-depends-list | sed s:$pdir/:: | sort -d | column ;;
h) help ;;
m) make -C $pdir/*/$2 missing | sed s:$pdir/:: | sort -d | column ;;
n) more $pdir/*/$2/pkg-descr ;;
o) make -C $pdir/*/$2 showconfig ;;
s) find $pdir/* -maxdepth 1 -iname *$2* | sed s:$pdir/:: | sort -d | column ;;
S) for i in $pdir/*/*/pkg-descr; do grep -il "$2" $i | xargs dirname | sed s:$pdir/:: ; done ;;
r) make -C $pdir/*/$2 run-depends-list | sed s:$pdir/:: | sort -d | column ;;
\?) echo "Type "`basename $0` -h" for help." >&2 ;;
esac
done