#!/bin/sh

# The wrapper for the imtacli program
# Sets some Environment variables and calls the actual imtacli program
#

SERVERROOT=<msg.RootPath>
INSTANCEDIR=<msg.RootPath>/config
MTASBINDIR=${SERVERROOT}/sbin
MTABINDIR=${SERVERROOT}/lib
MTASCRIPT=${MTABINDIR}/imtacli
CONFIGROOT=${INSTANCEDIR}
IMSIMTA_SAVEDIR=`pwd`

export SERVERROOT INSTANCEDIR CONFIGROOT MTASBINDIR MTABINDIR IMSIMTA_SAVEDIR

# Start environment variable settings
#
# LIBPATH is set for AIX 4+
# SHLIB_PATH is set for HPUX 11+
# LD_LIBRARY_PATH used for Solaris 2.5+, SCO Unix, IRIX, Linux
ADDPATH=${SERVERROOT}/lib
LD_LIBRARY_PATH=${ADDPATH}:${LD_LIBRARY_PATH}
LIBPATH=${ADDPATH}:${LIBPATH}
SHLIB_PATH=${ADDPATH}:${SHLIB_PATH}
SUID_OK_LIBPATH=${LIBPATH}
export LD_LIBRARY_PATH LIBPATH SHLIB_PATH SUID_OK_LIBPATH

IMTA_TAILOR=${INSTANCEDIR}/imta_tailor
export IMTA_TAILOR

ret=0

#Call the actual imta script, and pass it the arguments.
#Let the script take care of argument processing and error handling
#echo "${MTASCRIPT} $*"
OSNAME=`uname`
if [ $OSNAME = Linux ]; then
  /sbin/ldconfig $SERVERROOT/lib
fi
if [ $OSNAME = Linux -o $OSNAME = AIX ]; then
  SAVEDIR=`pwd`
  cd ${INSTANCEDIR}
fi
if [ "$QUERY_STRING" = "" ]; then
  ${MTASCRIPT} "$@"
else
  # suppress output if not called interactively (like from the Admin server)
  ${MTASCRIPT} "$@" > /dev/null 2>&1
fi
if [ $OSNAME = Linux -o $OSNAME = AIX ]; then
  cd $SAVEDIR
fi

exit $?
