#!/bin/sh
#
# Pre/post-installation setup of jesred

# 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_DIR=${SYSCONFDIR}/jesred
SAMPLE_DIR=$PREFIX/share/examples/jesred


do_notice()
{
    echo
    echo "+---------------"
    echo "| The existing $1 configuration files in"
    echo "| $CONFIG_DIR, have NOT been changed."
    echo "| You may want to compare configuration files"
    echo "| with samples in ${SAMPLE_DIR}"
    echo "| and update your configuration as needed."
    echo "+---------------"
    echo
}

do_install()
{
    cd $SAMPLE_DIR
    install -d -m 755 -o root -g wheel ${CONFIG_DIR}
    install -m 644 -o root -g wheel jesred.conf.sample ${CONFIG_DIR}/jesred.conf
    install -m 644 -o root -g wheel redirect.acl.sample ${CONFIG_DIR}/redirect.acl
    install -m 644 -o root -g wheel redirect.rules.sample ${CONFIG_DIR}/redirect.rules

    echo
    echo "+---------------"
    echo "| The $1 configuration files in $CONFIG_DIR,"
    echo "| have been installed."
    echo "| Please view these files and change the"
    echo "| 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 [ -e ${CONFIG_DIR} ]; then
		do_notice "$1"
	else
		do_install "$1"
	fi

	;;
    *)
	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
	exit 1
	;;
esac
