# $Id: Portfile,v 1.17 2006/05/28 13:45:19 mww Exp $

PortSystem 1.0

name			squid
version			2.5.STABLE14
categories		net
platforms		darwin
maintainers		mww@opendarwin.org
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	ftp://ftp.squid-cache.org/pub/squid-2/STABLE/ \
				http://www.squid-cache.org/Versions/v2/2.5/ \
				ftp://ftp.unimelb.edu.au/pub/cwis/servers/unix/squid/squid-2/STABLE/ \
				ftp://sunsite.auc.dk/pub/infosystems/squid/squid-2/STABLE/ \
				ftp://ftp.mirrorservice.org/sites/ftp.squid-cache.org/pub/squid-2/STABLE/ \
				http://ring.ip-kyoto.ad.jp/archives/net/www/squid/squid-2/STABLE/
checksums		md5 f413e0b887a5f9b2a75350243ed5564c \
                  sha1 ca7837c222800e25def1b6aad7d26245cb365960 \
                  rmd160 4af6b7c034e8b5aa19d8f95ec5a19f5780569224
use_bzip2		yes
patchfiles		patch-cf.data.pre.diff

depends_lib		port:openssl

configure.args	--with-pthreads \
				--mandir=${prefix}/share/man \
				--sysconfdir=${prefix}/etc/squid \
				--datadir=${prefix}/share/squid \
				--localstatedir=${prefix}/var/squid \
				--with-openssl=${prefix} \
				--enable-removal-policies

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

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

pre-destroot {
	addgroup squid
	set gid [existsgroup squid]
	adduser squid gid=${gid} realname=Squid\ Proxy home=${prefix}/var/squid
}
post-destroot	{
	reinplace "s|/etc/squid|${prefix}/etc/squid|g" \
		${destroot}${prefix}/share/man/man8/squid.8
	xinstall -o squid -g squid -m 755 -d \
		var/run/squid var/squid var/squid/cache var/squid/logs
	cd ${destroot}${prefix}/etc/squid
	file delete -force squid.conf mime.conf
}
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 } {
		if {![file exists ${prefix}/etc/squid/${f}]} {
			file copy ${prefix}/etc/squid/${f}.default \
				${prefix}/etc/squid/${f}
		}
	}
}

platform darwin 8 {
	configure.env	CC=/usr/bin/gcc-4.0 CPP=/usr/bin/cpp-4.0 CXX=/usr/bin/g++-4.0
}
