#!/bin/sh
# set -x
#
#       sunpcupdate:  sunpcupdate script.
#
#       @(#)sunpci      1.25    03/08/99
#
#       Copyright (c) 1998, Sun Microsystems, Inc.  All Rights Reserved
#       Sun considers its source code as an unpublished, proprietary
#       trade secret, and it is available only under strict license
#       provisions.  This copyright notice is placed here only to protect
#       Sun in the event the source is deemed a published work.  Dissassembly,
#       decompilation, or other means of reducing the object code to human
#       readable form is prohibited by the license agreement under which
#       this code is provided to the user or company in possession of this
#       copy.
#
#       RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
#       Government is subject to restrictions as set forth in subparagraph
#       (c)(1)(ii) of the Rights in Technical Data and Computer Software
#       clause at DFARS 52.227-7013 and in similar clauses in the FAR and
#       NASA FAR Supplement.
#
# CDRom Mount Configuration file

CD="/etc/rmmount.conf"
CD_CHANGED=0

#Set the path

PATH=/bin:/usr/bin:/usr/ucb:/etc:/usr/etc

#-------------------------------------------------------
# Check that user 'root' has invoked sunpc_install.
#-------------------------------------------------------

ISROOT=`/bin/id | /bin/awk '/root/ {print}'`
if [ -z "$ISROOT" ]
then
	echo "You must be root to run this script."
	exit 1
fi
 
# Record the starting point so we can return after determining $SUNPC2HOME.
INITIAL_DIR=`pwd`

#       If sunpc is invoked from a symbolic link, find out where it points to and use
#       the pointer to determine the distribution location. This works for one level of
#       symlink only.
IF_LINK=`/bin/ls -l "$0" | /bin/grep "lrwxrwxrwx"`
if [ -n "$IF_LINK" ]
then
        LINK_PATH=`/usr/bin/echo ${IF_LINK} | /bin/awk '{ printf "%s", $NF }'`
else
        LINK_PATH=$0
fi
 
#       Find out where this script lives, and determine $SUNPCIIHOME.
FROM_PATH=`/usr/bin/echo "$LINK_PATH" | /bin/grep "/"`
 
 
if [ -n "$FROM_PATH" ]
then
        #in this case $0 is a directory component.
        FIRSTARG=`/usr/bin/echo ${FROM_PATH} | /bin/awk -F/ '{ print $1 }'`
          
        if [ -z "$FIRSTARG" ]; then
                SOURCE3=`/usr/bin/echo ${LINK_PATH} | /bin/awk -F/ '{ for (i = 1; i < NF; i++)  { printf "%s", $i; printf "/" } }'`
        else
                SOURCE3=`/usr/bin/echo ${LINK_PATH} | /bin/awk -F/ '{ if ($1 == "") printf "/"; for (i = 1; i < NF; i++)  { printf "%s", $i; printf "/" } }'`
        fi
else
        #in this case $0 is not a directory component.
        SOURCE3="./"
fi        
 

#Copy the shared library
#
#  I don't know where this has to be done .it could be done here or
# in some other pre_install script
 
cd $SOURCE3
cp -p ../lib/action_sunpci.so.* /usr/lib/rmmount/.


# Load the new driver
# there must be a better way

cd ../drivers/solaris
./sunpcload
cd ../../bin


 
# Neeraj wrote this and I'm just using it
# modify the /etc/rmmount.conf to support sunpci cdrom
if [ -f ${CD} ]
then
    if [ ! -f ${CD}.beforesunpc ]
    then
        cp -p ${CD} ${CD}.beforesunpc
        egrep -e "^action cdrom" ${CD} >/dev/null 2>&1
        if [ $? -ne 0 ]
        then
                ${ECHO} "Volume manager is not managing the CDROM"
        else
                cat ${CD} | sed 's/^action cdrom action_filemgr.so/action cdrom action_sunpci.so \
action cdrom action_filemgr.so /' > ${CD}.temp1
 
                rm -f ${CD}
                mv ${CD}.temp1 ${CD}
        fi
    fi
fi
cd $INITIAL_DIR


