#!/bin/sh
# $OpenBSD: INSTALL,v 1.1.1.1 2001/07/13 18:53:55 pvalchev Exp $
#
# Pre/post-installation setup of grace

# exit on errors, use a sane path and install prefix
#
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
PREFIX=${PKG_PREFIX:-/usr/local}
GRACE_DIR=/usr/local/grace
NO_X11=`echo "$1" | sed -e "s/.*-no_x11/no_x11/"`

do_notice()
{
    echo
    echo "+---------------"
    echo "| A file/link $PREFIX/bin/grace has been found."
    echo "| Links to grace files will not be set!"
    echo "+---------------"
    echo
}

do_install()
{
    if [ $NO_X11 == "no_x11" ]; then
        ln -s $GRACE_DIR/bin/grace $PREFIX/bin/grace
        ln -s $GRACE_DIR/bin/grace $PREFIX/bin/gracebat
    else
        ln -s $GRACE_DIR/bin/xmgrace $PREFIX/bin/grace
        ln -s $GRACE_DIR/bin/xmgrace $PREFIX/bin/gracebat
        ln -s $GRACE_DIR/bin/xmgrace $PREFIX/bin/xmgrace
        ln -s $GRACE_DIR/doc/xmgrace.1 $PREFIX/man/man1/xmgrace.1
    fi
    ln -s $GRACE_DIR/include/grace_np.h $PREFIX/include/grace_np.h
    ln -s $GRACE_DIR/lib/libgrace_np.a $PREFIX/lib/libgrace_np.a
    ln -s $GRACE_DIR/doc/grace.1 $PREFIX/man/man1/grace.1
    ln -s $GRACE_DIR/doc/gracebat.1 $PREFIX/man/man1/gracebat.1
    ln -s $GRACE_DIR/doc/grconvert.1 $PREFIX/man/man1/grconvert.1
}

# 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 [ -x $PREFIX/bin/grace ]; then
		do_notice $1
	else
		do_install $1
	fi
	;;
    *)
	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
	exit 1
	;;
esac

exit 0
