#!/bin/sh
# cpanel - clamavconnector/uninstall              Copyright(c) 2012 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

AVV=0.97.8

./setupcrontab off

cd clamav-$AVV
make uninstall
killall -9 clamd

rm -f /var/clamd
rm -f /var/run/chkservd/clamd

# Disable clamav monitor setting
if [ -e /etc/chkserv.d/chkservd.conf ]; then 
    conf_file='/etc/chkserv.d/chkservd.conf'
    sed s/clamd:1/clamd:0/ $conf_file > $conf_file.temp  
    mv $conf_file.temp $conf_file
fi

rm -f /etc/chkserv.d/clamd
if [ -x /usr/local/cpanel/scripts/restartsrv_chkservd ]; then
    /usr/local/cpanel/scripts/restartsrv_chkservd
elif [ -x /etc/rc.d/init.d/chkservd ]; then
    /etc/rc.d/init.d/chkservd restart
else
    echo 'Warning: Unable to restart chkservd ... Neither "restartsrv_chkservd" nor "/etc/rc.d/init.d/chkservd" could be detected for execution.'
fi

/usr/local/cpanel/scripts/buildeximconf
/usr/local/cpanel/scripts/restartsrv exim

if [ -d "/usr/local/cpanel/base/frontend/x" ]; then
    rm -rf /usr/local/cpanel/base/frontend/x/cells
    rm -rf /usr/local/cpanel/base/frontend/x/clamavconnector
fi

if [ -d "/usr/local/cpanel/base/frontend/x2" ]; then
    rm -rf /usr/local/cpanel/base/frontend/x2/cells
    rm -ff /usr/local/cpanel/base/frontend/x2/clamavconnector
fi

rm -f /usr/local/cpanel/whostmgr/addonfeatures/clamavconnector
rm -f /usr/local/cpanel/whostmgr/docroot/cgi/addon_clamavconnector.cgi

if [ -h "/usr/local/bin/freshclam" ]; then
    rm -f /usr/local/bin/freshclam
fi

if [ -e "/usr/local/cpanel/Cpanel/ClamScanner.pm" -a ! -e "/var/cpanel/dev_sandbox" ]; then
    rm -f /usr/local/cpanel/Cpanel/ClamScanner.pm
else
    echo 'FYI: Detected sandbox environment ... Removal of "ClamScanner.pm" does not apply.'
fi

cd ..

if [ -e "/usr/local/cpanel/bin/unregister_appconfig" ]; then 
    /usr/local/cpanel/bin/unregister_appconfig appconfig/clamavconnector.conf
else 
    rm -f /var/cpanel/apps/clamavconnector.conf
fi

