#!/usr/bin/env bash

set -e

. ${0%/*}/_functions.sh

ok "* clamav init configuration"

if [ "$APP_ENV" = "dev" ]; then
  ok "* we will use bootstrap"
else
  ok "* deleting bootstrap since we are not dev env"
  rm -Rf /var/clamav-bootstrap
fi

mkdir /var/run/clamav 2>/dev/null
chown clamav:clamav /var/run/clamav
chmod 755 /var/run/clamav

replaceLine "Foreground " "Foreground true" /etc/clamav/clamd.conf
replaceLine "Foreground " "Foreground true" /etc/clamav/freshclam.conf
replaceLine "DatabaseDirectory /var/lib/clamav" "DatabaseDirectory /data/var/clamav" /etc/clamav/clamd.conf
replaceLine "DatabaseDirectory /var/lib/clamav" "DatabaseDirectory /data/var/clamav" /etc/clamav/freshclam.conf

cat /etc/clamav/clamd.conf | grep -v ScanOnAccess >/tmp/clamd.conf && mv /tmp/clamd.conf /etc/clamav/clamd.conf
# fix "WARNING: Ignoring deprecated option ScanOnAccess at /etc/clamav/clamd.conf:62"

rm /etc/logrotate.d/clamav-freshclam
