#!/bin/sh
# $OpenBSD: INSTALL,v 1.2 2003/04/04 21:19:23 sturm Exp $
#
# Pre/post-installation setup of tetex base

# 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=/etc/tetex.cfg
TEXMFCNF=$PREFIX/share/texmf/web2c/texmf.cnf

do_prenotice()
{
    echo
    echo "+---------------"
}

do_texmf_cnf_install()
{
    mv $TEXMFCNF $TEXMFCNF.dist
    mv $TEXMFCNF.old $TEXMFCNF
    echo "| The existing $TEXMFCNF.old has"
    echo "| been installed as $TEXMFCNF."
    echo "| You may want to compare it to the distribution's file"
    echo "| $TEXMFCNF.dist and update your"
    echo "| configuration as needed."
    echo "|"
}

do_tetex_cfg_install()
{
    cp -p $PREFIX/share/examples/teTeX/tetex.cfg $CONFIG
}

do_tetex_cfg_notice()
{
    echo "| The existing configuration file $CONFIG has not been"
    echo "| updated. You may want to compare it to the distribution's"
    echo "| file $PREFIX/share/examples/teTeX/tetex.cfg and update"
    echo "| your configuration as needed."
    echo "|"
}

do_notice()
{
    echo "| Run $PREFIX/bin/texconfig to adjust for your local"
    echo "| environment or see $CONFIG."
    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)
	do_prenotice
	if [ -f $TEXMFCNF.old ]; then
	    do_texmf_cnf_install $1
	fi
	if [ -f $CONFIG ]; then
	    do_tetex_cfg_notice
	else
	    do_tetex_cfg_install
	fi
	do_notice
	;;
    *)
	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
	exit 1
	;;
esac

exit 0
