#!/bin/sh
# $OpenBSD: INSTALL,v 1.3 2000/05/31 18:48:39 form Exp $
#
# Pre/post-installation setup of analog

IMAGES="analogo.gif bara1.gif bara16.gif bara2.gif bara32.gif bara4.gif \
	bara8.gif barb1.gif barb16.gif barb2.gif barb32.gif barb4.gif \
	barb8.gif barc1.gif barc16.gif barc2.gif barc32.gif barc4.gif \
	barc8.gif bard1.gif bard16.gif bard2.gif bard32.gif bard4.gif \
	bard8.gif bare1.gif bare16.gif bare2.gif bare32.gif bare4.gif \
	bare8.gif barf1.gif barf16.gif barf2.gif barf32.gif barf4.gif \
	barf8.gif barg1.gif barg16.gif barg2.gif barg32.gif barg4.gif \
	barg8.gif barh1.gif barh16.gif barh2.gif barh32.gif barh4.gif \
	barh8.gif html2.gif"

# 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/analog.cfg
SAMPLE_CONFIG_FILE=${PREFIX}/share/analog/analog.cfg

# verify proper execution
#
if [ $# -ne 2 ]; then
    echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
    exit 1
fi

# 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 file, ${CONFIG_FILE},"
    echo "| has NOT been changed.  You may want to compare it to the"
    echo "| current sample file, ${SAMPLE_CONFIG_FILE},"
    echo "| and update your configuration as needed."
    echo "+---------------"
    echo
}

# Function: install the default analog.cfg from the sample
#
do_install()
{
    install -o root -g wheel -m 644 ${SAMPLE_CONFIG_FILE} ${CONFIG_FILE}
    echo
    echo "+---------------"
    echo "| The $1 configuration file, ${CONFIG_FILE},"
    echo "| has been installed.  Please view this file and change"
    echo "| the configuration to meet your needs."
    echo "+---------------"
    echo

}

# Verify/process the command
#
case $2 in
    PRE-INSTALL)
	: nothing to pre-install for this port
	;;
    POST-INSTALL)
	install -d -o root -g bin -m 755 /var/www/htdocs/analog-images
	[ -d /var/www/cgi-bin ] || \
		install -d -o root -g daemon -m 755 /var/www/cgi-bin
	for img in ${IMAGES}; do
		install -o root -g bin -m 444 \
			${PREFIX}/share/analog/images/${img} \
			/var/www/htdocs/analog-images
	done
	install -o root -g bin -m 111 ${PREFIX}/share/analog/anlgform.pl \
		/var/www/cgi-bin
	if [ -f ${CONFIG_FILE} ]; then
		do_notice $1
	else
		do_install $1
	fi
	;;
    *)
	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
	exit 1
	;;
esac

exit 0
