#! /bin/sh
#
# $Id: drvrpoin.sh,v 1.3.32.2.16.6 2005/05/11 18:00:24 caude Exp $ Copyright (c) 2005, LEGATO Software, a division of EMC.
#

#
# Copyright (c) 2005 LEGATO Software, a division of EMC.
#
# All rights reserved.  This is an UNPUBLISHED work, and
# comprises proprietary and confidential information of LEGATO.
# Unauthorized use, disclosure, and distribution are strictly
# prohibited.  Use, duplication, or disclosure of the software
# and documentation by the U.S. Government is subject to
# restrictions set forth in a license agreement between the
# Government and LEGATO or other written agreement specifying
# the Government's rights to use the software and any applicable
# FAR provisions, such as FAR 52.227-19.
#

#==============================================================================
# Function:	total_confusion
# Summary:	install the correct lus driver and libscsi
# Details:
# With nsr_tape we have we have no way to intelligently package the correct lus
# driver and libscsi. Instead we package every version we build, then fix it
# with the LGTOdrvr postinstall script. The following is a brief description of
# what gets installed:
#
#	/usr/kernel/drv/lus - 32-bit lus driver built on Solaris 2.5.1
#	/usr/kernel/drv/lus32 - 32-bit driver built on Solaris 7
#	/usr/kernel/drv/sparcv9/lus - 64-bit driver built on Solaris 7
#	/usr/lib/nsr/libscsi.so.1 - 32-bit library built on Solaris 2.5.1
#	/usr/lib/nsr/libscsi27.so.1 - 32-bit library built on Solaris 7
#
# and what we do here on each version of Solaris:
#
#	Solaris 2.5.1, 2.6 - do nothing, works as-is
#	Solaris 7+ - replace lus and libscsi, with lus32 and libscsi27
#	Solaris 10+ - remove lus since it's unused
#==============================================================================
total_confusion()
{
if [ `uname -r | cut -f 2 -d '.'` -ge 7 ]; then
	mv -f $PKG_INSTALL_ROOT/usr/kernel/drv/lus32 \
		$PKG_INSTALL_ROOT/usr/kernel/drv/lus
	removef $PKGINST /usr/kernel/drv/lus > /dev/null
	removef $PKGINST /usr/kernel/drv/lus32 > /dev/null
	installf $PKGINST /usr/kernel/drv/lus f

	# This could be simplified since we do not use the 64-bit
	# libscsi anymore because of LGTpa56833 & LGTpa58366.
	if [ $PKGINST = LGTOdrvr ]; then
		INQUIRE=$CLIENT_PKG_INSTALL_ROOT/usr/sbin/inquire
	else
		INQUIRE=$CLIENT_PKG_INSTALL_ROOT/usr/sbin/nsr/inquire
	fi
	BINMODE=`file $INQUIRE | awk '{print $3}'`
	if [ ${BINMODE} = "32-bit" ]; then
		mv -f $PKG_INSTALL_ROOT/usr/lib/nsr/libscsi27.so.1 \
			$PKG_INSTALL_ROOT/usr/lib/nsr/libscsi.so.1
		removef $PKGINST /usr/lib/nsr/libscsi.so.1 > /dev/null
		removef $PKGINST /usr/lib/nsr/libscsi27.so.1 > /dev/null
		installf $PKGINST /usr/lib/nsr/libscsi.so.1 f
	else
		rm -f $PKG_INSTALL_ROOT/usr/lib/nsr/libscsi27.so.1
		removef $PKGINST /usr/lib/nsr/libscsi27.so.1 > /dev/null
	fi

	removef -f $PKGINST
	installf -f $PKGINST
fi

if [ `uname -r | cut -f 2 -d '.'` -ge 10 ]; then
	rm -f $PKG_INSTALL_ROOT/usr/kernel/drv/lus
	rm -f $PKG_INSTALL_ROOT/usr/kernel/drv/lus.conf
	rm -f $PKG_INSTALL_ROOT/usr/kernel/drv/sparcv9/lus
	removef $PKGINST $PKG_INSTALL_ROOT/usr/kernel/drv/lus > /dev/null
	removef $PKGINST $PKG_INSTALL_ROOT/usr/kernel/drv/lus.conf > /dev/null
	removef $PKGINST $PKG_INSTALL_ROOT/usr/kernel/drv/sparcv9/lus > /dev/null
fi
}

