home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / f / find37.zip / find-3.7 / locate / updatedb.sh < prev   
Linux/UNIX/POSIX Shell Script  |  1992-07-03  |  2KB  |  78 lines

  1. #!/bin/sh
  2. # updatedb -- build locate pathname database
  3. # csh original by James Woods; sh conversion by David MacKenzie.
  4. # Public domain.
  5.  
  6. PATH=/bin:/usr/bin # Just temporarily.
  7.  
  8. # You can set these in the environment to override their defaults:
  9.  
  10. # Non-network directories to put in the database.
  11. test -z "$SEARCHPATHS" && SEARCHPATHS="/"
  12.  
  13. # Network directories to put in the database.
  14. test -z "$NFSPATHS" && NFSPATHS=
  15.  
  16. # Pathnames that match this regular expression are not searched.
  17. test -z "$PRUNEREGEX" &&
  18.   PRUNEREGEX='\(^/tmp$\)\|\(^/usr/tmp$\)\|\(^/var/tmp$\)'
  19.  
  20. # User(s) to mail error messages about `sort' overflows to.
  21. test -z "$FINDHONCHO" && FINDHONCHO="root"
  22.  
  23. # User to search network directories as.
  24. test -z "$NFSUSER" && NFSUSER=daemon
  25.  
  26. # Directory to hold intermediate files.
  27. test -z "$TMPDIR" && TMPDIR=/usr/tmp
  28.  
  29. # The database file to build.
  30. test -z "$LOCATE_DB" && LOCATE_DB=@LOCATE_DB@
  31.  
  32.  
  33. # These you probably won't need to override:
  34.  
  35. # The directory containing the subprograms.
  36. LIBDIR=@libdir@
  37.  
  38. # The directory containing find.
  39. BINDIR=@bindir@
  40.  
  41. # Any prefix in the GNU find filename, before `find'.
  42. binprefix=@binprefix@
  43.  
  44. PATH=$LIBDIR:$BINDIR:/usr/ucb:/bin:/usr/bin export PATH
  45.  
  46. bigrams=$TMPDIR/f.bigrams$$
  47. filelist=$TMPDIR/f.list$$
  48. errs=$TMPDIR/f.errs$$
  49. trap 'rm -f $bigrams $filelist $errs' 0
  50. trap 'rm -f $bigrams $filelist $errs; exit' 1 15
  51.  
  52. # Make a file list.  Alphabetize `/' before any other char with `tr'.
  53.  
  54. {
  55. if test -n "$SEARCHPATHS"; then
  56.   ${binprefix}find $SEARCHPATHS \
  57.   \( -fstype nfs -o -type d -regex "$PRUNEREGEX" \) -prune -o -print
  58. fi
  59. if test -n "$NFSPATHS"; then
  60.   su $NFSUSER -c \
  61.   "${binprefix}find $NFSPATHS \\( -type d -regex \"$PRUNEREGEX\" -prune \\) -o -print"
  62. fi
  63. } | tr / '\001' | sort -f 2> $errs | tr '\001' / > $filelist
  64.  
  65. # Compute common bigrams.
  66.  
  67. bigram < $filelist | sort 2>> $errs | uniq -c | sort -nr |
  68.   awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $bigrams
  69.  
  70. # Code the file list.
  71.  
  72. if test -s $errs; then
  73.   echo 'updatedb: out of sort space' | mail $FINDHONCHO
  74. else
  75.   code $bigrams < $filelist > $LOCATE_DB
  76.   chmod 644 $LOCATE_DB
  77. fi
  78.