#!/bin/sh
#
#-------------------------------------------------------------------
# PROPRIETARY-STATEMENT:
# Licensed Material - Property of IBM
#
# 5724-I63, 5724-H88, 5655-N01, 5733-W61
# (C) Copyright IBM Corp. 1999, 2008
# All Rights Reserved
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
# Input parameters: 
# $1 - SMPE INSTALL ROOT
# $2 - INTERMEDIATE SYMBOLIC LINK NAME
#-------------------------------------------------------------------
<!-- import documents/data/buildInfo.script -->
#-------------------------------------------------------------------
<!-- Change Activity                                              -->
<!--  534171 H28W700 20070119 DMB  Initial drop                   -->

installRoot=$1
symlinkName=$2


# First check to see if the file exists
if [ -e $symlinkName ]; then

   # If its symbolic link... 
   if [ -h $symlinkName ]; then  

      # Get the name of the target of the symbolic link
      targetName=`ls -l $symlinkName | awk '{print $11}'`
      rc=$?
      if [ $rc -ne 0 ]; then
        echo "ERROR: rc=$rc while obtaining target of specified symbolic link $symlinkName"
        exit 8 
      fi

      # Symlink either already points to the install root or it doesn't 
      if [ $targetName = $installRoot ]; then
         echo "The specified intermediate symbolic link ($symlinkName) already exists with a target of the specified install directory ($installRoot)" 
         exit 0
      else
         echo "ERROR"
         echo " "
         echo "The specified symbolic link ($symlinkName) already exists with a target of $targetName"
         echo "If $symlinkName can be safely deleted, delete it, and rerun this job to create the symbolic link"
         echo "If $symlinkName can not be safely deleted, correct your customization definition to use a different symbolic link, and restart the customization process"
         exit 8 
      fi
   else 
      echo "ERROR"
      echo " "
      echo "A file or directory named $symlinkName already exists"
      echo "If $symlinkName can be safely deleted, delete it, and rerun this job to create the symbolic link"
      echo "If $symlinkName can not be safely deleted, correct your customization definition to use a different symbolic link, and restart the customization process"
      exit 8 
   fi
else
   ln -s $installRoot $symlinkName
   rc=$?
   if [ $rc -ne 0 ]; then
      echo "ERROR: rc=$rc received while attempting to create intermediate symbolic link $symlinkName" 
      exit 8 
   fi
fi