# $Id: samfs_prebackout,v 1.3 2002/12/03 16:38:51 hm129959 Exp $
err_code=1

#	Check for mounted samfs file systems.

/usr/sbin/mount -p | /usr/bin/awk '{print $4}' | /usr/bin/grep samfs > /dev/null
if [ $? = 0 ]; then
	echo " "
	echo "--> Before removing this package, you must unmount each"
	echo "--> SAM-FS filesystem and kill the sam-init process."
	echo " "
	exit 1
fi

echo " "

STAT=0


sed "/sf:23:respawn/d" /etc/inittab > /etc/inittab.tmp
if [ $? = 0 ]; then
	mv /etc/inittab.tmp /etc/inittab
	chmod 644 /etc/inittab
fi

chmod -x /usr/lib/fs/samfs/sam-fsd
FSDPID=`/bin/ps -e | /usr/bin/grep sam-fsd | /usr/bin/grep -v grep | /usr/bin/cut -c1-6`
if [ -n "$FSDPID" ]; then
	kill -TERM $FSDPID
fi

#
#       The samsys module is automatically unloaded when samfs unloads.
#
for SAMTYPE in samst samrd samfs
do
	modid=`/usr/sbin/modinfo | /usr/bin/grep $SAMTYPE | head -1 | cut -c0-4`
	if [ "$modid" -ne "" ] ; then
		echo "... unloading $SAMTYPE - module $modid"
		/usr/sbin/modunload -i $modid  ||  {
    		sleep 2
			echo "... unloading $SAMTYPE - module $modid (2nd attempt)"
			/usr/sbin/modunload -i $modid  ||  {
				sleep 2
				echo "... unloading $SAMTYPE - module $modid (3rd attempt)"
				/usr/sbin/modunload -i $modid  ||  {
					echo "    module $modid - $SAMTYPE" 
					echo " "
					STAT=1
				}
			}
		}
	fi
done
echo " "

ETCDIR=/etc/opt/SUNWsamfs
DATE=`/usr/bin/date +%m%d%y-%H%M`

if [ -f /etc/opt/SUNWsamfs/SamGUI.rsc ] ; then
      /bin/cp /etc/opt/SUNWsamfs/SamGUI.rsc /etc/opt/SUNWsamfs/SamGUI.rsc.${DATE}
fi
if [ ! -d /opt/SUNWsamfs/jre ]; then
	/bin/rm /opt/SUNWsamfs/jre
fi

if [ -f $ETCDIR/inquiry.conf ] ; then
#   if nothing in examples or installed copy differs, make a backup.
#   filter out the RCS id line.
	BACKUP=1
	if [ -f /opt/SUNWsamfs/examples/inquiry.conf ]; then
	  /bin/grep -v 'Id:' ${ETCDIR}/inquiry.conf > /tmp/$$.in1
	  /bin/grep -v 'Id:' /opt/SUNWsamfs/examples/inquiry.conf > /tmp/$$.in2
	  /bin/diff /tmp/$$.in1 /tmp/$$.in2 > /dev/null
	  BACKUP=$?
	  /bin/rm   /tmp/$$.in1 /tmp/$$.in2
	fi
	if [ "$BACKUP" != 0 ]; then
		/bin/cp ${ETCDIR}/inquiry.conf ${ETCDIR}/inquiry.conf.${DATE}
		echo "inquiry.conf backed up to ${ETCDIR}/inquiry.conf.${DATE}"
	fi
fi

if [ -f /kernel/drv/samst.conf ] ; then
#   if nothing in examples or installed copy differs, make a backup.
#   filter out the RCS id line.
	BACKUP=1
	if [ -f /opt/SUNWsamfs/examples/samst.conf ]; then
	  /bin/grep -v 'Id:' /kernel/drv/samst.conf > /tmp/$$.in1
	  /bin/grep -v 'Id:' /opt/SUNWsamfs/examples/samst.conf > /tmp/$$.in2
	  /bin/diff /tmp/$$.in1 /tmp/$$.in2 > /dev/null
	  BACKUP=$?
	  /bin/rm   /tmp/$$.in1 /tmp/$$.in2
	fi
	if [ "$BACKUP" != 0 ]; then
		/bin/cp /kernel/drv/samst.conf /kernel/drv/samst.conf.${DATE}
		echo "samst.conf backed up to /kernel/drv/samst.conf.${DATE}"
	fi
fi

if [ "$STAT" != 0 ] ; then
	echo " "
	echo "--> Before removing this package, you must unmount each"
	echo "--> SAM-FS filesystem and kill the sam-init process."
	echo " "
	exit 1
fi

#
#     Save the administrator group
#
/bin/ls -l /opt/SUNWsamfs/sbin/chmed | /bin/awk '{ print $4 }' > /opt/SUNWsamfs/.admingrp

/bin/rm -f /opt/SUNWsamfs/man/windex
