Here's what may be a more complete implementation since it will allow you to search the MANIFEST for any program, file or library:
Code:
#!/bin/sh
# This is a script to answer the question "In which Slackware package(s) does
# the file <query_filename> belong to?". Typically the user would have to
# manually consult the MANIFEST.gz file on the Slackware CD-ROM to find out
# this information. This file can be helpful for the testldddeps script, made
# by me also.
#
# Cameron R Kerr
# Last revised: 27 August 2001
# cameron.kerr@paradise.net.nz
# http://homepages.paradise.net.nz/~cameronk/
#
# Please send any improvements back to me to share with the world.
#
# Modified by Gilbert Ashley
# 3 July 2005
# Added support for bzip2 Manifests
function usage()
{
echo -n "USAGE: `basename $0` " >&2
echo "[-h|--help] | [-e|--exact] [-s|--show] <MANIFEST[.gz|.bz2]> <query>" >&2
echo "Version: 19 August 2001 Author: cameron.kerr@paradise.net.nz" >&2
exit 1
}
# Deal with program arguments
TEMP=`getopt -n \`basename $0\` --longoptions="help,exact,show" "hes" "$@"`
eval set -- "${TEMP}"
EXACT=0
SHOW=0
while true
do
case "$1" in
-h|--help) usage;;
-e|--exact) EXACT=1; shift;;
-s|--show) SHOW=1; shift;;
--) shift; break;;
*) echo "Internal error!"; exit 1;;
esac
done
MANIFEST="$1"; shift
QUERY="$1"; shift
# Lets support reading gzip'd versions of MANIFEST, since it is by default.
FILETYPE=`file "${MANIFEST}"`
if [ "`echo ${FILETYPE} | grep 'gzip compressed data'`" ]; then
CATTER=zcat
elif [ "`echo ${FILETYPE} | grep 'bzip2 compressed data'`" ]; then
CATTER=bzcat
elif [ "`echo ${FILETYPE} | grep 'ASCII text'`" ]; then
CATTER=cat
else
echo " Sorry! invalid file format for ${MANIFEST} ." >&2
echo " Give the path to a valid Slackware MANIFEST" >&2
echo " file. Either MANIFEST.bz2, MANIFEST.gz or the" >&2
echo " decompressed MANIFEST file." >&2
exit 2
fi
# Handle the case where /usr/bin/... is given, as it is stored as usr/bin/...
# in the MANIFEST
QUERY_INTERNAL="`echo \"${QUERY}\" | sed -e 's/^\///'`"
# If the user has asked for exact matching, append a space at the end.
if [ $EXACT == 1 ]; then
QUERY_INTERNAL="${QUERY_INTERNAL} "
fi
# If the user has asked for fully qualifed matching, prepend a space
echo "Please wait while searching..."
${CATTER} ${MANIFEST} | awk '
BEGIN {
starting = 1
}
/^\|\| Package: / {
if( starting == 1 )
starting = 0
else
printf( "\n" )
printf( "%s ", $3 )
}
/^[-bcdlps][-r][-w][-xsS][-r][-w][-xsS][-r][-w][-xtT][[:space:]]/ {
printf( "%s ", $6 )
}
END {
printf( "\n" )
}
' | fgrep "${QUERY_INTERNAL}" | cut -d' ' -f1
exit 0
A possible improvement might do something about integrating multiple MANIFESTS -that is mANIFESTS from /patches or /extra might be looked at first.
I use the script as posted as part of a ROX AppDir with several slackware package-related tools integrated. Just clicking the AppDir opens pktool in an xterm. Right-clicking gives me a menu with choices to list installed packages quickly using 'ls /var/log/packages/*', search for the installed package which contains a certain file or search for a file in 'all' available slack packages (the script above). Very handy and much faster than opening an xterm and entering these often-used commands manually. You could even create menu entries for your favorite window manager which would do the same thing.