#!/bin/sh
# $OpenBSD: INSTALL,v 1.8 2004/11/09 14:48:25 alek Exp $
#
# Pre/post-installation setup of freebsd_lib

# exit on errors, use a sane path and install prefix
#
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
PREFIX=${PKG_PREFIX:-/usr/local}/emul/freebsd

# Function: tell the user what s/he needs to do to use the port just installed
#
do_notice_top()
{
    echo
    echo "+---------------"
    echo "|"
}

do_notice_link()
{
    echo "| /emul/freebsd already exists but it's not a symlink to $PREFIX."
    echo "|"
    echo "| To make this port active you must make /emul/freebsd a symlink to"
    echo "| $PREFIX."
    echo "|"
}

do_notice_bottom()
{
    echo "| This package requires the sysctl kern.emul.freebsd being set to 1"
    echo "| and just did so. To make this change permanent, edit /etc/sysctl.conf."
    echo "|"
    echo "| Installation of $1 complete. See compat_freebsd(8)"
    echo "| for more information."
    echo "|"
    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)
	install -d -o root -g bin -m 755 /emul
	install -d -o root -g bin -m 755 $PREFIX
	;;
    POST-INSTALL)
	do_notice_top

	if [ -e /emul/freebsd ]; then
	    if [ x`readlink /emul/freebsd` != x"$PREFIX" ]; then
	    	do_notice_link
	    fi
	else
	    ln -sf $PREFIX /emul/freebsd
	fi
	
	do_notice_bottom $1
	;;
    *)
	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
	exit 1
	;;
esac

exit 0
