1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-07-07 23:50:55 +00:00
mailinabox/setup/management-capture.sh
downtownallday 3f385e6835 vacuum only if non-empty
the file may have already been created by the management daemon
2025-03-22 18:37:46 -04:00

52 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
#####
##### This file is part of Mail-in-a-Box-LDAP which is released under the
##### terms of the GNU Affero General Public License as published by the
##### Free Software Foundation, either version 3 of the License, or (at
##### your option) any later version. See file LICENSE or go to
##### https://github.com/downtownallday/mailinabox-ldap for full license
##### details.
#####
source setup/functions.sh
source /etc/mailinabox.conf # load global vars
echo "Installing miabldap-capture daemon..."
conf="$STORAGE_ROOT/reporting/config.json"
db="$STORAGE_ROOT/reporting/capture.sqlite"
apt_install sqlite3
if [ ! -e "$conf" ]; then
mkdir -p $(dirname "$conf")
cat > "$conf" <<EOF
{
"capture": true,
"prune_policy": {
"frequency_min": 2400,
"older_than_days": 30
},
"drop_disposition": {
"failed_login_attempt": false,
"suspected_scanner": false,
"reject": false
}
}
EOF
fi
sed "s|%BIN%|$(pwd)|g" conf/miabldap-capture.service > /etc/systemd/system/miabldap-capture.service
hide_output systemctl daemon-reload
# vacuum database if it exists and is non-empty
if [ -s "$db" ]; then
echo "Vacuum capture database"
hide_output systemctl stop miabldap-capture
hide_output /usr/bin/sqlite3 "$db" "VACUUM;"
fi
hide_output systemctl enable miabldap-capture
restart_service miabldap-capture