#!/bin/sh
PREFIX=/usr/local
IFHP_CONF=/usr/local/etc/ifhp.conf
INSTALL="/usr/bin/install -c -o root -g wheel"
DATADIR=/usr/local/share/ifhp
#
# -- START --
# postinstall.freebsd.sh,v 1.1 2001/08/21 20:33:16 root Exp
#
# If you are building a PORT, see the
# DISTRIBUTIONS directory for a complete port building package.
# 
# This is the shell script that does the postinstall
# dynamic fixup
#  It needs to be massaged with the information for
#  various paths.
# This version of the script has been massaged to work with the
# FreeBSD ports system.  When used with the ports system, this script
# is appended to special 'save the world' install script.
# At package install/deinstall you are invoked with:
#   script ifhp-<version> PRE-INSTALL
#   script ifhp-<version> POST-INSTALL
#   script ifhp-<version> DEINSTALL
#   script ifhp-<version> POST-DEINSTALL
# Under these circumstances, you may not want to stop or start
# the LPD server.
if [ "$VERBOSE_INSTALL" != "" ] ; then
	echo RUNNING postinstall.generic.sh parms "'$0 $@'" MAKEPACKAGE="$MAKEPACKAGE" MAKEINSTALL="$MAKEINSTALL" PREFIX="$PREFIX" INIT="$INIT" cwd `pwd` "INSTALL='$INSTALL'"
	set -x;
fi

fix () {
    v=`echo $1 | sed -e 's/[:;].*//'`;
    p=`echo $2 | sed -e 's/:.*//'`; d=`dirname $p`;
    if expr "$p" : "\|" >/dev/null ; then
        echo "$v is a filter '$p'" 
        return 0
    fi
	n=`basename $p`
    echo "Putting $n in $d, using $v"
    if [ ! -d "$d" ] ; then
        echo "Directory $d does not exist!"
        mkdir -p $d
    fi
	if [ -f $p ] ; then
		if ! diff $v $p ; then
			sv="$p.`date '+%Y_%m_%d'`";
			cnt=1;
			while [ -f "$sv.$cnt" ] ; do
				cnt=$(($cnt + 1))
			done
			sv="$sv.$cnt";
			cp $p $sv;
		fi
	fi
	${INSTALL} $v $p.sample;
	${INSTALL} $v $p;
}

hold=${DESTDIR}${DATADIR}
if [ "x$2" = 'x' -o "x$2" = "xPOST-INSTALL" ] ; then
	echo "Copy configuration files from " ${hold}
	fix ${hold}/ifhp.conf.sample "${DESTDIR}${IFHP_CONF}"
fi

if [ "x$2" = "xDEINSTALL" ] ; then
	for i in "${DESTDIR}${IFHP_CONF}" ; do
		if diff "$i" "$i.sample" >/dev/null ; then
			# no changes
			rm -f $i
		fi
		rm -f "$i.sample"
	done
fi
