rworkman / slackpkg

Slackware's slackpkg
35 stars 12 forks source link

finding packages that files belong to #10

Open louigi600 opened 3 years ago

louigi600 commented 3 years ago

Hi Robby, I noticed a little thing with finding packages that files belong to so I wrote to Roberto and Evaldo but one of them told me that you are now the maintainer.

I very much enjoy using slackpkg but there is one thing that I find frustrating: finding which package contains a file (to help solve dependences on minimal systems).

I see that there is a file-search function but the output is somewhat not super accurate, for example let's see what contains diff:

root@rpi4:~# slackpkg file-search diff
Looking for diff in package list. Please wait... DONE
The list below shows the packages that contains "diff" file.
[ installed ] - file-5.39-arm-1
[uninstalled] - a2ps-4.14-arm-4
[ installed ] - diffutils-3.7-arm-2
[uninstalled] - enscript-1.6.6-arm-3
[uninstalled] - joe-4.6-arm-3
[uninstalled] - mc-4.8.26-arm-1
[uninstalled] - vim-8.2.2461-arm-1
[uninstalled] - git-2.30.1-arm-1
[uninstalled] - guile-3.0.5-arm-1
[uninstalled] - llvm-11.0.1-arm-1
[uninstalled] - python2-2.7.18-arm-3
[uninstalled] - python3-3.9.1-arm-1
[uninstalled] - ruby-3.0.0-arm-1
[uninstalled] - rust-1.49.0-arm-1
[uninstalled] - subversion-1.14.1-arm-1
[uninstalled] - emacs-27.1-arm-3
[uninstalled] - kernel-source-5.10.14-arm-1
[uninstalled] - breeze-icons-5.78.0-noarch-1
[uninstalled] - cervisia-20.12.2-arm-2
[uninstalled] - lokalize-20.12.2-arm-2
[uninstalled] - gtksourceview3-3.24.11-arm-1
[uninstalled] - liboggz-1.1.1-arm-5
[uninstalled] - python-pygments-2.7.4-arm-1
[uninstalled] - python2-module-collection-2.7.18-arm-1
[ installed ] - bind-9.16.11-arm-1
[uninstalled] - epic5-2.1.2-arm-5
[uninstalled] - samba-4.13.4-arm-2
[uninstalled] - gftp-2.7.0b-arm-1
[uninstalled] - emacspeak-38.0-arm-1
You can search specific packages using "slackpkg search package".
root@rpi4:~#

and then if I say I'm looking from /usr/bin/diff*

root@rpi4:~# slackpkg file-search "/usr/bin/diff*"
Looking for /usr/bin/diff|/usr/bin/diff3 in package list. Please wait... DONE
No packages contains "/usr/bin/diff|/usr/bin/diff3" file.
root@rpi4:~#

Ok neet to remember to remove the leading / But even that gives wrong output:

root@rpi4:~# slackpkg file-search "usr/bin/diff*"
Looking for usr/bin/diff* in package list. Please wait... DONE
The list below shows the packages that contains "usr/bin/diff*" file.
[ installed ] - diffutils-3.7-arm-2
You can search specific packages using "slackpkg search package".
root@rpi4:~#

there is actually several packaged that contain usr/bin/diff* .. I did a little simple script to do that (will share with you ... look further down)

root@rpi4:~# ./spm "/usr/bi?/diff*"
/usr/bin/diffstat contained in diffstat-1.64-arm-1 [UNINSTALLED]
/usr/bin/diff contained in diffutils-3.7-arm-2 [INSTALLED]
/usr/bin/diff3 contained in diffutils-3.7-arm-2 [INSTALLED]
/usr/bin/diffpp contained in enscript-1.6.6-arm-3 [UNINSTALLED]
root@rpi4:~#

Even more funny things happen if one insists with wildcards

I don't want to maintain myself a modified version of slackpkg ... but would you consider adding something like this in slackpkg ?

set -o noglob
DB=/var/lib/spm/MANIFEST.bz2
Repo="http://slackware.uk/slackwarearm/slackwarearm-current"
InstalledPKGDir=/var/log/packages

#find which package contains a file (absolute path with optional wildchars) will look also amongst uninstalled packages
Query_File ()
{ Regexp="$(sed 's?^/??; s?\*?.\*?g; s/?/./g' <<< $1)"
  Info="$(bzcat $DB | awk -v filename="$Regexp" '
  $2 ~ /Package:/ {package=$3; sub("./","",package)};
  $NF ~ "^"filename"$" {printf("%s:/%s\n",package,$NF)} ')"

  for hit in $Info
  do
    PackageInfo=${hit%%:*}
    PackageFile=${PackageInfo##*/}
    PackageName=${PackageFile%%.t*z}
    File=${hit##*:}
    [ -f ${InstalledPKGDir}/$PackageName ] && Installed="INSTALLED" || Installed="UNINSTALLED"
    echo -e "$File contained in $PackageName [${Installed}]"
  done
}

Query_File $1

This way one needs not remember to strip the leading / Notice how I deal with both and ? wildchars ... so you can find libs even if you don't know where they are nor the exact name of the physical file ... eg: "/libz*" Not advocating that you should do it exactly this way but it would be wonderful if you could achieve something like thin in slackpkg.

I'm also working on something that will give me the list of missing libraries for a given package ... at least the ones you can see are missing with ldd and turn that into a list of packages to install ... I know this is not in the spirit of slackware ... but on my RPi I like to keep it minimal so I really need an easier way to install just what I need.

ATB, David

rworkman commented 3 years ago

Definitely not something that has a chance of landing in 15.0.x, and I'm not a huge fan of adding features (one of the main principles I decided on when taking over maintenance of slackpkg was that new features would be rare), but I might be willing to accept some tweaks to the file-search function so that it handles wildcards and such.