#!/bin/sh
# $OpenBSD: INSTALL,v 1.2 2003/04/20 17:36:40 sturm Exp $
#
# Pre/post-installation setup of logsentry

# exit on errors, use a sane path and install prefix

set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
CONFIG_DIR=/etc/logsentry
EXAMPLE_DIR=/usr/local/share/examples/logsentry
DOC_DIR=/usr/local/share/doc/logsentry
TMP_DIR=/var/tmp/logsentry

do_notice()
{
    echo
    echo "+---------------"
    echo "| The existing $1 configuration files in ${CONFIG_DIR},"
    echo "| have NOT been changed. You may want to compare them to the"
    echo "| current sample files in ${EXAMPLE_DIR},"
    echo "| and update your configuration as needed."
    echo "|"
    echo "| Also, verify that your crontab is configured as indicated"
    echo "| in /usr/local/share/doc/logsentry/INSTALL."
    echo "+---------------"
    echo
}

do_install()
{
    mkdir -m 600 /etc/logsentry
    if [ ! -d ${TMP_DIR} ]; then
       mkdir -m 600 ${TMP_DIR}
    fi
    install -o root -g wheel -m 700 ${EXAMPLE_DIR}/logsentry.sh ${CONFIG_DIR}
    install -o root -g wheel -m 600 ${EXAMPLE_DIR}/logsentry.hacking \
       ${CONFIG_DIR}
    install -o root -g wheel -m 600 ${EXAMPLE_DIR}/logsentry.ignore \
       ${CONFIG_DIR}
    install -o root -g wheel -m 600 ${EXAMPLE_DIR}/logsentry.violations \
       ${CONFIG_DIR}
    install -o root -g wheel -m 600 ${EXAMPLE_DIR}/logsentry.violations.ignore \
       ${CONFIG_DIR}

    echo
    echo "+---------------"
    echo "| The $1 configuration files have been installed at"
    echo "| ${CONFIG_DIR}. Please view these files and change the" 
    echo "| configuration to meet your needs."
    echo "|"
    echo "| Currently $1 will check the following files:"
    echo "|"
    echo "| /var/log/messages"
    echo "| /var/log/maillog"
    echo "| /var/log/authlog"
    echo "| /var/log/secure"
    echo "| /var/log/daemon"
    echo "| /var/log/xferlog"
    echo "|"
    echo "| Edit ${CONFIG_DIR}/logsentry.sh if you want to add more files."
    echo "|"
    echo "| Be sure to configure your crontab as indicated by"
    echo "| /usr/local/share/doc/logsentry/INSTALL so that $1"
    echo "| is run regularly."
    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 [ ! -d $CONFIG_DIR ]; then
	    do_install $1
	else
	    do_notice $1
	fi
	;;
    *)
	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
	exit 1
	;;
esac

exit 0
