home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / LINUX / LINUXISO.S97 / lgazette / issue14 / misc / updatedb.gen < prev   
Encoding:
Text File  |  1997-07-19  |  3.0 KB  |  143 lines

  1. #!/bin/sh
  2. # updatedb.gen -- build a general locate database from parameters
  3. # cloned from /usr/bin/updatedb, Keith Owens.
  4. # parameter required, the name of the master list file.
  5. # Copyright (C) 1994 Free Software Foundation, Inc.
  6.  
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2, or (at your option)
  10. # any later version.
  11.  
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16.  
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. # csh original by James Woods; sh conversion by David MacKenzie.
  22.  
  23. x=${1:?"suffix for file.codes is required"}
  24. x=${2:?"name of input file list is required"}
  25. select=$3
  26.  
  27. # Use cat or zcat
  28. case `file $2` in
  29.     *compress*)
  30.         CAT=zcat
  31.         ;;
  32.     *)
  33.         CAT=cat
  34.         ;;
  35. esac
  36.  
  37. # The database file to build.
  38. : ${LOCATE_DB=/var/spool/locate/locatedb.$1}
  39.  
  40. # These you probably won't need to override:
  41.  
  42. # Directory to hold intermediate files.
  43. if test -d /var/tmp; then
  44.   : ${TMPDIR=/var/tmp}
  45. else
  46.   : ${TMPDIR=/usr/tmp}
  47. fi
  48.  
  49. # The directory containing the subprograms.
  50. : ${LIBEXECDIR=/usr/libexec}
  51.  
  52. # The names of the utilities to run to build the database.
  53. : ${find=find}
  54. : ${frcode=frcode}
  55. : ${bigram=bigram}
  56. : ${code=code}
  57.  
  58. PATH=$LIBEXECDIR:$BINDIR:/usr/ucb:/bin:/usr/bin:$PATH export PATH
  59.  
  60. # Make a file list.  Alphabetize `/' before any other char with `tr'.
  61.  
  62. $CAT $2 | \
  63. awk ' \
  64. #    decide if we process the first line or not
  65. FNR == 1    {
  66.     if ($1 == "total") {
  67.         ls = 1
  68.         dir = "./"
  69.     }
  70.     else if (/:/ && NF == 1) {
  71.         ls = 1
  72.         dir = $1
  73.     }
  74.     else if (/^\+\+==/) {
  75.         # slakware MANIFEST
  76.         ls = 6
  77.         dir = ""
  78.     }
  79.     else
  80.         ls = 0
  81. }
  82.  
  83. #    determine which format we are looking at
  84. FNR == (ls + 1)    {
  85.     if ($1 == "total") {
  86.         ++ls
  87.         next
  88.     }
  89.     select = select + 0
  90.     if (NF == 1)
  91.         select = 1
  92.     else {
  93.         for (i = 1; i <= NF; ++i) {
  94.             if ($i ~ /^[12][0-9][0-9][0-9]$/ || $i ~ /^[0-2][0-9]:[0-5][0-9]$/)
  95.                 select = i + 1
  96.         }
  97.     }
  98.     if (select == 0) {
  99.         print "cannot decide which field to select" > "/dev/stderr"
  100.         exit 1
  101.     }
  102.     else
  103.         print "selecting field " select > "/dev/stderr"
  104. }
  105.  
  106. /:/ && ls && NF == 1    {
  107.     dir = $1
  108.     sub(/:/, "/", dir)
  109. }
  110.  
  111. /^\|\| *Package/ && ls    {
  112.     # slakware MANIFEST
  113.     dir = "slakware" substr($NF, 2) "/"
  114. }
  115.  
  116. NF < select    { next }
  117.  
  118. {
  119.     if (ls)
  120.         printf("%s", dir)
  121.     for (i = select; i <= NF; ++i) {
  122.         printf("%s", $i)
  123.         if (i < NF)
  124.             printf(" ")
  125.         else
  126.             printf("\n")
  127.     }
  128. }
  129.  
  130. ' select=$select | \
  131. sort -f | $frcode > $LOCATE_DB.n
  132.  
  133. # To avoid breaking locate while this script is running, put the
  134. # results in a temp file, then rename it atomically.
  135. if test -s $LOCATE_DB.n; then
  136.   rm -f $LOCATE_DB
  137.   mv $LOCATE_DB.n $LOCATE_DB
  138.   chmod 644 $LOCATE_DB
  139. else
  140.   echo "updatedb: new database would be empty" >&2
  141.   rm -f $LOCATE_DB.n
  142. fi
  143.