#!/bin/sh
# $OpenBSD: INSTALL,v 1.5 2003/04/25 19:33:06 sturm Exp $
#
# Pre/post-installation setup of amanda

set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
PREFIX=${PKG_PREFIX:-/usr/local}
EXAMPLE_DIR=$PREFIX/share/examples/amanda
CONF_DIR=${SYSCONFDIR}/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 "** ${EXAMPLE_DIR} and add any desired (but missing) entries into"
        echo "** your current ${CONF_DIR}"

    else
	mkdir -p ${CONF_DIR}/csd
        cp ${EXAMPLE_DIR}/amanda.conf ${CONF_DIR}/csd
        cp ${EXAMPLE_DIR}/disklist ${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/gnutar-lists
    chown -R operator:operator /var/amanda
}

# create the needed /etc/amandates file if it does not exist 
# note that it is hardwired to be in /etc, not ${SYSCONFDIR}
#
do_amandates()
{
    touch /etc/amandates
    chown operator:operator /etc/amandates
}

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

exit 0
