#!/usr/bin/qsh
# // 5639-D57, 5630-A36, 5630-A37, 5724-D18 (C) COPYRIGHT International Business Machines Corp. 1997, 2005
# // The source code for this program is not published or otherwise divested
# // of its trade secrets, irrespective of what has been deposited with the
# // U.S. Copyright Office.
#
#############################################################################################
# This script is inovked by the configuration manager during the
# config action phase of the product install.
# The purpose of the script is to determine the canonical path of
# for the path passed in. The canonical path is the path as it was created which includes
# case. 
#############################################################################################

if [ $# -ne 1 ]; then
  echo "Error: Missing required parameter"
  echo "Usage: _getCanonicalPath path"
  exit 0;
fi

# Keep current dir so we can switch back to it when done
CUR_DIR=`pwd`

# Working variables
PATH_VALUE=$1
PATH_NON_EXIST=
PATH_EXIST=${PATH_VALUE}
SLASH=

# Separate out any non-existent portion of the path from any existing portion
while [ ! -e ${PATH_EXIST} ]; do
  PATH_NON_EXIST=`/usr/bin/basename ${PATH_EXIST}`${SLASH}${PATH_NON_EXIST}
  PATH_EXIST=`/usr/bin/dirname ${PATH_EXIST}`
  SLASH="/"
done

# Change dir to existing portion and use pwdx to get canonical (case correct) path
cd ${PATH_EXIST}
CANONICAL_PORTION=`pwdx`
if [ ${CANONICAL_PORTION} = "/" ]; then
  SLASH=
fi
FULL_CANONICAL_PATH=${CANONICAL_PORTION}${SLASH}${PATH_NON_EXIST}

cd ${CUR_DIR}

# Our return value
echo ${FULL_CANONICAL_PATH}