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