#!/bin/sh
# $OpenBSD: INSTALL,v 1.3 2003/07/09 07:17:15 pvalchev Exp $
#
# Pre/post-installation setup of conserver

# 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_FILE=/etc/conserver.cf
PASSWD_FILE=/etc/conserver.passwd
SAMPLE_DIR=$PREFIX/share/examples/conserver
SAMPLE_CONFIG_FILE=$SAMPLE_DIR/conserver.cf
SAMPLE_PASSWD_FILE=$SAMPLE_DIR/conserver.passwd
LOG_DIR=/var/consoles
SERVICES=/etc/services

# 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 files, $CONFIG_FILE and"
    echo "| $PASSWD_FILE have NOT been changed.  You may want to"
    echo "| compare them to the current sample files in $SAMPLE_DIR,"
    echo "| and update your configuration as needed.  Make sure"
    echo "| a line similar to this also exists in $SERVICES:"
    echo "| console	782/tcp conserver	# console server"
    echo "+---------------"
    echo
}

# Function: install the system conserver.cf from the sample
#
do_install()
{
    install -o root -g wheel -m 644 $SAMPLE_CONFIG_FILE $CONFIG_FILE
    install -o root -g wheel -m 600 $SAMPLE_PASSWD_FILE $PASSWD_FILE
    echo
    echo "+---------------"
    echo "| The $1 configuration files, $CONFIG_FILE and"
    echo "| $PASSWD_FILE,"
    echo "| have been installed.  Please view these files and change"
    echo "| the configuration to meet your needs."
    echo "| Refer to $SAMPLE_DIR/README.OpenBSD"
    echo "| You need to add a line similar to this to $SERVICES:"
    echo "| console	782/tcp conserver	# console server"
    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 [ -f $CONFIG_FILE ]; then
	    do_notice $1
	else
	    do_install $1
	fi
	mkdir -p $LOG_DIR
	;;
    *)
	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
	exit 1
	;;
esac

exit 0
