#!/bin/bash
MY_PATH=$(dirname $(readlink -f $0))
BASE_PATH=$(readlink -f $MY_PATH/../../..)
GLOBAL_GETVERSIONS="/opt/454/bin/getVersions"
TOOL_LIST=( sffinfo newbler )
global=no

# Check if we're installed in the default location.
COMPONENT=`echo "${MY_PATH}" | /bin/grep -E '/opt/454/apps/[a-zA-Z]*/libexec' 2>/dev/null | sed -e 's:^/opt/454/apps/\([a-zA-Z]*\)/libexec/*:\1:' 2>/dev/null`

# Check to see if we should call the global copy of getVersions.
if [ -n "$COMPONENT" ] ; then
   if [ -z "$1" ] ; then
      if [ -x "$GLOBAL_GETVERSIONS" ] ; then
         global=yes
      fi
   fi
else
   # Try to get the component name from the parent directory.
   COMPONENT=`echo "${MY_PATH}" | /bin/grep -E '^.*/[a-zA-Z]*/libexec/*' | sed -e 's:^.*/\([a-zA-Z]*\)/libexec/*:\1:' 2>/dev/null`
   
   # Default to "release" if we are not installed correctly.
   if [ -z "$COMPONENT" ] ; then
      COMPONENT="release"
   fi
fi

# Display the version info or call the global copy.
if [ $global == yes ] ; then
   eval $GLOBAL_GETVERSIONS
else
   echo "AppJava [$COMPONENT] 2.6 (v20110523_1440)"
   echo "AppCRelease [$COMPONENT] 2.6 (v20110517_1502)"
   echo "LinuxSupportFiles [$COMPONENT] 2.6 (v20101119_1743)"
   
   for tool in "${TOOL_LIST[@]}"
   do
      VERSION=`"${BASE_PATH}/bin/${tool}" --version 2>/dev/null | grep ${tool}`
      [ -n "$VERSION" ] && echo "$VERSION" | sed -e 's/\([a-z]*\)[^0-9]*/\1 ['$COMPONENT'] /'
   done
fi
