#! /usr/bin/sh
#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)preremove	1.3	09/06/15 SMI"
#

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

DRVR_NAME=iscsi
STOP_DELAY=5
# Disable the iSCSI initiator service

if [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" ]; then
	#
	# We can't safely disable the service in this case.
	#
	smf_alive=no
else
	#
	# We can verify if the service is disabled prior to
	# removal.
	#
	if [ -r /etc/svc/volatile/repository_door ]; then
		smf_alive=yes
	fi
fi

if [ "$smf_alive" = "yes" ]; then
	/usr/sbin/svcadm disable iscsi/initiator 2>/dev/null
	if [ $? -eq 0 ]; then
		#
		# Wait few seconds here
		#
		/usr/bin/sleep $STOP_DELAY
	fi
fi

# Remove the driver entries but leave it attached.
/usr/sbin/rem_drv -b ${BASEDIR} ${DRVR_NAME}

exit 0
