Fixes for locates updatedb.csh script, remove -T from sort
[unix-history] / usr / src / usr.bin / locate / locate / updatedb.csh
CommitLineData
73a38c8c
WJ
1#!/bin/csh -f
2#
3# Copyright (c) 1989 The Regents of the University of California.
4# 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 5.1 (Berkeley) 4/2/91
38#
92609681
GR
39# PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
40# -------------------- ----- ----------------------
41# CURRENT PATCH LEVEL: 1 00132
42# -------------------- ----- ----------------------
43#
44# 04 Apr 93 Geoff Rehmet Modified to remove the -T option
45# from all of the sort calls
46#
73a38c8c
WJ
47
48set SRCHPATHS = "/" # directories to be put in the database
49set LIBDIR = /usr/libexec # for subprograms
50if (! $?TMPDIR) set TMPDIR = /var/tmp # for temp files
51set FCODES = /var/db/locate.database # the database
52
53set path = ( /bin /usr/bin )
54set bigrams = $TMPDIR/locate.bigrams.$$
55set filelist = $TMPDIR/locate.list.$$
56set errs = $TMPDIR/locate.errs.$$
57
58# Make a file list and compute common bigrams.
59# Alphabetize '/' before any other char with 'tr'.
60# If the system is very short of sort space, 'bigram' can be made
61# smarter to accumulate common bigrams directly without sorting
62# ('awk', with its associative memory capacity, can do this in several
63# lines, but is too slow, and runs out of string space on small machines).
64
65# search locally or everything
66# find ${SRCHPATHS} -print | \
67find ${SRCHPATHS} ! -fstype local -a -prune -o -print | \
68 tr '/' '\001' | \
92609681 69 (sort -f; echo $status > $errs) | tr '\001' '/' > $filelist
73a38c8c
WJ
70
71$LIBDIR/locate.bigram < $filelist | \
92609681
GR
72 (sort ; echo $status >> $errs) | \
73 uniq -c | sort -nr | \
73a38c8c
WJ
74 awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $bigrams
75
76# code the file list
77
78if { grep -s -v 0 $errs } then
79 printf 'locate: updatedb failed\n\n'
80else
81 $LIBDIR/locate.code $bigrams < $filelist > $FCODES
82 chmod 644 $FCODES
83 rm $bigrams $filelist $errs
84endif