#==============================================================================
# Function:	add_devlink
# Summary:	add entries to /etc/devlink.tab
#==============================================================================
add_devlink()
{
file=${PKG_INSTALL_ROOT}/etc/devlink.tab
echo "Adding entries to ${file}"

# clean up any previous entries in /etc/devlink.tab
sedcmd1="/^#Legato Juke begin/,/^#Legato Juke end/d"
sedcmd2="/^#Legato uscsi begin/,/^#Legato uscsi end/d"
sedcmd3="/^#Legato Optical begin/,/^#Legato Optical end/d"
sed -e "${sedcmd1}" -e "${sedcmd2}" -e "${sedcmd3}" ${file} > ${file}.tmp.$$
if [ $? -eq 0 ]; then
	mv ${file}.tmp.$$ ${file}
else
	echo "cleanup of ${file} failed"
	exit 2
fi

# add entries to /etc/devlink.tab
echo "#Legato uscsi begin - added by ${PKGINST} - do not EDIT" >> ${file}
if [ `uname -r | cut -f 2 -d '.'` -lt 10 ]; then
	# lus driver only supported on Solaris 9 and below
	echo "type=ddi_pseudo;name=lus;minor=0	lus" >> ${file}
fi
echo "type=ddi_pseudo;name=op	optical\N0" >> ${file}
echo "#Legato uscsi end - added by ${PKGINST} - do not EDIT" >> ${file}
}

#==============================================================================
# Function:	add_sgen
# Summary:	add entries to /kernel/drv/sgen.conf
#==============================================================================
add_sgen()
{
file=${PKG_INSTALL_ROOT}/kernel/drv/sgen.conf
list=device-type-config-list
types='"direct", "sequential", "worm", "rodirect", "optical", "changer"'
echo "Adding entries to ${file}"

echo "#begin - added by ${PKGINST} - do not EDIT" >> ${file}
echo "${list}=${types};" >> ${file}
for t in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
  for l in 0 1 2 3 4 5 6; do
    echo "name=\"sgen\" class=\"scsi\" target=${t} lun=${l};" >> ${file}
  done
done
echo "#end - added by ${PKGINST} - do not EDIT" >> ${file}
}

#==============================================================================
# Function:	load_drivers
# Summary:	load the lus and op drivers
#==============================================================================
load_drivers()
{
if [ "X${PKG_INSTALL_ROOT}" = "/a" ]; then
	touch ${PKG_INSTALL_ROOT}/reconfigure
	fmt<<-!
	Due to package relocation, the lus and optical drivers can not be
	dynamically loaded. The drivers will be configured automatically
	the next time the target system is rebooted.
	!
else
	if [ `uname -r | cut -f 2 -d '.'` -lt 10 ]; then
		# use lus driver on Solaris 9 and below
		add_drv -m '* 0666 bin bin' lus > /dev/null 2>&1
		if [ $? -eq 0 ]; then
			echo "lus driver configured and loaded"
		else
			echo "lus driver did not configure properly"
		fi
	else
		# use sgen driver on Solaris 10 and above
		modload -p drv/sgen
		if [ $? -eq 0 ]; then
			echo "sgen driver configured and loaded"
		else
			echo "sgen driver did not configure properly"
		fi
	fi
	add_drv -n -m '* 0600 bin bin' op > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		echo "optical driver configured and loaded"
	else
		echo "optical driver did not configure properly"
	fi
fi
}

#==============================================================================
# Function:	driver_postinstall
# Summary:	called by postinstall.sh
#==============================================================================
driver_postinstall()
{
total_confusion
add_devlink
if [ `uname -r | cut -f 2 -d '.'` -ge 10 ]; then
	add_sgen
fi
load_drivers
}
#! /bin/sh
#
# $Id: drvrprrm.sh,v 1.1.42.5 2006/02/17 19:29:47 slattc Exp $ Copyright (c) 2005, LEGATO Software, a division of EMC.
#

#
# Copyright (c) 2005 LEGATO Software, a division of EMC.
#
# All rights reserved.  This is an UNPUBLISHED work, and
# comprises proprietary and confidential information of LEGATO.
# Unauthorized use, disclosure, and distribution are strictly
# prohibited.  Use, duplication, or disclosure of the software
# and documentation by the U.S. Government is subject to
# restrictions set forth in a license agreement between the
# Government and LEGATO or other written agreement specifying
# the Government's rights to use the software and any applicable
# FAR provisions, such as FAR 52.227-19.
#

#==============================================================================
# Function:     unload_drivers
# Summary:      unload the lus and op drivers so they can be removed
#==============================================================================
unload_drivers()
{
modinfo | grep lus > /dev/null 2>&1
if [ $? -eq 0 ]; then
	# unload lus driver if it is loaded
	rem_drv lus > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		echo "lus driver unloaded"
	else
		echo "lus driver did not unload properly"
		exit 2
	fi
fi
modinfo | grep sgen > /dev/null 2>&1
if [ $? -eq 0 -a `uname -r | cut -f 2 -d '.'` -ge 10 ]; then
	# unload sgen driver on Solaris 10 and above if it is loaded
	ID=`modinfo | grep sgen | awk '{print $1}'`
	if [ -n "$ID" ]; then
		modunload -i $ID
		if [ $? -eq 0 ]; then
			echo "sgen driver unloaded"
		else
			echo "sgen driver did not unload properly"
			exit 2
		fi
	fi
fi
modinfo | grep op > /dev/null 2>&1
if [ $? -eq 0 ]; then
	# unload op driver if it is loaded
	rem_drv op > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		echo "optical driver unloaded"
	else
		echo "optical driver did not unload properly"
		exit 2
	fi
fi
}

