# $Id: Portfile 88135 2011-12-20 16:51:07Z pixilla@macports.org $

PortSystem              1.0

name                    clamav-server
version                 0.97.3
homepage                http://www.clamav.net/
categories              sysutils
platforms               darwin
supported_archs         noarch
maintainers             pixilla openmaintainer
license                 BSD
distfiles

description \
    launchdaemons for clamav antivirus software

long_description \
    Clam AntiVirus is a GPL anti-virus toolkit for UNIX. The \
    main purpose of this software is the integration with mail \
    servers (attachment scanning). This port installs launchdaemons \
    that can be used to manage clamav.

depends_run \
    port:clamav

if {"darwin" == ${os.platform} && ${os.major} > 8} {
    set clamavuser      _clamav
} else {
    set clamavuser      clamav
}

use_configure           no

build {}

set dataPath ${prefix}/var/clamav
set logPath ${prefix}/var/log/clamav
set runPath ${prefix}/var/run/clamav

destroot {
    addgroup ${clamavuser}
    set gid [existsgroup ${clamavuser}]
    adduser ${clamavuser} gid=${gid} realname=clamav
    set LaunchDaemonsPath ${destroot}/Library/LaunchDaemons
    xinstall -d ${LaunchDaemonsPath}
    xinstall -m 0644 -W ${filespath} \
        org.macports.clamd.plist \
        org.macports.freshclam.plist \
        ${LaunchDaemonsPath}
    reinplace "s|__PREFIX__|${prefix}|g" \
        ${LaunchDaemonsPath}/org.macports.clamd.plist \
        ${LaunchDaemonsPath}/org.macports.freshclam.plist
    xinstall -m 0755 -o ${clamavuser} -g ${clamavuser} -d \
        ${destroot}${dataPath} \
        ${destroot}${logPath} \
        ${destroot}${runPath}
    touch ${destroot}${logPath}/clamav.log
    destroot.keepdirs \
        ${destroot}${dataPath} \
        ${destroot}${runPath}
}

notes "******************************************************
* To configure clamd and freshclam look for the following files
* ${prefix}/etc/clamd.conf
* ${prefix}/etc/freshclam.conf
**
* If these files do not exist copy do the following to copy these files into place
cp ${prefix}/etc/example-clamd.conf ${prefix}/etc/clamd.conf
cp ${prefix}/etc/example-freshclam.conf ${prefix}/etc/freshclam.conf
**
* Alter/Add the following lines to your ${prefix}/etc/clamd.conf
* Comment out 'Example' near the top like so '#Example'
* LogFile ${logPath}/clamd.log
* PidFile ${runPath}/clamd.pid
* LocalSocket ${runPath}/clamd.socket
**
* Alter/Add the following lines to your ${prefix}/etc/freshclam.conf
* Comment out 'Example' near the top like so '#Example'
* UpdateLogFile ${logPath}/freshclam.log
* PidFile ${runPath}/freshclam.pid
* NotifyClamd ${prefix}/etc/clamd.conf
**
* Two launchd startup items have been installed
**
* To load clamd and freshclam do the following
launchctl load -w /Library/LaunchDaemons/org.macports.clamd.plist
launchctl load -w /Library/LaunchDaemons/org.macports.freshclam.plist
**
* To unload clamd and freshclam do the following
launchctl unload -w /Library/LaunchDaemons/org.macports.clamd.plist
launchctl unload -w /Library/LaunchDaemons/org.macports.freshclam.plist
**
* To try things out do
freshclam
* If all is well you should see your clamav database being updated
******************************************************"

livecheck.type    regex
livecheck.url     http://www.clamav.net/lang/en/download/sources/
livecheck.regex   "clamav-(\\d+(?:\\.\\d+)*)${extract.suffix}"
