Hi nick65go
... OR, if the speed is not the main goal (but nice for multi-CPU core) then maybe the user confort for seach parameters (GUI options will be nice also). But of course, the pro[fessionals] already know the use of "" and back-quotes, etc.
I think backwards compatibility and user friendly search parameters
should be the primary goals.
I did a rewrite of provides.sh as follows:
1. The default search mode is unchanged.
2. No backslashes to enter. The script adds them if needed.
3. No quoting of search term.
4. End of search term can be marked with an anchor ($).
5. Added a brief usage message.
6. This works for both the command line and the GUI.
Examples:
Search for plain file name:
tc@E310:~/Scripting/Provides$ ./provides.sh grep | wc -l
51
tc@E310:~/Scripting/Provides$
Search for file name with leading slash:
tc@E310:~/Scripting/Provides$ ./provides.sh /grep
boost-1.65-dev.tcz
boost-dev.tcz
emacs.cedet.tcz
emacs.doc.tcz
emacs.minimal.tcz
emacs.prog.tcz
fpc-src.tcz
fpc.tcz
grep.tcz
kompozer.tcz
libreoffice.tcz
mariadb-test.tcz
python3.6.tcz
tc@E310:~/Scripting/Provides$
Search for file name with partial path:
tc@E310:~/Scripting/Provides$ ./provides.sh bin/grep
emacs.minimal.tcz
fpc.tcz
grep.tcz
tc@E310:~/Scripting/Provides$
Search for file name with partial path and trailing anchor:
tc@E310:~/Scripting/Provides$ ./provides.sh bin/grep$
grep.tcz
tc@E310:~/Scripting/Provides$
Added help message:
tc@E310:~/Scripting/Provides$ ./provides.sh --help
Finds extension(s) that provide a filename.
Filenames in list being searched include full paths, for example:
usr/local/bin/grep
Usage:
provides.sh FileName
Examples:
This also finds all extensions that include local in their pathes.
provides.sh cal
This finds *bin/cal*. Including sbin/cal, bin/calibrate, etc.
provides.sh bin/cal
This finds *bin/cal. Including sbin/cal, usr/bin/cal, etc.
provides.sh bin/cal$
The more specific the search, the fewer the results returned.
tc@E310:~/Scripting/Provides$
And the script itself:
#!/bin/busybox ash
. /etc/init.d/tc-functions
useBusybox
# --------------------------------------------------------------------------- #
Usage()
{
echo "
Finds extension(s) that provide a filename.
Filenames in list being searched include full paths, for example:
usr/local/bin/grep
Usage:
${0##*/} FileName
Examples:
This also finds all extensions that include local in their pathes.
${0##*/} cal
This finds *bin/cal*. Including sbin/cal, bin/calibrate, etc.
${0##*/} bin/cal
This finds *bin/cal. Including sbin/cal, usr/bin/cal, etc.
${0##*/} bin/cal$
The more specific the search, the fewer the results returned.
"
exit
}
# --------------------------------------------------------------------------- #
# See if user needs help.
case "$1" in
-h) Usage;;
-help) Usage;;
--help) Usage;;
"") exit 1;;
esac
# Flag to indicate whether we want an exact match. 0=No 1=Yes.
Exact=0
TARGET="$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
chmod g+rw "$TCEDIR"/"$DB"
cd - > /dev/null
# Save string length of TARGET.
Length=${#TARGET}
# Remove trailing $ (exact match request) if present.
TARGET="${TARGET%$}"
# If TARGET is now shorter, exact match was requested.
[ ${#TARGET} -lt $Length ] && Exact=1
# Replace all instances of / with \/.
TARGET="${TARGET//\//\\\/}"
if [ $Exact -eq 0 ]
then
awk 'BEGIN {FS="\n";RS=""} /'${TARGET}'/{print $1}' "$TCEDIR"/"$DB"
else
awk 'BEGIN {FS="\n";RS=""} /'${TARGET}'\n/||/'${TARGET}'$/{print $1}' "$TCEDIR"/"$DB"
fi
A copy of the script is attached. If you want to try it with the Apps GUI
after downloading it:
sudo cp provides.sh /usr/bin