#!/bin/sh
# $OpenBSD: INSTALL,v 1.2 2000/06/28 07:08:32 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
CONFIG_FILE=${SYSCONFDIR}/squid.conf

install -d -o root -g wheel ${SYSCONFDIR}
install -d -o root -g wheel ${PREFIX}/share/squid/icons
install -d -o root -g wheel ${PREFIX}/share/squid/errors
install -d -o www -g www ${STATEDIR}
install -d -o www -g www ${STATEDIR}/logs
install -d -o www -g www ${STATEDIR}/cache
ln -sf ${STATEDIR}/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()
{
    install -o root -g wheel ${PREFIX}/lib/squid/conf/squid.conf.sample /etc/squid/squid.conf
    install -o root -g wheel ${PREFIX}/lib/squid/conf/mime.conf.sample /etc/squid/mime.conf
    install -o root -g wheel ${PREFIX}/lib/squid/conf/mib.txt.sample /etc/squid/mib.txt
    cp -R ${PREFIX}/lib/squid/errors/* ${PREFIX}/share/squid/errors
    cp -R ${PREFIX}/lib/squid/icons/* ${PREFIX}/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
