]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/locate/locate/updatedb.csh
BSD 4.4 Lite Usr.bin Sources
[FreeBSD/FreeBSD.git] / usr.bin / locate / locate / updatedb.csh
1 #!/bin/csh -f
2 #
3 # Copyright (c) 1989, 1993
4 #       The Regents of the University of California.  All rights reserved.
5 #
6 # This code is derived from software contributed to Berkeley by
7 # James A. Woods.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 #    notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 #    notice, this list of conditions and the following disclaimer in the
16 #    documentation and/or other materials provided with the distribution.
17 # 3. All advertising materials mentioning features or use of this software
18 #    must display the following acknowledgement:
19 #       This product includes software developed by the University of
20 #       California, Berkeley and its contributors.
21 # 4. Neither the name of the University nor the names of its contributors
22 #    may be used to endorse or promote products derived from this software
23 #    without specific prior written permission.
24 #
25 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 # SUCH DAMAGE.
36 #
37 #       @(#)updatedb.csh        8.3 (Berkeley) 3/19/94
38 #
39
40 set SRCHPATHS = "/"                     # directories to be put in the database
41 set LIBDIR = /usr/libexec               # for subprograms
42                                         # for temp files
43 if (! $?TMPDIR) setenv TMPDIR = /var/tmp
44 set FCODES = /var/db/locate.database    # the database
45
46 set path = ( /bin /usr/bin )
47 set bigrams = $TMPDIR/locate.bigrams.$$
48 set filelist = $TMPDIR/locate.list.$$
49 set errs = $TMPDIR/locate.errs.$$
50
51 # Make a file list and compute common bigrams.
52 # Alphabetize '/' before any other char with 'tr'.
53 # If the system is very short of sort space, 'bigram' can be made
54 # smarter to accumulate common bigrams directly without sorting
55 # ('awk', with its associative memory capacity, can do this in several
56 # lines, but is too slow, and runs out of string space on small machines).
57
58 # search locally or everything
59 # find ${SRCHPATHS} -print | \
60 find ${SRCHPATHS} \! -fstype local -prune -or -print | \
61         tr '/' '\001' | \
62         (sort -T $TMPDIR -f; echo $status > $errs) | tr '\001' '/' > $filelist
63
64 $LIBDIR/locate.bigram < $filelist | \
65         (sort -T /$TMPDIR; echo $status >> $errs) | \
66         uniq -c | sort -T /$TMPDIR -nr | \
67         awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $bigrams
68
69 # code the file list
70
71 if { grep -s -v 0 $errs } then
72         printf 'locate: updatedb failed\n\n'
73 else
74         $LIBDIR/locate.code $bigrams < $filelist > $FCODES
75         chmod 644 $FCODES
76         rm $bigrams $filelist $errs
77 endif