Unix Technical Forum

script: whichpkg - which package installed that file?

This is a discussion on script: whichpkg - which package installed that file? within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Every so often the question comes up, "which package installed that file?" This little script tries to answer that ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-19-2008, 08:29 AM
William Hunt
 
Posts: n/a
Default script: whichpkg - which package installed that file?


Every so often the question comes up,
"which package installed that file?"

This little script tries to answer that question as
concisely as possible, accepting input in several forms.

Enjoy!

----- snip here ----------------------------------------
#!/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 ftp://prv8.net/slackstuff/
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!
----- snip here ----------------------------------------

--
William Hunt, Portland Oregon USA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-19-2008, 08:29 AM
richard
 
Posts: n/a
Default Re: script: whichpkg - which package installed that file?

William Hunt wrote:

> Every so often the question comes up,
> "which package installed that file?"
>
> This little script tries to answer that question as
> concisely as possible, accepting input in several forms.
>
> Enjoy!
>
> ----- snip here ----------------------------------------
> #!/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 ftp://prv8.net/slackstuff/
> 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!
> ----- snip here ----------------------------------------
>


You know what would be good is a program that hunts through your hard
drive and looks for files that do not come from a package. Of course it
would skip home directories and /dev and /tmp etc. Then it would allow
you to group those files so you can create packages. From those loose files.

Also another good program would be one that looks at a file in
/var/log/packages and recreates that package from the files listed.
Unfortunatley it wouldn't get thinks like symlinks.

Richard
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-19-2008, 08:31 AM
George Georgakis
 
Posts: n/a
Default Re: script: whichpkg - which package installed that file?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

William Hunt <wjh@huntbros.net> wrote:

> 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.


Heh. A similar concept with this script snippet (extracted from my
old workhorse, checkpkg. Old code, but it still works for me):

#!/bin/sh
cd /var/log/packages/ ; SEARCH=`grep "/$1"$ * | grep -v " " | \
grep -v "doc" | awk '{print $1}' | sed -e s/"\:"/" "/g`
[ ! "$SEARCH" ] && (cd /var/log/packages/ ;
SEARCH=`grep "/$1\.new"$ * | grep -v " " |\
grep -v "doc" | awk '{print $1}' | sed -e s/"\:"/" "/g`)
echo "$SEARCH"

Only checks for .new suffixes, though.

- --
George Georgakis-geeg AT tripleg net au-http://www.tripleg.net.au/
SlackBuild Central - http://slackpack.tripleg.net.au/

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>

iQA/AwUBQDQvlklp3nJf7PixEQIWMwCfQV/vbL16oCZ/KlEQJ7AM5uXqmaAAni6l
LUZQhWq7CDmFGafeWQ0gTUvK
=Tt5N
-----END PGP SIGNATURE-----
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-19-2008, 08:31 AM
George Georgakis
 
Posts: n/a
Default Re: script: whichpkg - which package installed that file?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

richard <c@dog.bird.eu> wrote:

> You know what would be good is a program that hunts through your hard
> drive and looks for files that do not come from a package. Of course it
> would skip home directories and /dev and /tmp etc. Then it would allow
> you to group those files so you can create packages. From those loose
> files.


Too tricky, too many variables involved. Especially on multi-user
machines.

> Also another good program would be one that looks at a file in
> /var/log/packages and recreates that package from the files listed.
> Unfortunatley it wouldn't get thinks like symlinks.


That's different -- /var/log/scripts/ contains a list of symlinks
created by a package.

- --
George Georgakis-geeg AT tripleg net au-http://www.tripleg.net.au/
SlackBuild Central - http://slackpack.tripleg.net.au/

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>

iQA/AwUBQDQwwklp3nJf7PixEQJTPQCgq9LKifKaDCrSB4aq+ENb83 wBT8YAoIyw
2C3jtbW3JOowCq/dfcgcSu83
=1Ytj
-----END PGP SIGNATURE-----
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:11 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com