#!/bin/sh
#
#ident "@(#)postinstall   1.11     99/09/30 SMI"
#
# Copyright (c) 1994,1999 by Sun Microsystems, Inc.
#

myname=`basename $0`
#echo "begin with the $myname script"
eval=0

OLD_PATCHES="101231 101929 103926 102580 104172 104173 104275"

#
# Clear out old DiskSuite patches
#
clear_old_patches() {
	if [ -d /var/sadm/patch ]; then
		cd /var/sadm/patch
	else
		return
	fi

	for patch in $OLD_PATCHES; do
		rm -rf ${patch}-??
	done
}

#
# set error part of exit value
#
seterr() {
	err=`expr "$eval" % 10`
	reb=`expr "$eval" - "$err"`
	if [ "$1" -gt "$err" ]; then
		eval=`expr "$reb" + "$1"`
	fi
}

#
# set reboot part of exit value
#
setreb() {
	err=`expr "$eval" % 10`
	reb=`expr "$eval" - "$err"`
	if [ "$1" -gt "$reb" ]; then
		eval=`expr "$1" + "$err"`
	fi
}

#
# set error part of exit value and exit
#
errout() {
	seterr $1
	#echo "done with the $myname script, exiting with $eval"
	exit $eval
}

#
# set reboot part of exit value and exit
#
rebout() {
	setreb $1
	errout 0
}

#
# catch common signals
#
trap 'echo "$myname: caught signal"; errout 3' 1 2 3

#
# error and warning messages for application registration failures
#

pf_err='WARNING: Failed to register application "%s" with solstice launcher'
pf_lck=', solstice registry file is locked'
pf_dup=', the name "%s" is already registered and must be deleted first'
pf_nl='.\n'

warn_pfx='ERROR: DiskSuite Tool was not registered with solstice launcher,'
addapp_warn=' /usr/snadm/bin/soladdapp command not found'
addapp_x_warn=' /usr/snadm/bin/soladdapp command is not executable'

#
# function for error reporting
#

report_if_add_error ()
{
	case $1 in
		0)	;;
		2)
			/usr/bin/printf "$pf_err" "$2"
			/usr/bin/printf "$pf_lck"
			/usr/bin/printf "$pf_nl" ;;
		3)
			/usr/bin/printf "$pf_err" "$2"
			/usr/bin/printf "$pf_dup" "$2"
			/usr/bin/printf "$pf_nl" ;;
		*)
			/usr/bin/printf "$pf_err" "$2"
			/usr/bin/printf "$pf_nl" ;;
	esac
}

#
# Try and register applications with the "solstice" application palette
# If its not there..dont worry. Its not on our dependency list.

if [ -x ${PKG_INSTALL_ROOT}/usr/snadm/bin/soladdapp ] ; then

	# Unregister any old app before trying to register the new app.
	# Ignore any errors.

	${PKG_INSTALL_ROOT}/usr/snadm/bin/soldelapp \
		-r ${PKG_INSTALL_ROOT}/etc/.solstice_registry \
		-n "DiskSuite Tool" \
		1>/dev/null 2>&1

	# Start registering apps.

	${PKG_INSTALL_ROOT}/usr/snadm/bin/soladdapp \
		-r ${PKG_INSTALL_ROOT}/etc/.solstice_registry \
		-n "DiskSuite Tool" \
		-i /usr/lib/lvm/X11/bitmaps/SDStool.xpm \
		-e /usr/sbin/metatool 1>/dev/null 2>&1
	
	report_if_add_error $? "DiskSuite Tool"
fi

 

if [ "$IS_AN_UPGRADE" = "true" ]; then
	clear_old_patches
	sh $UPGR_SCRIPT &
	# Give the script a chance to queue onto the package database lock
	sleep 3
fi

errout 0
