#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)preinstall	1.17	08/11/19 SMI"

#
# When first introduced the /etc/inet/ipnodes file was seperate from
# /etc/inet/hosts.  It is now a symbolic link to /etc/inet/hosts.  The
# i.hosts class action script merges the saved temporary ipnodes file 
# into a single hosts file.
#
if [ ! -h $BASEDIR/etc/inet/ipnodes ]; then
	if [ -f $BASEDIR/etc/inet/ipnodes ]; then
		cp -f $BASEDIR/etc/inet/ipnodes \
			$BASEDIR/etc/inet/ipnodes.hostsmerge
	fi
fi

#
# TIMEZONE.temp is processed and removed by the i.definit class action
# script.
#
if [ -f $BASEDIR/etc/TIMEZONE ] ; then
	cp $BASEDIR/etc/TIMEZONE $BASEDIR/etc/TIMEZONE.temp
fi

# mail.ABCsavedXYZ is processed and removed by postinstall
if [ -h $BASEDIR/var/mail ] ; then
	rm -rf $BASEDIR/var/mail.ABCsavedXYZ
	mv $BASEDIR/var/mail $BASEDIR/var/mail.ABCsavedXYZ
fi

# news.ABCsavedXYZ is processed and removed by postinstall
if [ -h $BASEDIR/var/news ] ; then
	rm -rf $BASEDIR/var/news.ABCsavedXYZ
	mv $BASEDIR/var/news $BASEDIR/var/news.ABCsavedXYZ
fi

CLEANUP=/tmp/CLEANUP

print_dhcptags_warning() {

	cat >> $CLEANUP <<-EOF
	You have made changes to /etc/dhcp/dhcptags, which has been superseded
	by /etc/dhcp/inittab, as documented in dhcp_inittab(4).  Please refer
	to the DHCP documentation in the Answerbook for information on how to
	convert your existing customizations.
	EOF
}

if [ "x$UPDATE" = xyes ]; then

	DHCPTAGS=$BASEDIR/etc/dhcp/dhcptags

	# If the dhcptags file has been modified, then install moved
	# it to a funky name like /etc/dhcp/dhcptags:8.  Use this as
	# an opportunity to issue a warning to the user.  Since the
	# file may be left over from a previous upgrade, only issue
	# the warning if the current package database is familiar with
	# the file.
	#
	# The construct ${PKG_INSTALL_ROOT:-/} is used instead of
	# $PKG_INSTALL_ROOT/ because the packaging subsystem will
	# think we're changing the path (from $PKG_INSTALL_ROOT to
	# $PKG_INSTALL_ROOT/) and will output spurious warnings.
	#
	# We need to pass in the -R since otherwise we will get a
	# warning from a `make install' on this package that we may
	# be accessing a stale package database (in fact, this won't
	# happen since installf and friends inherit the
	# $PKG_INSTALL_ROOT environment variable).  Note that the -R
	# must be on the same line as the command it's used with.
	#
	# ${CLIENT_BASEDIR}foo is used instead of $CLIENT_BASEDIR/foo
	# because the packaging commands don't always realize that
	# //foo and /foo are the same file.

	if [ "`echo $DHCPTAGS:*`" != "$DHCPTAGS:*" ]; then
		pkgchk -l -R ${PKG_INSTALL_ROOT:-/}			\
		    -p ${CLIENT_BASEDIR}etc/dhcp/dhcptags $PKGINST |    \
		    grep -i installed > /dev/null 2>&1 &&		\
		    print_dhcptags_warning
	fi	

fi

if [ "$UPDATE" = yes ]; then
	# Check for existing smf(5) manifests
	BASEPREFIX=`echo $BASEDIR | sed "s/\//_/g"`
	if [ -f ${PKG_INSTALL_ROOT}/var/svc/network/ipsec/ike.xml ]; then
		IKEMANIFEST=`echo ike.xml"$BASEPREFIX" | cut -c 1-256`
		touch /tmp/${IKEMANIFEST}
	fi
	if [ -f ${PKG_INSTALL_ROOT}/var/svc/network/ipsec/manual-key.xml ]; then
		MANKEYMANIFEST=`echo manual-key.xml$BASEPREFIX" | cut -c 1-256`
		touch /tmp/${MANKEYMANIFEST}
	fi
fi

exit 0
