2 # updatedb -- build a locate pathname database
3 # Copyright (C) 1994 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # csh original by James Woods; sh conversion by David MacKenzie.
22 Usage: updatedb [--localpaths='dir1 dir2...'] [--netpaths='dir1 dir2...']
23 [--prunepaths='dir1 dir2...'] [--output=dbfile] [--netuser=user]
24 [--old-format] [--version] [--help]"
29 opt
=`echo $arg|sed 's/^\([^=]*\).*/\1/'`
30 val
=`echo $arg|sed 's/^[^=]*=\(.*\)/\1/'`
32 --localpaths) SEARCHPATHS
="$val" ;;
33 --netpaths) NETPATHS
="$val" ;;
34 --prunepaths) PRUNEPATHS
="$val" ;;
35 --output) LOCATE_DB
="$val" ;;
36 --netuser) NETUSER
="$val" ;;
37 --old-format) old
=yes ;;
38 --version) echo "GNU updatedb version @version@"; exit 0 ;;
39 --help) echo "$usage"; exit 0 ;;
40 *) echo "updatedb: invalid option $opt
46 # You can set these in the environment, or use command-line options,
47 # to override their defaults:
49 # Non-network directories to put in the database.
52 # Network (NFS, AFS, RFS, etc.) directories to put in the database.
55 # Directories to not put in the database, which would otherwise be.
56 : ${PRUNEPATHS="/tmp /usr/tmp /var/tmp /afs /amd /net /alex"}
58 # The same, in the form of a regex that find can use.
59 test -z "$PRUNEREGEX" &&
60 PRUNEREGEX
=`echo $PRUNEPATHS|sed -e 's,^,\\\(^,' -e 's, ,$\\\)\\\|\\\(^,g' -e 's,$,$\\\),'`
62 # The database file to build.
63 : ${LOCATE_DB=@LOCATE_DB@}
65 # Directory to hold intermediate files.
66 if test -d /var
/tmp
; then
72 # The user to search network directories as.
75 # The directory containing the subprograms.
76 : ${LIBEXECDIR=@libexecdir@}
78 # The directory containing find.
81 # The names of the utilities to run to build the database.
87 PATH
=$LIBEXECDIR:$BINDIR:/usr
/ucb
:/bin
:/usr
/bin
:$PATH export PATH
89 # Make and code the file list.
90 # Sort case insensitively for users' convenience.
92 if test $old = no
; then
94 # FIXME figure out how to sort null-terminated strings, and use -print0.
96 if test -n "$SEARCHPATHS"; then
98 \
( -fstype nfs
-o -fstype NFS
-o -fstype proc
-o -type d
-regex "$PRUNEREGEX" \
) -prune -o -print
101 if test -n "$NETPATHS"; then
102 if [ "`whoami`" = root
]; then
104 "$find $NETPATHS \\( -type d -regex \"$PRUNEREGEX\" -prune \\) -o -print"
106 $find $NETPATHS \
( -type d
-regex "$PRUNEREGEX" -prune \
) -o -print
109 } |
sort -f |
$frcode > $LOCATE_DB.n
111 # To avoid breaking locate while this script is running, put the
112 # results in a temp file, then rename it atomically.
113 if test -s $LOCATE_DB.n
; then
115 mv $LOCATE_DB.n
$LOCATE_DB
118 echo "updatedb: new database would be empty" >&2
124 bigrams
=$TMPDIR/f.bigrams$$
125 filelist
=$TMPDIR/f.list$$
126 trap 'rm -f $bigrams $filelist; exit' 1 15
128 # Alphabetize subdirectories before file entries using tr. James says:
129 # "to get everything in monotonic collating sequence, to avoid some
130 # breakage i'll have to think about."
132 if test -n "$SEARCHPATHS"; then
134 \
( -fstype nfs
-o -fstype NFS
-o -type d
-regex "$PRUNEREGEX" \
) -prune -o -print
136 if test -n "$NETPATHS"; then
137 if [ "`whoami`" = root
]; then
139 "$find $NETPATHS \\( -type d -regex \"$PRUNEREGEX\" -prune \\) -o -print"
141 $find $NETPATHS \
( -type d
-regex "$PRUNEREGEX" -prune \
) -o -print
144 } |
tr / '\001' |
sort -f |
tr '\001' / > $filelist
146 # Compute the (at most 128) most common bigrams in the file list.
147 $bigram < $filelist |
sort |
uniq -c |
sort -nr |
148 awk '{ if (NR <= 128) print $2 }' |
tr -d '\012' > $bigrams
150 # Code the file list.
151 $code $bigrams < $filelist > $LOCATE_DB
154 rm -f $bigrams $filelist $errs