#!/bin/sh
#
# Wrapper to set environment variables then exec the real zapper.
# The reasons for this are twofold:
#	- for some reason squid doesn't preserve the original environment
#	  when you do a restart (or SIGHUP)
#	- to avoid having to hack the squid startup script (if you have
#	  a presupplied one, such as ships with some linux distributions)
#
# Install in the same directory you put the zapper (just for convenience) and
# hack the pathnames below to suit.
# Note that you can skip this script and run the zapper with no environment
# settings at all and it will work fine; the variables are all set here merely
# for completeness so that customisation is easy for you.
#	- Cameron Simpson <cs@zip.com.au> 21apr2000
#

# modify this to match your install
zapper=/usr/local/libexec/squid_redirect

ZAP_MODE=				# or "CLEAR"
ZAP_BASE=http://adzap.cs.zip.com.au	# a local web server will be better
ZAP_BASE_SSL=https://adzap.cs.zip.com.au # this can probably be ignored
ZAP_PREMATCH=				# pathname of extra pattern file
					# for patterns to preempt the stock
					# zapper
ZAP_POSTMATCH=				# pathname of extra pattern file
					# for patterns in addition to the
					# stock zapper; this is the one to
					# which you should add new ads

. /usr/local/etc/adzap.conf

STUBURL_AD=$ZAP_BASE/ad.gif
STUBURL_ADSSL=$ZAP_BASE_SSL/ad.gif
STUBURL_ADBG=$ZAP_BASE/adbg.gif
STUBURL_ADJS=$ZAP_BASE/no-op.js
STUBURL_ADHTML=$ZAP_BASE/no-op.html
STUBURL_ADMP3=$ZAP_BASE/ad.mp3
STUBURL_ADPOPUP=$ZAP_BASE/closepopup.html
STUBURL_ADSWF=$ZAP_BASE/ad.swf
STUBURL_COUNTER=$ZAP_BASE/counter.gif
STUBURL_COUNTERJS=$ZAP_BASE/no-op-counter.js
STUBURL_WEBBUG=$ZAP_BASE/webbug.gif
STUBURL_WEBBUGJS=$ZAP_BASE/webbug.js

. /usr/local/etc/adzap.conf

export ZAP_MODE ZAP_BASE ZAP_BASE_SSL ZAP_PREMATCH ZAP_POSTMATCH
export STUBURL_AD STUBURL_ADSSL STUBURL_ADJS STUBURL_ADHTML STUDURL_ADMP3 \
	STUBURL_ADPOPUP STUBURL_ADSWF STUBURL_COUNTER STUBURL_COUNTERJS \
	STUBURL_WEBBUG STUBURL_WEBBUGJS

# Here, having arranged the environment, we exec the real zapper.
# If you're chaining redirectors then comment out the direct exec below and
# uncomment (and adjust) the exec of zapchain which takes care of running
# multiple redirections.

exec "$zapper"
# exec /path/to/zapchain "$zapper" /path/to/another/eg/squirm
