|
- #!/bin/bash
- # whichpkg - list the slackware package(s) which installed
- # the given file or directory;
- # syntax: whichpkg name [...]
- #
- # starts with strict tests: full match on file or directory;
- # if nothing found, try full match on .new or in;
- # if nothing found, try substring match;
- # multiple arguments are handled recursively.
- #
- # copyright 2004 by William Hunt, all rights reserved.
- # distributed under terms of the Gnu Public License, version 2 or later.
- # master distribution at [url]ftp://prv8.net/slackstuff/[/url]
- DATA=/var/log/packages/*
- [ "$1" = . ] || [ "$1" = .. ] && shift # skip if given
- [ "${1:0:2}" = ./ ] && F=${1:2} || F=$1 # trim relative root if given
- [ "${1:0:1}" = / ] && F=${1:1} # trim absolute root if given
- [ -z $F ] && exit # argument required
- x=$( grep ^$F$ ${DATA} )
- [ -z "$x" ] && x=$( grep ^$F/$ ${DATA} )
- [ -z "$x" ] && x=$( grep ^$F.new$ ${DATA} )
- [ -z "$x" ] && x=$( grep ^$F.in$ ${DATA} )
- [ -z "$x" ] && x=$( grep /$F/$ ${DATA} | grep -v ":.*:" )
- [ -z "$x" ] && x=$( grep /$F.new$ ${DATA} | grep -v ":.*:" )
- [ -z "$x" ] && x=$( grep /$F.in$ ${DATA} | grep -v ":.*:" )
- [ -z "$x" ] && x=$( grep /$F$ ${DATA} | grep -v ":.*:" )
- for a in $x ; do b=${a%:*} ; echo ${b##*/} ; done | uniq
- shift ; $0 $* # recursion.
- # tha-tha-tha-that's all, folks!
复制代码 |
|