/usr/bin/bf_compact-bdb is in bogofilter-bdb 1.2.4+dfsg1-12.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | #! /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.in 6749 2008-10-15 23:08:06Z clint $
set -e # die on errors
: ${BOGOFILTER:=bogofilter}
: ${BOGOUTIL:=bogoutil}
if [ -z "$1" ] ; then
echo 'usage: bf_compact source_dir [wordlist_name...]'
exit 1
fi
# extract home directory
BOGOHOME="$1"
shift
if [ ! -d "$BOGOHOME" ] ; then
echo "$BOGOHOME must be a directory, not a file"
exit 1
fi
# strip trailing slashes
while true; do
case "$BOGOHOME" in
*/) BOGOHOME=${BOGOHOME%/} ;;
*) break ;;
esac
done
export BOGOHOME
# find wordlists
if [ -n "$1" ] ; then
FILES="$@"
else
DIR=$($BOGOFILTER -QQ | grep ^bogofilter_dir | awk '{print $3}')
if [ "$BOGOHOME" != "$DIR" ] ; then
FILES=$(ls "$BOGOHOME"/*.db)
else
FILES=$($BOGOFILTER -QQ | grep ^wordlist | cut -f3 -d,)
fi
fi
BOGOTEMP="bf_compact.$$"
mkdir "$BOGOTEMP" || {
echo "Cannot create directory $BOGOTEMP. Abort."
exit 1
}
# copy Berkeley DB configuration if present
if test -f "$BOGOHOME"/DB_CONFIG ; then
cp -p "$BOGOHOME"/DB_CONFIG "$BOGOTEMP"/
fi
case "$($BOGOFILTER -V | grep Database:)" in
*"Berkeley DB"*)
# determine transactions
if test "$(find "$BOGOHOME/" -name "log.??????????" -print)" = "" ; then
TXN=no
else
TXN=yes
fi
;;
*)
TXN=noarg
;;
esac
# reload files
for FILE in $FILES ; do
NAME="$(basename $FILE)"
$BOGOUTIL --db-verify "$FILE" \
|| { echo "$FILE corrupted, aborting." ; rm -r "$BOGOTEMP" ; exit 1 ; }
$BOGOUTIL -d "$FILE" | case $TXN in
no|yes) $BOGOUTIL --db-transaction=no -l "$BOGOTEMP/$NAME" ;;
noarg) $BOGOUTIL -l "$BOGOTEMP/$NAME" ;;
esac
done
if [ $TXN = "yes" ] ; then
#create database environment files
$BOGOFILTER -e -C -d "$BOGOTEMP" --db-transaction=yes < /dev/null
fi
# remove $BOGOHOME.old so we don't move the new backup *into* it
# rather than renaming the backup to it.
rm -rf "$BOGOHOME.old"
mv "$BOGOHOME" "$BOGOHOME.old"
mv "$BOGOTEMP" "$BOGOHOME"
|