# -*- 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$

PortSystem 1.0

name            squid
version         2.7.STABLE9
revision        2
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      net
platforms       darwin
license         GPL-2+
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/v2/${branch}/ \
                ftp://ftp.squid-cache.org/pub/squid/

checksums       md5 3c6642c85470b1079207d43bba25a819 \
                sha1 bd389da9b74fd338e358f6b3f83bd3a1ed4d4f6f \
                rmd160 bfa7c3dc3ede68646603f3379de35f44d7d8e97d

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

depends_lib     port:zlib

conflicts       squid3

configure.args  --with-pthreads \
                --mandir=${prefix}/share/man \
                --sysconfdir=${prefix}/etc/squid \
                --datadir=${prefix}/share/squid \
                --localstatedir=${prefix}/var/squid \
                --libexecdir=${prefix}/libexec/squid \
                --enable-delay-pools \
                --enable-removal-policies \
                --enable-storeio=ufs,aufs,diskd,coss,null \
                --enable-auth=negotiate,ntlm,digest,basic \
                --enable-negotiate-auth-helpers=squid_kerb_auth \
                --enable-ntlm-auth-helpers=SMB,fakeauth,no_check \
                --enable-digest-auth-helpers=eDirectory,ldap,password \
                --enable-basic-auth-helpers=DB,LDAP,MSNT,NCSA,PAM,POP3,SASL,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"
    }
}

build.args      DEFAULT_PID_FILE=${prefix}/var/run/squid/squid.pid
use_parallel_build  yes

startupitem.create      yes
startupitem.name        Squid
startupitem.netchange   yes
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\""

add_users       squid group=squid 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/msntauth.conf
    move ${destroot}${prefix}/etc/squid/cachemgr.conf \
         ${destroot}${prefix}/etc/squid/cachemgr.conf.default
}
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 } {
        if {![file exists ${prefix}/etc/squid/${f}]} {
            file copy ${prefix}/etc/squid/${f}.default \
                ${prefix}/etc/squid/${f}
        }
    }
}

variant openssl description "Enable SSL/TLS support using OpenSSL" {
    depends_lib-append      port:openssl
    configure.args-append   --with-openssl=${prefix} \
                            --enable-ssl
}

default_variants    +openssl

livecheck.type  regex
livecheck.url   http://www.squid-cache.org/Versions/v2/${branch}/
livecheck.regex squid-(${branch}\\.STABLE\[0-9\\.\]+)-RELEASENOTES