Added file-search function.

Thanks to phenixia2003
This commit is contained in:
Matteo Rossini 2013-05-05 15:49:11 +02:00
parent 6aef9d6695
commit 9a10a4d531
2 changed files with 71 additions and 39 deletions

View file

@ -2,6 +2,7 @@ Current
- fixed an error when a folder is missing in the slackware mirror (as
/testing).
- fixed a conflict searching the package 'slackpkg'
- added file-search function
Version 0.9rc3 - 01/May/2013
- added more config file checks

View file

@ -308,7 +308,6 @@ if [ "$SLACKPKGPLUS" = "on" ];then
touch ${TMPDIR}/waiting
if [ "$CMD" == "search" ] ; then
# -- PKGLIST:
# temporary file used to store data about packages. It use
# the following format:
@ -323,7 +322,30 @@ if [ "$SLACKPKGPLUS" = "on" ];then
DIR=$(echo "$i" | cut -f2- -d":")
fi
if [ "$CMD" == "file-search" ] ; then
[ ! -e "${WORKDIR}/${DIR}-filelist.gz" ] && continue
# NOTE:
# The awk below produces an output formatted like
# in file TMPDIR/pkglist, but without true values
# for the fields: version(3) arch(4) build(5), path(7),
# extension(8)
#
zegrep -w "${INPUTLIST}" ${WORKDIR}/${DIR}-filelist.gz | \
cut -d" " -f 1 | rev | cut -f2- -d"." | cut -f1 -d"/" | rev |\
awk '{
l_pname=$0
l_count=split($0,l_parts,"-");
l_basename=l_parts[1];
for (i=2;i<=l_count-3;i++) {
l_basename=l_basename"-"l_parts[i];
}
print l_dir" "l_basename" ------- ---- ----- "l_pname" ---- ---------"
}' l_dir=${DIR} > $PKGINFOS
else # -- CMD==search
grep "^${DIR}.*${PATTERN}" "${TMPDIR}/pkglist" > $PKGINFOS
fi
while read PKG ; do
PKGDIR=$(echo "$PKG" | cut -f1 -d" ")
@ -339,9 +361,7 @@ if [ "$SLACKPKGPLUS" = "on" ];then
echo "repository:${PKGDIR}:basename:${PKGBASENAME}:" >> $PKGLIST
done < $PKGINFOS
done
rm -f $PKGLIST $PKGINFOS
fi
LIST=$(echo -e $LIST | tr \ "\n" | uniq )
@ -350,7 +370,6 @@ if [ "$SLACKPKGPLUS" = "on" ];then
echo -e "DONE\n"
}
function searchlistEX() {
local i
local BASENAME
@ -407,20 +426,32 @@ function searchlistEX() {
done
}
if [ "$CMD" == "search" ] ; then
if [ "$CMD" == "search" ] || [ "$CMD" == "file-search" ] ; then
PATTERN=$(echo $ARG | sed -e 's/\+/\\\+/g' -e 's/\./\\\./g' -e 's/ /\|/g')
searchPackages $PATTERN
case $CMD in
search)
if [ "$LIST" = "" ]; then
echo -e "No package name matches the pattern."
else
echo -e "The list below shows all packages with name matching \"$PATTERN\".\n"
searchlistEX "$LIST"
# PENDING: file-search must be implemented first.
#
#echo -e "\nYou can search specific files using \"slackpkg file-search file\".\n"
echo -e "\nYou can search specific files using \"slackpkg file-search file\".\n"
fi
;;
file-search)
if [ "$LIST" = "" ]; then
echo -e "No packages contains \"$PATTERN\" file."
else
echo -e "The list below shows the packages that contains \"$PATTERN\" file.\n"
searchlistEX "$LIST"
echo -e "\nYou can search specific packages using \"slackpkg search package\".\n"
fi
;;
esac
cleanup
fi