#!/bin/sh
# $OpenBSD: INSTALL,v 1.2 2002/04/26 03:35:34 pvalchev Exp $
#
# Pre/post-installation setup of wwwcount

# exit on errors, use a sane path and install prefix
#
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
PREFIX=${PKG_PREFIX:-/usr/local}
DATA_DIR=/var/www/wwwcount/data
CONFIG_DIR=/var/www/wwwcount/conf
CONFIG_FILE=${CONFIG_DIR}/count.cfg
SAMPLE_CONFIG_FILE=/usr/local/lib/wwwcount/count.cfg.sample
COUNT_SCRIPT=/usr/local/lib/wwwcount/Count.cgi
CGI_DIR=/var/www/cgi-bin

# Function: tell the user what s/he needs to do to use the port just installed
#
do_notice()
{
	echo
	echo "+---------------"
	echo "| The existing $1 configuration file,"
	echo "| ${CONFIG_FILE}, has NOT been changed."
	echo "| You may want to compare it to the current sample file, "
	echo "| ${SAMPLE_CONFIG_FILE}, and update"
	echo "| your configuration as needed."
	echo "+---------------"
	echo
}

# Function: install the wwwcount config file from the sample
#
do_install()
{
	umask 022
	[ -d ${DATA_DIR} ] || mkdir -p ${DATA_DIR}
	[ -d ${CONFIG_DIR} ] || mkdir -p ${CONFIG_DIR}
	cp ${SAMPLE_CONFIG_FILE} ${CONFIG_FILE}
	echo
	echo "+---------------"
	echo "| The $1 configuration file, ${CONFIG_FILE},"
	echo "| has been installed.  Please view this file and change"
	echo "| 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)
		install -o root -g bin -m 111 ${COUNT_SCRIPT} ${CGI_DIR}
		if [ -f $CONFIG_FILE ]; then
			do_notice $1
		else
			do_install $1
		fi
		;;
	*)
		echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
		exit 1
		;;
esac

exit 0
