#!/bin/bash

LOG_ROOT_DIR="/var/log/clamav"
CLAMAV_LOG_FILE="${LOG_ROOT_DIR}/clamav.log"
FRESH_LOG_FILE="${LOG_ROOT_DIR}/freshclam.log"
FRESH_STATUS_LOG_FILE="${LOG_ROOT_DIR}/freshclam-status.log"

[ "$(CreoleGet activer_clam non)" = 'oui' ] || exit 0

# Reload apparmor profile with new capabilities #7063
APPARMOR_CONF=/etc/apparmor.d/usr.sbin.clamd
apparmor_parser -r ${APPARMOR_CONF}

#fixes #1711 : droits sur les fichiers de log
if [ -e ${LOG_ROOT_DIR} ]
then
    chown -R root:clamav ${LOG_ROOT_DIR}
fi

# attribution des droits pour freshclam minimaux #8001
if [ -e ${FRESH_LOG_FILE} ]
then
    /bin/chown -R clamav:clamav ${FRESH_LOG_FILE}
else
    touch ${FRESH_LOG_FILE}
    /bin/chown -R clamav:clamav ${FRESH_LOG_FILE}
fi

[ ! -e ${FRESH_STATUS_LOG_FILE} ] && touch ${FRESH_STATUS_LOG_FILE}
/bin/chown -R clamav:clamav ${FRESH_STATUS_LOG_FILE}

service clamav-freshclam status > /dev/null 2>&1
if [ $? != 0 ]; then
    #démarre freshclam pour que les fichiers de mises à jour soient copiés
    service clamav-freshclam start > /dev/null 2>&1
else
    #fixe #1623
    /usr/share/eole/sbin/clamd-reload.sh > /dev/null 2>&1
fi

exit 0
