#!/bin/sh
# updatedb -- build locate pathname database
# csh original by James Woods; sh conversion by David MacKenzie.
# Public domain.

# ftp.funet.fi edition by Matti Aarnio <mea@nic.funet.fi> 22-Jul-94

PATH=/ftp/files:/bin:/usr/bin

FINDHINCHO=postmaster

LOCBINS=/ftp/files
LOCATE_DB=/ftp/files/LOCATE.DB
filelist=/ftp/files/ALL_FILES
PREFIX="-27"

TMPDIR=/usr/tmp
export TMPDIR

bigrams=$TMPDIR/f.bigrams$$
errs=$TMPDIR/f.errs$$

trap 'rm -f $bigrams $errs' 0
trap 'rm -f $bigrams $errs; exit' 1 15

# Make a file list.  Alphabetize `/' before any other char with `tr'.


# Compute common bigrams.

$LOCBINS/bigram $PREFIX < $filelist | sort 2>> $errs | uniq -c | sort -nr |
  awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $bigrams

# Code the file list.

if test -s $errs; then
  echo 'updatedb: out of sort space' | mail $FINDHONCHO
else
  $LOCBINS/code $PREFIX $bigrams < $filelist > $LOCATE_DB
  rm -f $bigrams $errs
  chmod 644 $LOCATE_DB
fi
