#!/bin/bash # #!F:rpmfsu # #!P:/usr/local/bin # #!M:755 # #!D:RedHat Package Manager File Search Utility # #!C: Copyright 1997-2000 by Peter Bieringer # #!V: Version 1.45 2000-04-22 #!H: Usage: rpmfsu [-nf] whatfiletosearch #!H: searches for whatfiletosearch in the rpm-packages #!H: #!H: rpmfsu -cf [-ff fastfindfile] [-fc] [-sp rpm-directory] #!H: creates a fastfindfile, more faster search afterwards #!H: #!H: Options: -cf create 'FastFindFile' #!H: -fc force create, override old #!H: -ff filename specify 'FastFindFile' #!H: -sp directory specify search path directory #!H: -nf use no 'FastFindFile' #!H: -af search in all availble files #!H: -? display this help # Changes to # 1.21: Minor corrections # 1.22: Info display # 1.23: Fixed location of temp files # 1.30: Possiblilty to use a file instead of the rpm-directory (faster) # 1.31: New option handling, some corrections # 1.32: Some corrections, bugfix: '-sp' will now work # 1.40: Now supports regular expressions, changes in RPM-search # 1.41: Autodetect RedHat/Delix # 1.42: Remove displaying of option '-sf', no longer used, add 'Usage' # 1.43: Change name from "rpms" to "rpmfsu" # Change algorithm for extracting program help information # 1.44: Fix // output bug # 1.45: Fix .gz bug on option -cf #set -x DEFAULT_FASTFINDFILEDIR=/var/local autodetect() { ## File definitions and default stettings # Autodetect distribution echo -n " Autodetecting distribution..." if [ -d /usr/src/redhat ]; then # RedHat echo "found RedHat" DEFAULT_SEARCHPATH=/mnt/cdrom/RedHat/RPMS DEFAULT_FASTFINDFILE=/var/local/rpm-redhat-contents elif [ -d /usr/src/delix ]; then # Delix echo "found Delix DLD" DEFAULT_SEARCHPATH=/cdrom/delix/RPMS/i386 DEFAULT_FASTFINDFILE=/var/local/rpm-delix-contents fi echo } TMPPATH=/var/tmp ## Built-in functions # Displays information info() { grep "^#!D:" $0 | sed 's/^#!D://g' grep "^#!C:" $0 | sed 's/^#!C://g' grep "^#!V:" $0 | sed 's/^#!V://g' echo } # Shows help help() { grep "^#!H" $0 | sed 's/^#!H://g' echo } # Running sign running_start() { j=0 } running() { case $[ $j & 3 ] in 0) echo -n -e "\b/"; ;; 1) echo -n -e "\b-"; ;; 2) echo -n -e "\b\\"; ;; 3) echo -n -e "\b|"; ;; esac; j=$[ $j + 1 ] } running_end() { echo -e -n "\b \b" } # get options getoptions() { while [ ! "$1" = "" ]; do if [ "$1" = "-?" ]; then return 1 elif [ "$1" = "-ff" ]; then shift if [ $# -ge 1 ]; then # Without a perhps given .gz-Suffix OPTION_FASTFINDFILE=`echo $1 | sed 's/\.gz$//g'` shift else echo " Missing filename!" return 1 fi elif [ "$1" = "-sp" ]; then shift if [ $# -ge 1 ]; then # remove trailling / OPTION_SEARCHPATH=`echo $1 | sed 's/\/$//g'` shift else echo " Missing path!" return 1 fi elif [ "$1" = "-cf" ]; then OPTION_CREATEFASTFINDFILE=1 shift elif [ "$1" = "-af" ]; then OPTION_SEARCHINALLFILES=1 shift elif [ "$1" = "-nf" ]; then OPTION_NOFASTFIND=1 shift elif [ "$1" = "-fc" ]; then OPTION_FORCECREATE=1 shift else if echo $1 | grep "^-" >/dev/null 2>&1; then echo " Option '$1' isn't understood!" return 1 else OPTION_SEARCHFILE=$1 return 0 fi fi done return 0 } ## Start info getoptions $* || { help; exit 1; } autodetect if [ "$OPTION_SEARCHPATH" = "" ]; then echo -e " No 'Search Path' specified" OPTION_SEARCHPATH=$DEFAULT_SEARCHPATH echo -e " Using default: '$OPTION_SEARCHPATH'\n" fi if [ "$OPTION_FASTFINDFILE" = "" ]; then echo -e " No 'FastFindFile' specified" if [ "$OPTION_SEARCHINALLFILES" = "1" ]; then echo -e " Using all available FastFindFiles:" find $DEFAULT_FASTFINDFILEDIR -name rpm-*-contents.gz | while read file; do echo " $file"; done else OPTION_FASTFINDFILE=$DEFAULT_FASTFINDFILE echo -e " Using default: '$OPTION_FASTFINDFILE'\n" fi fi # Option: create fast find file if [ "$OPTION_CREATEFASTFINDFILE" = "1" ]; then # test if search path exists if [ ! -d $OPTION_SEARCHPATH ]; then echo -e "\a Search path '$OPTION_SEARCHPATH' doesn't exist!\n" exit 2 fi # test if old file exists and fore is off if [ -f $OPTION_FASTFINDFILE.gz -a "$OPTION_FORCECREATE" = "" ]; then echo -e "\a FastFindFile '$OPTION_FASTFINDFILE.gz' already exists!" echo -e " Override it with option '-fc' or specify another one with '-ff'\n" exit 2 fi # clear old cat /dev/null >$OPTION_FASTFINDFILE running_start echo -e " Create FastFindFile '$OPTION_FASTFINDFILE.gz'" echo -e " from all packages in: '$OPTION_SEARCHPATH'" for i in $OPTION_SEARCHPATH/*.rpm; do FILENAME=`echo $i | awk -F/ '{ print $NF }'` running rpm -ql -p $i >$TMPPATH/rpm.tmp cat $TMPPATH/rpm.tmp | while read line; do echo "$i:$line" >>$OPTION_FASTFINDFILE done done running_end # Compress it echo -e " Compress FastFindFile" gzip -f $OPTION_FASTFINDFILE echo "...done!" fi # Option: search file if [ ! "$OPTION_SEARCHFILE" = "" ]; then # Remove regular expression chars for faster search mechanism SEARCH=`echo $OPTION_SEARCHFILE | sed 's/^^//g'` SEARCH=`echo $SEARCH | sed 's/$$//g'` # fast find file exists? if [ ! -f $OPTION_FASTFINDFILE.gz -a "$OPTION_NOFASTFIND" != "1" -a "$OPTION_SEARCHINALLFILES" = 0 ]; then if [ ! "$OPTION_NOFASTFIND" = "1" ]; then echo -e " Info: try option '-cf' to create a 'FastFindFile'\n" fi # test if search path exists if [ ! -d $OPTION_SEARCHPATH ]; then echo -e "\a Search path '$OPTION_SEARCHPATH' doesn't exist!\n" exit 2 fi echo -e " Search in Path: '$OPTION_SEARCHPATH' for '$OPTION_SEARCHFILE'\n" running_start for packet in $OPTION_SEARCHPATH/*.rpm;do running PACKET="" rpm -qlp $packet | grep -i $SEARCH | while read line; do if echo $line | awk -F/ '{ print $NF }' | grep -i $OPTION_SEARCHFILE >/dev/null; then if [ ! "$PACKET" = "$packet" ]; then running_end echo -e "\n$packet:" PACKET=$packet fi echo " $line" fi done done running_end echo "...done!" rm -f $TMPPATH/rpms.tmp $TMPPATH/rpms.tmp1 else if [ ! "$OPTION_SEARCHINALLFILES" = "1" ]; then echo -e " Search in FastFindFile: '$OPTION_FASTFINDFILE' for '$OPTION_SEARCHFILE'\n" PACKET="" gzip -cd $OPTION_FASTFINDFILE | grep -i $SEARCH | while IFS=":" read packet file; do if echo $file | awk -F/ '{ print $NF }' | grep -i $OPTION_SEARCHFILE >/dev/null; then if [ ! "$packet" = "$PACKET" ]; then echo -e "\n$packet:" PACKET=$packet fi echo " $file" fi done echo "...done!" else PACKET="" find $DEFAULT_FASTFINDFILEDIR -name rpm-*-contents.gz | while read fastfindfile; do fastfindfilename=`echo $fastfindfile | awk -F/ '{ print $NF }' | sed 's/\.gz$//g' | sed 's/rpm\-//g' | sed 's/\-contents//g'` gzip -cd $fastfindfile | grep -i $SEARCH | while IFS=":" read packet file; do if echo $file | awk -F/ '{ print $NF }' | grep -i $OPTION_SEARCHFILE >/dev/null; then if [ ! "$packet" = "$PACKET" ]; then echo -e "\n$packet: ($fastfindfilename)" PACKET=$packet fi echo " $file" fi done done echo "...done!" fi fi fi exit 0