#!/bin/sh
# $OpenBSD: INSTALL,v 1.1 1999/05/09 20:01:57 brad Exp $
#
# Pre/post-installation setup of squid

# exit on errors, use a sane path and install prefix
#
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
PREFIX=${PKG_PREFIX:-/usr/local}
CONFIG_FILE=/etc/squid/squid.conf

mkdir -p /etc/squid
mkdir -p /usr/local/share/squid/icons
mkdir -p /usr/local/share/squid/errors
install -d -o www -g www /var/squid
install -d -o www -g www /var/squid/logs
install -d -o www -g www /var/squid/cache
ln -sf /var/squid/logs/squid.pid /var/run/squid.pid

# Function: tell the user what s/he needs to do to use the port just installed
#
do_notice_conf()
{
    echo
    echo "+---------------"
    echo "| The existing $1 configuration files in /etc/squid have NOT"
    echo "| been changed.  You may want to compare them to the current samples in"
    echo "| ${PREFIX}/lib/squid/conf, and update your configuration files as needed."
    echo "+---------------"
    echo
}

# Function: install the system configuration files from the samples
#
do_install_conf()
{
    cp ${PREFIX}/lib/squid/conf/squid.conf.sample /etc/squid/squid.conf
    cp ${PREFIX}/lib/squid/conf/mime.conf.sample /etc/squid/mime.conf
    cp ${PREFIX}/lib/squid/conf/mib.txt.sample /etc/squid/mib.txt
    cp -R ${PREFIX}/lib/squid/errors/* /usr/local/share/squid/errors
    cp -R ${PREFIX}/lib/squid/icons/* /usr/local/share/squid/icons
    echo
    echo "+---------------"
    echo "| The $1 configuration files have been installed in /etc/squid."
    echo "| Please view these files and change the configuration to meet your needs."
    echo "+---------------"
    echo
}

# verify proper execution
#
if [ $# -ne 2 ]; then
    echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
    exit 1
fi

# Verify/process the command
#
case $2 in
    PRE-INSTALL)
	: nothing to pre-install for this port
	;;
    POST-INSTALL)
	if [ -f $CONFIG_FILE ]; then
	    do_notice_conf $1
	else
	    do_install_conf $1
	fi
	;;
    *)
	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
	exit 1
	;;
esac

exit 0
