#!/bin/bash
#
# Oracle Education
# Create a library directory, and copy into it all the required jar files 
# used by Coherence REST
# Note that the bulk of the jar files are copied from COHERENCE_HOME
# However two are provided directly
#     * coherence-rest.jar - which has a bug in the manifest which specifies 
#       an older version of Jersey
#     * jersey-grizzly2-1.8.jar which can be freely downloaded
#       but is provided as a convience
#

#
# If Coherence is installed in a location other the /opt
# update the variable below appropriately
# Likewise the OBE sources 
#
COHERENCE_HOME=/opt/coherence
OBE_HOME=/opt/REST.OBE
TARGET=${OBE_HOME}/lib
#
# Clean up the lib directory if it exists
#
if [ -d ${TARGET} ] ; 
then
  rm -rf ${TARGET}
else
  echo ${TARGET} directory not found, not cleaning.
fi
mkdir ${TARGET}

#
# Copy into the lib directory the Coherence REST support libraries
#
declare -a JARFILES
JARFILES=("coherence.jar" "jackson-all-1.8.1.jar" "jersey-core-1.8.jar" "jersey-json-1.8.jar" "jersey-server-1.8.jar")

echo  Copying ${#JARFILES[@]} jar files to ${TARGET}
for ((i=0;i<${#JARFILES[@]};i++)); do
   TEMP=${COHERENCE_HOME}/lib/${JARFILES[$i]}
   if [ ! -a "${!TEMP}" ]; then
        echo "Did not find file ${TEMP}"
        error=-1
   else
        echo cp ${TEMP} ${TARGET}/
        cp ${TEMP} ${TARGET}/
   fi
done

#
# Copy the packaged libraries
#
SUPPORTJARS=("coherence-rest.jar" "jersey-grizzly2-1.8.jar")
echo  Copying ${#SUPPORTJARS[@]} jar files to ${TARGET}
for ((i=0;i<${#SUPPORTJARS[@]};i++)); do
   TEMP=./support.lib/${SUPPORTJARS[$i]}
   if [ ! -a "${!TEMP}" ]; then
        echo "Did not find file ${TEMP}"
        error=-1
   else
        echo cp ${TEMP} ${TARGET}/
        cp ${TEMP} ${TARGET}/
   fi
done

