Tiny Core Base > TCB Tips & Tricks
How to find which extension provides a file
Rich:
Hi gadget42
--- Quote from: gadget42 on November 13, 2024, 05:52:51 AM --- ... when i use the "provides" function and search for "ps" it reports many results. how would the uninitiated decide which to use? ...
--- End quote ---
Good question.
The following was performed on TC10 x86 using the command line for
provides instead of the GUI. The only difference is the command line
requires quotes and the GUI can not handle quotes.
Trying to find which extension provides a program can be a frustrating
experience, especially with short names like ps or dd which will return
many results. A search for ps returned 580 results:
--- Code: ---tc@E310:~$ provides.sh ps | wc -l
580
tc@E310:~$
--- End code ---
The reason for so many matches is provides searches for a match anywhere
in the string, not an exact match. Searching for the calendar program called
cal returns 2661 results:
--- Code: ---tc@E310:~$ provides.sh cal | wc -l
2661
tc@E310:~$
--- End code ---
That's because it's also matching on every usr/local/ string in the provides.db
file. That's important because we can use that to create a more precise match by
including some path information.
We know cal is a program so it's probably in a bin or sbin directory. We can cover
both cases with a search like this:
--- Code: ---tc@E310:~$ provides.sh "bin\/cal"
ax25-apps.tcz
fox-apps.tcz
fox.tcz
util-linux.tcz
valgrind.tcz
xastir.tcz
tc@E310:~$
--- End code ---
Notice we need to escape the path separator "/" with a backslash "\".
As I said earlier, command line, use quotes. GUI, don't use quotes.
Let's see what happens for ps:
--- Code: ---tc@E310:~$ provides.sh "bin\/ps"
aspell-dev.tcz
ghostscript.tcz
gnutls3.6.tcz
gnutls.tcz
lcms2.tcz
libcap-ng.tcz
libpsl.tcz
pax-utils.tcz
postgresql-10-client.tcz
postgresql-10.tcz
postgresql-11-client.tcz
postgresql-11.tcz
postgresql-12-client.tcz
postgresql-12.tcz
postgresql-9.5-client.tcz
postgresql-9.5.tcz
postgresql-9.6-client.tcz
postgresql-9.6.tcz
procps-ng.tcz
procps.tcz
pstree.tcz
putty.tcz
sc.tcz
tc@E310:~$
--- End code ---
23 results.
Lets lengthen the path a little:
--- Code: ---tc@E310:~$ provides.sh "local\/bin\/ps"
aspell-dev.tcz
ghostscript.tcz
gnutls3.6.tcz
gnutls.tcz
lcms2.tcz
libcap-ng.tcz
libpsl.tcz
pax-utils.tcz
procps-ng.tcz
procps.tcz
pstree.tcz
putty.tcz
sc.tcz
tc@E310:~$
--- End code ---
That's a little better.
The previous search was picking up this from the postgresql extensions:
/usr/local/pgsql10/bin/psql
That brings me to another point.
Some extensions have another sub-directory between local and bin, sbin, or lib
as you just saw:
/usr/local/pgsql10/bin/psql
Just something to keep in mind when performing searches.
Leee:
While browsing through provides.db, I note that most file paths start with /usr/ but in a few extensions they start with usr/ or ./usr/Is this legit? irrelevant? indicative of a problem?
examples: base-locale.tcz uses ./usr/ bash-completeion.tcz uses usr/
Rich:
Hi Leee
Yes, I've noticed that too. Whether tce-load does a copy to file
system or creates symlinks to the file system, the destination
is always "/".
That would translate to //usr/ , /usr/ , or /./usr/ , all of which resolve
to the same location. Extra consecutive slashes are ignored. The
"./" means the current directory. So "/./" becomes root "current directory"
which is still the root directory. Hope that makes sense. Try this:
--- Code: ---cd /./
--- End code ---
then do a directory listing and you'll see you're in the root directory.
Rich:
Hi gadget42
I've created a modified provides.sh script and copied it
to /usr/bin/provides.sh. Then I did:
--- Code: ---sudo ln -rs /usr/bin/provides.sh /usr/bin/Provides.sh
tc@E310:~/Scripting/Provides$ ls -l /usr/bin/Provides.sh
lrwxrwxrwx 1 root root 11 Nov 14 00:02 /usr/bin/Provides.sh -> provides.sh
--- End code ---
When called as provides.sh, it behaves as it always has, so the Apps GUI
won't know the difference.
When called as Provides.sh, it behaves like an anchor was added to
the end of the search term. So a search for ps would reject ps2pdf
because it does not end in ps.
Here is the search for ps repeated with both versions:
--- Code: ---tc@E310:~/Scripting/Provides$ time provides.sh "\/local\/bin\/ps"
aspell-dev.tcz
ghostscript.tcz
gnutls3.6.tcz
gnutls.tcz
lcms2.tcz
libcap-ng.tcz
libpsl.tcz
pax-utils.tcz
procps-ng.tcz
procps.tcz
pstree.tcz
putty.tcz
sc.tcz
real 0m 1.81s
user 0m 0.90s
sys 0m 0.18s
--- End code ---
--- Code: ---tc@E310:~/Scripting/Provides$ time Provides.sh "\/local\/bin\/ps"
procps-ng.tcz
procps.tcz
real 0m 1.92s
user 0m 1.00s
sys 0m 0.20s
--- End code ---
Here is the search for cal repeated with both versions:
--- Code: ---tc@E310:~/Scripting/Provides$ time provides.sh "\/local\/bin\/cal"
ax25-apps.tcz
fox-apps.tcz
fox.tcz
util-linux.tcz
valgrind.tcz
xastir.tcz
real 0m 1.99s
user 0m 0.86s
sys 0m 0.24s
--- End code ---
--- Code: ---tc@E310:~/Scripting/Provides$ time Provides.sh "\/local\/bin\/cal"
util-linux.tcz
real 0m 1.96s
user 0m 0.98s
sys 0m 0.23s
--- End code ---
This is the modified provides.sh:
--- Code: ---#!/bin/busybox ash
. /etc/init.d/tc-functions
useBusybox
TARGET="$1"
[ -z "$TARGET" ] && exit 1
TCEDIR="/etc/sysconfig/tcedir"
DB="provides.db"
getMirror
cd "$TCEDIR"
if zsync -i "$TCEDIR"/"$DB" -q "$MIRROR"/"$DB".zsync
then
rm -f "$DB".zs-old
else
if [ ! -f "$TCEDIR"/"$DB" ]
then
wget -O "$TCEDIR"/"$DB".gz "$MIRROR"/"$DB".gz
gunzip "$TCEDIR"/"$DB".gz
fi
fi
cd - > /dev/null
if [ "${0##*/}" == "provides.sh" ]
then
awk 'BEGIN {FS="\n";RS=""} /'${TARGET}'/{print $1}' "$TCEDIR"/"$DB"
else
awk -v Find="$TARGET" -v FindEnd="$TARGET$" 'BEGIN {FS="\n";RS=""} {if ( $0 ~ Find ) { for (i=2; i <= NF; i++) { if ( $i ~ FindEnd ) {print $1; break} } } }' "$TCEDIR"/"$DB"
fi
chmod g+rw "$TCEDIR"/"$DB"
--- End code ---
What I don't understand is the purpose of the chmod command
at the end that executes after the script has finished running.
polikuo:
Hi
This is what I do in my systems.
--- Code: ---#!/bin/sh
[ -z "$1" ] && exit 1
TCEDIR="/etc/sysconfig/tcedir"
DB="provides.db"
awk 'BEGIN {FS="\n";RS=""} /'"$1"'/{print $1}' "$TCEDIR"/"$DB"
--- End code ---
I call it /usr/local/bin/prov, because it's a shrunken version of provides.sh that doesn't sync with the repo. (syncing takes time, especially if you're searching frequently.)
While searching, you can add "\n" to the end of the query.
--- Code: ---tc@pi4:~$ prov 'bin\/ps\n'
procps-ng.tcz
--- End code ---
You can do the same with the regular provides.sh (or the app browser) as well.
--- Quote from: Rich on November 14, 2024, 01:01:01 AM ---What I don't understand is the purpose of the chmod command
at the end that executes after the script has finished running.
--- End quote ---
I believe it was meant to make sure the file is modifiable by any user to sync with the repo.
Navigation
[0] Message Index
[#] Next page
Go to full version