#!/bin/sh
# $OpenBSD: INSTALL,v 1.2 2000/03/07 01:58:07 kevlo Exp $
#
# Pre/post-installation setup of amanda

set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
PREFIX=${PREFIX:-/usr/local}
EXAMPLE_DIR=${EXAMPLE_DIR:-${PREFIX}/share/examples/amanda}
EXAMPLECONF_DIR=/usr/local/lib/amanda
CONF_DIR=/etc/amanda

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

# install the configuration files unless an existing configuration
# is found in which case warn the user that it may need to be
# updated.
#
do_configuration()
{
    if [ ! -d ${EXAMPLE_DIR} ]; then
	echo "-- Can't find configuration examples: ${EXAMPLE_DIR}" >&2
	exit 1
    fi

    echo ""
    if [ -d ${CONF_DIR} ]; then
	echo "** The directory ${CONF_DIR} exists.  Your existing configuration"
	echo "** files have not been changed.  You MAY need to update your"
	echo "** configuration.  Please look at the directory"
        echo "** ${EXAMPLECONF_DIR} and add any desired (but missing) entries into"
        echo "** your current ${CONF_DIR}"

    else
	mkdir -p ${EXAMPLECONF_DIR} ${CONF_DIR}
	mkdir -p ${EXAMPLECONF_DIR}/csd ${CONF_DIR}/csd
	cp ${EXAMPLE_DIR}/amanda.conf ${EXAMPLECONF_DIR}/csd
        cp ${EXAMPLE_DIR}/amanda.conf ${CONF_DIR}/csd
	echo "** The directory ${CONF_DIR} has been created with a sample"
	echo "** configuration.  You probably need to modify the files for"
	echo "** your site."
    fi
    echo ""
    echo "** See amanda(8) and the sample configuration files and INSTALL"
    echo "** instructions in ${EXAMPLE_DIR} for more information"
}

# create the needed /var directories
#
do_var()
{
    mkdir -p /var/amanda
}

# Output sample crontab entries
#
do_crontab()
{
    echo ""
    echo "** See ${CONF_DIR}/crontab.sample for sample crontab entries"
    cat >${EXAMPLECONF_DIR}/crontab.sample <<EOF
0 16 * * 1-5 /usr/local/bin/amcheck -m csd
45 0 * * 2-6 /usr/local/bin/amdump csd
EOF
    cp ${EXAMPLECONF_DIR}/crontab.sample ${CONF_DIR}
}

# Run the amanda "patch-system" command to update /etc/services and
# /etc/inetd.conf
#
do_system()
{
    echo ""
    echo "** udating /etc/services and /etc/inetd.  You should check"
    echo "** both of these files, verifying proper installation.  Once"
    echo "** verified issue the command:"
    echo "**	kill -HUP `cat /var/run/inetd.pid`"
    ${PREFIX}/libexec/patch-system
}

case $2 in
    PRE-INSTALL)
	: nothing to pre-install for this port
	;;
    POST-INSTALL)
	do_configuration
	do_crontab
	do_system
	echo ""
	;;
esac

exit 0

