#!/bin/sh

#  bf_compact source_dir [wordlist_name]
#
#    use to compact wordlist.db
#    replaces original directory with new one
#    renames original directory with '.old' extension

# $Id: bf_compact,v 1.9 2004/12/24 22:05:15 relson Exp $

set -e # die on errors

if [ -z "$1" ] ; then
    echo usage: bf_compact source_dir [wordlist_name]
    exit 1
fi

ORIG="$1"
if [ -z "$2" ] ; then
    FILE="wordlist.db"
else
    FILE="$2"
fi

TEMP="bf_compact.$$"

if [ -d $TEMP ] ; then
    echo Directory $TEMP already exists.
    echo exiting.
    exit 1
else
    mkdir $TEMP
fi

if test -f "$ORIG"/DB_CONFIG ; then cp -p "$ORIG"/DB_CONFIG "$TEMP" ; fi
bogoutil -d "$ORIG"/"$FILE" | bogoutil -l $TEMP/"$FILE"

#checkpoint and remove unneeded log files
bogoutil --db-prune=$TEMP

mv "$ORIG" "$ORIG.old"
mv  $TEMP  "$ORIG"
