summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authornate <nate@FreeBSD.org>1995-11-09 00:48:41 +0000
committernate <nate@FreeBSD.org>1995-11-09 00:48:41 +0000
commitfb600fd0f668853b825474437a968ed33370e37e (patch)
tree93f049e599b325f98a43b1b5c6b76bcb2f2379b8 /usr.bin
parenta2bca2c1aca67ce2c4ce6298073390af953d472f (diff)
downloadFreeBSD-src-fb600fd0f668853b825474437a968ed33370e37e.zip
FreeBSD-src-fb600fd0f668853b825474437a968ed33370e37e.tar.gz
Re-wrote the locate.updatedb script in /bin/sh for speed and portability.
Obtained from: Partially my work in 1.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/locate/locate/Makefile2
-rw-r--r--usr.bin/locate/locate/updatedb.sh79
2 files changed, 80 insertions, 1 deletions
diff --git a/usr.bin/locate/locate/Makefile b/usr.bin/locate/locate/Makefile
index 928bc71..f95067c 100644
--- a/usr.bin/locate/locate/Makefile
+++ b/usr.bin/locate/locate/Makefile
@@ -4,7 +4,7 @@ PROG= locate
beforeinstall:
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- ${.CURDIR}/updatedb.csh ${DESTDIR}/usr/libexec/locate.updatedb
+ ${.CURDIR}/updatedb.sh ${DESTDIR}/usr/libexec/locate.updatedb
.include "../../Makefile.inc"
.include <bsd.prog.mk>
diff --git a/usr.bin/locate/locate/updatedb.sh b/usr.bin/locate/locate/updatedb.sh
new file mode 100644
index 0000000..bcd3456
--- /dev/null
+++ b/usr.bin/locate/locate/updatedb.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+#
+# Copyright (c) 1989, 1993
+# The Regents of the University of California. All rights reserved.
+#
+# This code is derived from software contributed to Berkeley by
+# James A. Woods.
+#
+# Modified to be a /bin/sh script by Nate Williams
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by the University of
+# California, Berkeley and its contributors.
+# 4. Neither the name of the University nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# @(#)updatedb.csh 8.3 (Berkeley) 3/19/94
+#
+
+SRCHPATHS="/" # directories to be put in the database
+LIBDIR="/usr/libexec" # for subprograms
+FCODES="/var/db/locate.database" # the database
+if [ "$TMPDIR" = "" ]; then
+ TMPDIR="/var/tmp" # for temp files
+fi
+
+PATH=/bin:/usr/bin
+BIGRAMS="$TMPDIR/locate.bigrams.$$"
+FILELIST="$TMPDIR/locate.list.$$"
+ERRS="$TMPDIR/locate.errs.$$"
+
+# Make a file list and compute common bigrams.
+# Alphabetize '/' before any other char with 'tr'.
+# If the system is very short of sort space, 'bigram' can be made
+# smarter to accumulate common bigrams directly without sorting
+# ('awk', with its associative memory capacity, can do this in several
+# lines, but is too slow, and runs out of string space on small machines).
+
+# search locally or everything
+# find ${SRCHPATHS} -print | \
+find ${SRCHPATHS} ! -fstype local -prune -or -print | \
+ tr '/' '\001' | \
+ (sort -T $TMPDIR -f; echo $? > $ERRS) | tr '\001' '/' > $FILELIST
+
+$LIBDIR/locate.bigram < $FILELIST | \
+ (sort -T $TMPDIR ; echo $? >> $ERRS) | \
+ uniq -c | sort -T $TMPDIR -nr | \
+ awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $BIGRAMS
+
+# code the file list
+if [ `sort -u $ERRS | grep -s -v 0` ]; then
+ printf 'locate: updatedb failed\n\n'
+else
+ $LIBDIR/locate.code $BIGRAMS < $FILELIST > $FCODES
+ chmod 644 $FCODES
+ rm $BIGRAMS $FILELIST $ERRS
+fi
OpenPOWER on IntegriCloud