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 - fixed an error when a folder is missing in the slackware mirror (as
/testing). /testing).
- fixed a conflict searching the package 'slackpkg' - fixed a conflict searching the package 'slackpkg'
- added file-search function
Version 0.9rc3 - 01/May/2013 Version 0.9rc3 - 01/May/2013
- added more config file checks - added more config file checks

View file

@ -308,40 +308,60 @@ if [ "$SLACKPKGPLUS" = "on" ];then
touch ${TMPDIR}/waiting touch ${TMPDIR}/waiting
if [ "$CMD" == "search" ] ; then
# -- PKGLIST: # -- PKGLIST:
# temporary file used to store data about packages. It use # temporary file used to store data about packages. It use
# the following format: # the following format:
# repository:<repository_name>:basename:<package_basename>: # repository:<repository_name>:basename:<package_basename>:
# #
PKGLIST=$(tempfile --directory=$TMPDIR) PKGLIST=$(tempfile --directory=$TMPDIR)
PKGINFOS=$(tempfile --directory=$TMPDIR) PKGINFOS=$(tempfile --directory=$TMPDIR)
for i in ${PRIORITY[@]}; do
DIR="$i"
if echo "$DIR" | grep -q "[a-zA-Z0-9]\+[:]" ; then
DIR=$(echo "$i" | cut -f2- -d":")
fi
for i in ${PRIORITY[@]}; do if [ "$CMD" == "file-search" ] ; then
DIR="$i" [ ! -e "${WORKDIR}/${DIR}-filelist.gz" ] && continue
if echo "$DIR" | grep -q "[a-zA-Z0-9]\+[:]" ; then
DIR=$(echo "$i" | cut -f2- -d":") # NOTE:
fi # 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 grep "^${DIR}.*${PATTERN}" "${TMPDIR}/pkglist" > $PKGINFOS
fi
while read PKG ; do
PKGDIR=$(echo "$PKG" | cut -f1 -d" ") while read PKG ; do
PKGBASENAME=$(echo "$PKG" | cut -f2 -d" ") PKGDIR=$(echo "$PKG" | cut -f1 -d" ")
PKGFULLNAME=$(echo "$PKG" | cut -f6 -d" ") PKGBASENAME=$(echo "$PKG" | cut -f2 -d" ")
PKGFULLNAME=$(echo "$PKG" | cut -f6 -d" ")
if echo "$PKGDIR" | grep -q "SLACKPKGPLUS_" ; then
grep -q "^repository:${PKGDIR}:basename:${PKGBASENAME}:" $PKGLIST && continue if echo "$PKGDIR" | grep -q "SLACKPKGPLUS_" ; then
else grep -q "^repository:${PKGDIR}:basename:${PKGBASENAME}:" $PKGLIST && continue
grep -q ":basename:${PKGBASENAME}:" $PKGLIST && continue else
fi grep -q ":basename:${PKGBASENAME}:" $PKGLIST && continue
LIST="$LIST ${PKGDIR}:${PKGFULLNAME}" fi
echo "repository:${PKGDIR}:basename:${PKGBASENAME}:" >> $PKGLIST LIST="$LIST ${PKGDIR}:${PKGFULLNAME}"
done < $PKGINFOS echo "repository:${PKGDIR}:basename:${PKGBASENAME}:" >> $PKGLIST
done done < $PKGINFOS
done
rm -f $PKGLIST $PKGINFOS rm -f $PKGLIST $PKGINFOS
fi
LIST=$(echo -e $LIST | tr \ "\n" | uniq ) LIST=$(echo -e $LIST | tr \ "\n" | uniq )
@ -349,7 +369,6 @@ if [ "$SLACKPKGPLUS" = "on" ];then
echo -e "DONE\n" echo -e "DONE\n"
} }
function searchlistEX() { function searchlistEX() {
local i local i
@ -407,20 +426,32 @@ function searchlistEX() {
done 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') PATTERN=$(echo $ARG | sed -e 's/\+/\\\+/g' -e 's/\./\\\./g' -e 's/ /\|/g')
searchPackages $PATTERN searchPackages $PATTERN
if [ "$LIST" = "" ]; then case $CMD in
echo -e "No package name matches the pattern." search)
else if [ "$LIST" = "" ]; then
echo -e "The list below shows all packages with name matching \"$PATTERN\".\n" echo -e "No package name matches the pattern."
searchlistEX "$LIST" else
echo -e "The list below shows all packages with name matching \"$PATTERN\".\n"
searchlistEX "$LIST"
echo -e "\nYou can search specific files using \"slackpkg file-search file\".\n"
fi
;;
# PENDING: file-search must be implemented first. file-search)
# if [ "$LIST" = "" ]; then
#echo -e "\nYou can search specific files using \"slackpkg file-search file\".\n" echo -e "No packages contains \"$PATTERN\" file."
fi 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 cleanup
fi fi