# $Id: samfs_postpatch,v 1.3 2002/12/03 16:38:51 hm129959 Exp $
INSLOG=/tmp/SAM_install.log
ETCDIR=/etc/opt/SUNWsamfs
VARDIR=/var/opt/SUNWsamfs
LAST_DIR=/etc/opt/SUNWsamfs/samfs.old.last
NEW_EXE=/opt/SUNWsamfs/sbin
LIB=/opt/SUNWsamfs/lib/libsamconf.so
LIB64=/opt/SUNWsamfs/lib/sparcv9/libsamconf.so
MUST_REBOOT=0

/bin/rm -f $INSLOG

#  main script.

if [ ! -f /kernel/drv/samst.conf ]; then
	/bin/cp /opt/SUNWsamfs/examples/samst.conf /kernel/drv/samst.conf
else
	/bin/grep -v 'Id:' /opt/SUNWsamfs/examples/samst.conf > /tmp/$$.in1
	/bin/grep -v 'Id:' /kernel/drv/samst.conf > /tmp/$$.in2
	/bin/diff /tmp/$$.in1 /tmp/$$.in2 > /dev/null
	if [ $? -ne 0 ]; then
		echo "samst.conf has been updated.  /opt/SUNWsamfs/examples/samst.conf "
		echo "is the latest version; please add your changes and copy it  "
		echo "to /kernel/drv/samst.conf "
		echo "When you have done this you may need to run "
		if [ -f /opt/SUNWsamfs/sbin/samdev ]; then
			echo "/usr/sbin/add_drv samst    and"
			echo "/opt/SUNWsamfs/sbin/samdev again."
		else
			echo "/usr/sbin/devfsadm -i samst"
			echo "again."
		fi
		echo " "
	fi
	/bin/rm   /tmp/$$.in1 /tmp/$$.in2
fi

if [ ! -f $ETCDIR/inquiry.conf ]; then
	/bin/cp /opt/SUNWsamfs/examples/inquiry.conf $ETCDIR/inquiry.conf
else
	/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
	if [ $? -ne 0 ]; then
		echo "inquiry.conf has been updated. /opt/SUNWsamfs/examples/inquiry.conf"
		echo "is the latest version; please add your changes and copy this file"
		echo "to $ETCDIR/inquiry.conf "
		echo " "
	fi
	/bin/rm   /tmp/$$.in1 /tmp/$$.in2
fi

if [ ! -f /opt/SUNWsamfs/sbin/archiver.sh ]; then
	 /bin/cp /opt/SUNWsamfs/examples/archiver.sh /opt/SUNWsamfs/sbin/archiver.sh
fi
if [ ! -f /opt/SUNWsamfs/sbin/recycler.sh ]; then
	 /bin/cp /opt/SUNWsamfs/examples/recycler.sh /opt/SUNWsamfs/sbin/recycler.sh
fi

if [ ! -p /etc/opt/SUNWsamfs/samlogd_fifo ]; then
	 /usr/bin/mkfifo -m660 /etc/opt/SUNWsamfs/samlogd_fifo
fi

/bin/catman -w -M /opt/SUNWsamfs/man

/bin/sync

# Add samst driver.

echo "# Configuring devices.  Please wait, this may take a while."
/bin/sync
/usr/sbin/add_drv samst >> $INSLOG 2>&1
if [ $? -eq 1 ]; then
    echo "add_drv returned an error.  This can occur if there are no tape or"
    echo "optical devices connected to the system or the driver is already  "
    echo "installed.  See $INSLOG for the additional messages. "
    echo " "
fi

# Add samrd driver.

if [ ! -f /etc/devlink.tab ]; then
	echo "The /etc/devlink.tab file is missing" >> $INSLOG
	echo "The /etc/devlink.tab file is missing.  This Solaris system  "
	echo "file is required for SAM-Remote to operate.  Please ensure  "
	echo "the file is installed, then reinstall the SUNWsamfs package."
	exit 1
fi

# NOTE:  the line echoed to devlink.tab contains a TAB character, not a space.

/usr/bin/grep 'name=samrd' /etc/devlink.tab >/dev/null 2>&1  ||  {
	echo "Updating /etc/devlink.tab file" >> $INSLOG
	echo "type=ddi_pseudo;name=samrd	samrd/rd\M1" >> /etc/devlink.tab || {
		echo "Unable to update the /etc/devlink.tab file.   " >> $INSLOG
		echo "Unable to update the /etc/devlink.tab file.   "
		echo "Please ensure you are running as 'root', then "
		echo "reinstall the SUNWsamfs package.               "
		echo " "
		exit 2
	}
}

if [ -c /devices/pseudo/samrd@0:0,raw ]; then
	echo "Removing device driver samrd"
	echo "Removing device driver samrd" >> $INSLOG
	/usr/sbin/rem_drv samrd >> $INSLOG 2>&1
fi

echo "Adding device driver samrd"
echo "Adding device driver samrd" >> $INSLOG
/usr/sbin/add_drv samrd >> $INSLOG 2>&1
STAT=$?
if [ $STAT -eq 1 ]; then
	echo "add_drv returned an error.  " >> $INSLOG
	echo "add_drv returned an error.  This can occur if there     "
	echo "are no tape or optical devices connected to the system. "
	echo "See $INSLOG for additional messages.                    "
	echo "                                                        "
fi

/bin/sync ; /bin/sleep 4

#  Set up for STK network attached library

if [ ! -f /etc/opt/SUNWsamfs/ssi.sh ]; then
	/bin/cp /opt/SUNWsamfs/examples/ssi.sh /etc/opt/SUNWsamfs/ssi.sh
else
	/bin/grep -v 'Id:' /opt/SUNWsamfs/examples/ssi.sh > /tmp/$$.si1
	/bin/grep -v 'Id:' /etc/opt/SUNWsamfs/ssi.sh > /tmp/$$.si2
	/bin/diff /tmp/$$.si1 /tmp/$$.si2 > /dev/null
	if [ $? -ne 0 ]; then
		echo "ssi.sh has been updated. /opt/SUNWsamfs/examples/ssi.sh " >>$INSLOG
		echo "is the latest version; please add your changes and "    >>$INSLOG
		echo "copy it to /etc/opt/SUNWsamfs/ssi.sh .  See the"         >>$INSLOG
		echo " ssi_so(7) man page for details."                       >>$INSLOG
		echo " "                                                      >>$INSLOG
	fi
	/bin/rm /tmp/$$.si1 /tmp/$$.si2
fi
/usr/bin/chown root:sys /etc/opt/SUNWsamfs/ssi.sh
/usr/bin/chmod 0750     /etc/opt/SUNWsamfs/ssi.sh

#  Build samst devices

if [ ! -f /opt/SUNWsamfs/sbin/samdev ]; then
	echo "Issuing /usr/sbin/devfsadm -i samst >> $INSLOG 2>&1"
	/usr/sbin/devfsadm -i samst >> $INSLOG 2>&1
else
	echo "Issuing /opt/SUNWsamfs/sbin/samdev  >> $INSLOG 2>&1"
	/opt/SUNWsamfs/sbin/samdev >> $INSLOG 2>&1
fi

/bin/chmod 0750 /usr/lib/fs/samfs/sam-fsd

#
#    Reset the administrator group to the previous value.
#
if [ -s /opt/SUNWsamfs/.admingrp ] ; then
	ADMINGRP=`/bin/cat /opt/SUNWsamfs/.admingrp`
	if [ $ADMINGRP != "bin" ] ; then
		/opt/SUNWsamfs/sbin/set_admin.sh $ADMINGRP
	fi
fi

exit 0
