#! /usr/bin/sh
#
# ident	"@(#)postinstall 1.3     05/02/05 SMI"
#
# Copyright (c) 2004 by Sun Microsystems, Inc.
# All rights reserved.
#
# Permitted exit codes:
# 0 = success, 1 = fatal error, 2 = warning (install continues),
# 3 = install suspended cleanly, 10/20 = reboot after install all/current
#

# Set the install root directory for lookup; use PKG_INSTALL_ROOT if set:
iroot=${PKG_INSTALL_ROOT:-$BASEDIR}

PATH="/usr/bin:/usr/sbin"
export PATH

PERL="/opt/SUNWcest/bin/perl"


#
# Verify required binary is present:
#
if  [ ! -x "${PERL}" ]
then
	# TRANSLATION_NOTE: %s is the name of the missing file.
	printf "`gettext \
		'\nWARNING: Perl executable not found at "%s".\ncediag(1M) will not run until Perl is installed.'`" \
		"${PERL}" | fmt -w 78
	# if we use 2, this package gets marked as "partially installed",
	# which forces the user to say they want to install the dependent
	# package SUNWcestx anyway, in spite of the installation status of
	# this package (SUNWcest).  Let the warning message suffice.
	exit 0
fi

VER=`${PERL} -v | grep "^This is perl" | sed -e 's/^[A-Za-z,	 ]*//' | \
	awk '{print $1}' | awk -F. '{print $1}'`

if  [ "${VER}" -lt "5" ]
then
	printf "`gettext \
		'\nWARNING: cediag(1M) is not supported on this version of Perl.  Perl 5 or later is required to run cediag(1M).'" | fmt -w 78
	# if we use 2, this package gets marked as "partially installed",
	# which forces the user to say they want to install the dependent
	# package SUNWcestx anyway, in spite of the installation status of
	# this package (SUNWcest).  Let the warning message suffice.
	exit 0
fi

printf "`gettext \
	'\n\nREMINDER: Be sure to run cediag(1M) manually after installation as it\ncannot be run by automated tools such as cron(1M) and explorer until\nthe license for cediag(1M) has been accepted.'`\n\n"

case "${SUNWcest_CRONTAB}" in
y*|Y*)	crontab -l | sed -e "/.*# SUNWcest$/d" > /tmp/crontab.$$
	crontab /tmp/crontab.$$
	echo "0 0 * * * /opt/SUNWcest/bin/cediag -L >/dev/null  # SUNWcest" >> /tmp/crontab.$$
	crontab /tmp/crontab.$$
	rm -f /tmp/crontab.$$
	;;
esac

exit 0 # successful checkinstall run
