#!/bin/sh

# For RTI 4711800
# Create symbolic link
# Install symlink only on Solaris 9
#  ln -s /usr/cluster/lib/sparcv9/libH.so.5 /usr/cluster/lib/sparcv9/libC.so.5
# only on Solaris 9 and if /usr/cluster/lib/sparcv9/libH.so.5 exists
# and if the SUNWscorx package is installed.
#  

#------------------------------------
# This function will add the indicated symlink which belongs to the
# indicated package to the system and the contents file.
# It will create the files' parent directory if necessary
# and add it to the contents file.
#
#    add_link <MY_PKGNAME> <SYMLINK> <LINK_TARGET>
#------------------------------------
add_link()
{
   MY_PKGNAME=$1
   ADD_LINK=$2
   ADD_LINK_TARGET=$3

   if [ $ROOTDIR = "/" ]; then
      FS_ROOTDIR=""
      FS_LINK=${ADD_LINK}
   else 
      FS_ROOTDIR="${ROOTDIR}"
      FS_LINK=${ROOTDIR}${ADD_LINK}
   fi

   # If the link is already there, do nothing.
   if [ -h ${FS_LINK} ]; then
      return 0
   fi

   # See if we need to add the directory
   # We expect the directory to already be there but this code
   # is here to be complete and to associate the symlink with
   # our package in the contents database.
   LINK_DIR=`/bin/dirname ${ADD_LINK}`
   FS_DIR=${FS_ROOTDIR}$LINK_DIR

   /usr/sbin/installf -R $ROOTDIR $MY_PKGNAME $LINK_DIR d 0755 root bin
   if [ ! -d ${FS_DIR} ]; then
      mkdir ${FS_DIR}
      if [ $? -ne 0 ]; then
         echo "Could not create link directory ${FS_DIR}."
         return 1
      fi
      chown root ${FS_DIR}
      chgrp bin ${FS_DIR}
      chmod 0755 ${FS_DIR}
      echo "Created directory ${FS_DIR}"
   fi
   /usr/sbin/installf -f -R $ROOTDIR $MY_PKGNAME
   if [ $? -ne 0 ]; then
      return 1
   fi


   # NOTE: installf(1) will create the actual symlink for us.
   echo "Creating symlink ${FS_LINK}"
   /usr/sbin/installf -R $ROOTDIR $MY_PKGNAME ${ADD_LINK}=${ADD_LINK_TARGET} s
   /usr/sbin/installf -f -R $ROOTDIR $MY_PKGNAME
   if [ $? -ne 0 ]; then
      return 1
   fi
   
   return 0
}

###########################################
#
# Cleanup any temporary files on exit/interrupt
#
###########################################
cleanup()
{
	exit_code=$1

	if [ "${TMPFILES}" ]; then
		rm -f ${TMPFILES}
	fi

	exit ${exit_code}
}

##############################
# MAIN
##############################
trap 'echo "caught signal";  cleanup 3' 1 2 3 15

# Name of package
PKGINST=SUNWscorx
OS=`/bin/uname -r`

# Don't execute if the package is not installed or we're not on Solaris 9.
if [ -d /var/sadm/pkg/${PKGINST} -a "$OS" = "5.9" ]; then

   # If the target of the symlink is not there, exit. 
   if [ ! -f /usr/cluster/lib/sparcv9/libH.so.5 ]; then
      exit 0
   fi

   #-----------------------------
   # Add the required symlink.
   #-----------------------------
   add_link $PKGINST /usr/cluster/lib/sparcv9/libC.so.5 ./libH.so.5
   if [ $? -ne 0 ]; then
      exit 1
   fi 
   
fi

exit 0
