# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 68293 2010-05-31 08:04:03Z jmr@macports.org $

PortSystem 1.0

name            squid3
version         3.1.4
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      net
platforms       darwin
license         GPLv2+
maintainers     jmr openmaintainer
description     advanced proxy caching server for http, https, ftp, gopher
long_description    Squid is a high-performance proxy caching server for \
                web clients, supporting FTP, gopher, and HTTP data \
                objects. Unlike traditional caching software, Squid \
                handles all requests in a single, non-blocking, \
                I/O-driven process. Squid keeps meta data and \
                especially hot objects cached in RAM, caches DNS \
                lookups, supports non-blocking DNS lookups, and \
                implements negative caching of failed requests.

homepage        http://www.squid-cache.org/
master_sites    http://mirrors.24-7-solutions.net/pub/squid/ \
                http://mirror.aarnet.edu.au/pub/squid/squid/ \
                http://www.mirrorservice.org/sites/ftp.squid-cache.org/pub/squid/ \
                http://ftp.ring.gr.jp/archives/net/www/squid/ \
                ftp://ftp.is.co.za/pub/squid/ \
                ftp://ftp1.cl.squid-cache.org/pub/squid/ \
                http://www.squid-cache.org/Versions/v3/${branch}/ \
                ftp://ftp.squid-cache.org/pub/squid/

distname        squid-${version}
checksums       md5 3fb544ae02fadc2b4085f62bb927e861 \
                sha1 bb83b865c081c25a5989adf689923935742315e0 \
                rmd160 f2b7e4ff5cf2ab082ae71defa289d7d703b41266

use_bzip2       yes
patchfiles      patch-cf.data.pre.diff \
                patch-include_squid_types.h.diff \
                patch-pam_auth.c.diff

depends_lib     port:openssl port:zlib

conflicts       squid

configure.args  --mandir=${prefix}/share/man \
                --sysconfdir=${prefix}/etc/squid \
                --datadir=${prefix}/share/squid \
                --localstatedir=${prefix}/var/squid \
                --libexecdir=${prefix}/libexec/squid \
                --with-pidfile=${prefix}/var/run/squid/squid.pid \
                --with-openssl=${prefix} \
                --disable-ipv6 \
                --enable-delay-pools \
                --enable-zph-qos \
                --enable-removal-policies \
                --enable-storeio=ufs,aufs,diskd \
                --enable-disk-io=AIO,Blocking,DiskDaemon,DiskThreads \
                --enable-icap-client \
                --with-default-user=squid \
                --enable-auth=negotiate,ntlm,digest,basic \
                --enable-negotiate-auth-helpers=squid_kerb_auth \
                --enable-ntlm-auth-helpers=smb_lm,fakeauth,no_check \
                --enable-digest-auth-helpers=eDirectory,ldap,password \
                --enable-basic-auth-helpers=DB,LDAP,MSNT,NCSA,PAM,POP3,SMB,YP,getpwnam,multi-domain-NTLM,squid_radius_auth
post-configure {
    if {[variant_isset universal]} {
        system "cd ${worksrcpath} && ed - ${worksrcpath}/include/autoconf.h < ${filespath}/include_autoconf.h.ed && touch include/stamp-h1"
    }
}

use_parallel_build  yes

startupitem.create      yes
startupitem.name        Squid
startupitem.start \
    "cd ${prefix}/var/squid" \
    "if \[ ! -d \"${prefix}/var/squid/cache/00\" \]; then" \
    "\tsu -fm root -c \"exec ${prefix}/sbin/squid -s -z\"" \
    "fi" \
    "su -fm root -c \"exec ${prefix}/sbin/squid -s\""
startupitem.stop \
    "cd ${prefix}/var/squid" \
    "su -fm root -c \"exec ${prefix}/sbin/squid -k shutdown\""

pre-destroot {
    addgroup squid
    set gid [existsgroup squid]
    adduser squid gid=${gid} realname=Squid\ Proxy home=${prefix}/var/squid
}
post-destroot   {
    xinstall -o squid -g squid -m 755 -d \
        ${destroot}${prefix}/var/run/squid ${destroot}${prefix}/var/squid \
        ${destroot}${prefix}/var/squid/cache ${destroot}${prefix}/var/squid/logs
    file delete -force ${destroot}${prefix}/etc/squid/squid.conf \
                       ${destroot}${prefix}/etc/squid/mime.conf \
                       ${destroot}${prefix}/etc/squid/cachemgr.conf \
                       ${destroot}${prefix}/etc/squid/msntauth.conf \
                       ${destroot}${prefix}/etc/squid/errorpage.css
}
destroot.keepdirs   ${destroot}${prefix}/var/run/squid \
                ${destroot}${prefix}/var/squid/cache \
                ${destroot}${prefix}/var/squid/logs

post-activate {
    # Make sure initial conf files are present and setup correctly
    foreach f { squid.conf mime.conf cachemgr.conf msntauth.conf errorpage.css } {
        if {![file exists ${prefix}/etc/squid/${f}]} {
            file copy ${prefix}/etc/squid/${f}.default \
                ${prefix}/etc/squid/${f}
        }
    }
}

variant kqueue description "Enable kqueue() support (experimental)" {
    configure.args-append   --enable-kqueue
}

variant ipfw_transparent description "Enable transparent proxy support using IPFW" {
    configure.args-append   --enable-ipfw-transparent
}

livecheck.type  regex
livecheck.url   http://www.squid-cache.org/Versions/v3/${branch}/
livecheck.regex "<a href=\"RELEASENOTES\\.html\">squid-(3\[0-9.\]+)</a>"
