#!/bin/sh
#
# post install script for srcd
#

#
# PRE-INSTALL part
#
if [ "$2" = "PRE-INSTALL" ]
then
    if [ -f /etc/srcd.conf ]
    then
	if [ -f /etc/srcd.conf.1 ]
	then
	    if [ -f /etc/srcd.conf.2 ]
	    then
		if [ -f /etc/srcd.conf.3 ]
		then
		    if [ -f /etc/srcd.conf.4 ]
		    then
			echo "*** Found an old /etc/srcd.conf.4"
			echo "***   moving it to /etc/srcd.conf.5"
			mv /etc/srcd.conf.4 /etc/srcd.conf.5
		    fi
		    echo "*** Found an old /etc/srcd.conf.3"
		    echo "***   moving it to /etc/srcd.conf.4"
		    mv /etc/srcd.conf.3 /etc/srcd.conf.4
		fi
		echo "*** Found an old /etc/srcd.conf.2"
		echo "***   moving it to /etc/srcd.conf.3"
		mv /etc/srcd.conf.2 /etc/srcd.conf.3
	    fi
	    echo "*** Found an old /etc/srcd.conf.1"
	    echo "***   moving it to /etc/srcd.conf.2"
	    mv /etc/srcd.conf.1 /etc/srcd.conf.2
	fi
	echo "*** Found an old /etc/srcd.conf"
	echo "***   moving it to /etc/srcd.conf.1"
	mv /etc/srcd.conf /etc/srcd.conf.1
    fi
    exit 0
fi

#
# POST-INSTALL part
#

FBSD_VERSION=`uname -r|sed 's/\..*//'`

if [ "$FBSD_VERSION" = "4" ]
then
    if [ -x /usr/local/etc/srcd.sh ]
    then
        if [ ! -d /usr/local/etc/rc.d ]
        then
            mkdir -p /usr/local/etc/rc.d
        fi
        ln -s ../srcd.sh /usr/local/etc/rc.d/99srcd.sh
    fi
fi

if [ ! -c /dev/iir ]
then
    mknod /dev/iir c 164 0
fi

echo "---"
echo "--- Installation of $1 succeeded."
echo "--- You should now configure the service by "
echo "---    either editing /etc/srcd.conf"
echo "---    or executing /usr/sbin/srcdconf.sh "
echo "--- before starting the service."
echo "---"

exit 0

