#!/bin/sh
#
# Starting PutQuit
#
# Required Parameters:
# -m QueueManagerName
# -h host
# -p port
# -c channel
# -q RequestQueueName
# -u userId
# -x password
#
# Set defaul values
#
MY_JVM_PARMS="-Dcom.ibm.mq.cfg.useIBMCipherMappings=false -Dcom.ibm.jsse2.disableSSLv3=false"
#
# Common CLASSPATH value
#
CLASSPATH=".:libs/sqlite-jdbc-3.20.0.jar"
#
#
if [ -n "${MQSSLKEYR}" ]; then
   MY_JVM_PARMS="${MY_JVM_PARMS} -Djavax.net.ssl.trustStore=${MQSSLKEYR}.jks"
fi
#
export CLASSPATH
#
# Are the MQ Java libraries installed
#
if [ -f "/opt/mqm/java/lib/com.ibm.mq.jar" ] || [ -f "/usr/mqm/java/lib/com.ibm.mq.jar" ] || [ -f "/QIBM/ProdData/mqm/java/lib/com.ibm.mq.jar" ]; then
  #
  # Figure out CLASSPATH and shared library
  #
  case `uname -s` in
  AIX)
    if [ -z "${MQ_JAVA_LIB_PATH}" ]; then
      MQLIBPATH="/usr/mqm/java/lib"
    else
      MQLIBPATH="${MQ_JAVA_LIB_PATH}"
    fi

    if [ -n "${LIBPATH}" ]; then
      LIBPATH="${MQLIBPATH}:$LIBPATH"
    else
      LIBPATH="${MQLIBPATH}"
    fi

    export LIBPATH
    echo "LIBPATH=${LIBPATH}"
  ;;
  HP-UX)
    if [ -z "${MQ_JAVA_LIB_PATH}" ]; then
      MQLIBPATH="/opt/mqm/java/lib"
    else
      MQLIBPATH="${MQ_JAVA_LIB_PATH}"
    fi

    if [ -n "${SHLIB_PATH}" ]; then
      SHLIB_PATH="${MQLIBPATH}:$SHLIB_PATH"
    else
      SHLIB_PATH="${MQLIBPATH}"
    fi

    export SHLIB_PATH
    echo "SHLIB_PATH=${SHLIB_PATH}"
  ;;
  LINUX|Linux)
    if [ -z "${MQ_JAVA_LIB_PATH}" ]; then
      MQLIBPATH="/opt/mqm/java/lib"
    else
      MQLIBPATH="${MQ_JAVA_LIB_PATH}"
    fi

    if [ -n "${LD_LIBRARY_PATH}" ]; then
      LD_LIBRARY_PATH="${MQLIBPATH}:$LD_LIBRARY_PATH"
    else
      LD_LIBRARY_PATH="${MQLIBPATH}"
    fi

    export LD_LIBRARY_PATH
    echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
  ;;
  SunOS)
    if [ -z "${MQ_JAVA_LIB_PATH}" ]; then
      MQLIBPATH="/opt/mqm/java/lib"
    else
      MQLIBPATH="${MQ_JAVA_LIB_PATH}"
    fi

    if [ -n "${LD_LIBRARY_PATH}" ]; then
      LD_LIBRARY_PATH="${MQLIBPATH}:$LD_LIBRARY_PATH"
    else
      LD_LIBRARY_PATH="${MQLIBPATH}"
    fi

    export LD_LIBRARY_PATH
    echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
  ;;
  OS400)
    if [ -z "${MQ_JAVA_LIB_PATH}" ]; then
      MQLIBPATH="/QIBM/ProdData/mqm/java/lib"
    else
      MQLIBPATH="${MQ_JAVA_LIB_PATH}"
    fi

    if [ -n "${LIBPATH}" ]; then
      LIBPATH="${MQLIBPATH}:$LIBPATH"
    else
      LIBPATH="${MQLIBPATH}"
    fi

    export LIBPATH
    echo "LIBPATH=${LIBPATH}"
  ;;
  *)
    if [ -z "${MQ_JAVA_LIB_PATH}" ]; then
       echo "Using included libs libraries - Only Client mode connections allowed."
       MQLIBPATH="libs"
    else
      MQLIBPATH="${MQ_JAVA_LIB_PATH}"
    fi
  esac
else
  echo "Java MQ not found."
  exit
fi
#
# Add MQ JAR files to the CLASSPATH
#
# For IBM v8.0 & v9.0
#
CLASSPATH="${MQLIBPATH}/com.ibm.mq.allclient.jar:${MQLIBPATH}:$CLASSPATH"
#
# For IBM v7.0, 7.1 & v7.5
# uncomment for MQ v7.* environment
#
# CLASSPATH="${MQLIBPATH}/com.ibm.mq.jar:${MQLIBPATH}/connector.jar:${MQLIBPATH}/com.ibm.mq.jmqi.jar:${MQLIBPATH}/com.ibm.mq.headers.jar:${MQLIBPATH}/com.ibm.mq.commonservices.jar:${MQLIBPATH}/com.ibm.mq.pcf.jar:${MQLIBPATH}:$CLASSPATH"
#
export CLASSPATH
echo "CLASSPATH=${CLASSPATH}"
#
#
java ${MY_JVM_PARMS} PutQuit "$@"