#==============================================================================
# Function:	del_devlink
# Summary:	remove entries from /etc/devlink.tab
#==============================================================================
del_devlink()
{
file=${PKG_INSTALL_ROOT}/etc/devlink.tab
echo "Removing entries from ${file}"

# remove entries from /etc/devlink.tab
sedcmd="/^#Legato uscsi begin/,/^#Legato uscsi end/d"
sed -e "${sedcmd}" ${file} > ${file}.tmp.$$
if [ $? -eq 0 ]; then
	mv ${file}.tmp.$$ ${file}
else
	echo "cleanup of ${file} failed"
	exit 2
fi
}

#==============================================================================
# Function:	del_sgen
# Summary:	remove entries from /kernel/drv/sgen.conf
#==============================================================================
del_sgen()
{
file=${PKG_INSTALL_ROOT}/kernel/drv/sgen.conf
echo "Removing entries from ${file}"

# remove entries from /etc/devlink.tab
sedcmd="/^#begin - added by ${PKGINST}/,/^#end - added by ${PKGINST}/d"
sed -e "${sedcmd}" ${file} > ${file}.tmp.$$
if [ $? -eq 0 ]; then
	mv ${file}.tmp.$$ ${file}
else
	echo "cleanup of ${file} failed"
	exit 2
fi
}

#==============================================================================
# Function:     driver_preremove
# Summary:	called by preremove.sh
#==============================================================================
driver_preremove()
{
unload_drivers
del_devlink
if [ `uname -r | cut -f 2 -d '.'` -ge 10 ]; then
	del_sgen
fi
}
#! /bin/sh
#
# $Id: sunpatch.sh,v 6.5.18.5.16.3 2005/08/04 19:14:49 caude Exp $ Copyright (c) 2001-2005 EMC Corporation
#

#
# Copyright (c) 2001-2005 EMC Corporation.
#
# All rights reserved.  This is an UNPUBLISHED work, and
# comprises proprietary and confidential information of EMC.
# Unauthorized use, disclosure, and distribution are strictly
# prohibited.  Use, duplication, or disclosure of the software
# and documentation by the U.S. Government is subject to
# restrictions set forth in a license agreement between the
# Government and EMC or other written agreement specifying
# the Government's rights to use the software and any applicable
# FAR provisions, such as FAR 52.227-19.
#

## This is the pre/post-patch and pre/post-backout script. The case
## statement at the end decides what to do based on the value of $0.

## I've stripped all the duplicate code from here and we now make use of the
## existing functions in the driver package postinstall and preremove scripts.

client_postinstall()
{
if [ -f /usr/bin/nsr/nsrfile ]; then
	rm -f /usr/bin/nsr/nsrfile
	removef SUNWebsc /usr/bin/nsr/nsrfile
	removef -f SUNWebsc
fi
}

driver_postpatch()
{
PKGINST=SUNWebsd
total_confusion
add_devlink
if [ `uname -r | cut -f 2 -d '.'` -ge 10 ]; then
	add_sgen
fi
unload_drivers
load_drivers
}

driver_postbackout()
{
PKGINST=SUNWebsd
if [ `uname -r | cut -f 2 -d '.'` -ge 10 ]; then
	del_sgen
fi
unload_drivers
load_drivers
}

start()
{
if [ -x /etc/init.d/networker ]; then
    ( cd / ; /etc/init.d/networker start )
else
    echo "You should now restart the Sun StorEdge(TM) Enterprise Backup daemons."
fi
}

stop()
{
nsr_procs=`/bin/ps -ef | egrep 'ansrd|nsrd|nsrindex|nsrindxd|nsrmmd|nsrmmdbd|nsrexecd|nsrib|nsriba' | grep -v egrep`

if [ "X$nsr_procs" != "X" ]; then
    if [ -x /usr/sbin/nsr/nsr_shutdown ]; then
	/usr/sbin/nsr/nsr_shutdown -a -q
    else
        echo "It appears that there are Sun StorEdge(TM) Enterprise Backup daemons running."
        echo "Please run 'nsr_shutdown -a' before proceeding."
	exit 1
    fi
fi
}

## main
case "`basename $0`" in
prepatch)	stop
		;;
postpatch)	pkginfo -q SUNWebsc && client_postinstall
		pkginfo -q SUNWebsd && driver_postpatch
		start
		;;
prebackout)	stop
		;;
postbackout)	pkginfo -q SUNWebsd && driver_postbackout
		start
		;;
esac
exit 0
