#!/bin/sh
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.

[ -f "/var/lib/fail2ban/fail2ban.sqlite3" ] || exit 0

outfile=`mktemp /tmp/fail2ban-vacuum.XXXXXX`

trap 'rm -f $outfile;' TERM INT EXIT
sqlite3 /var/lib/fail2ban/fail2ban.sqlite3 "VACUUM;" >$outfile 2>&1

rc=$?
if [ $rc -eq 0 ]; then
	logger -t fail2ban-vacuum "Vacuum of fail2ban database successfully completed"
else
	logger -t fail2ban-vacuum -f "$outfile"
fi
exit $rc
