#!/bin/sh 
 
##################################################################
# The new utilities have to be added to the list between 
# 'Start Commands' and 'End Commands' flags.
# For each utility 3 fields has to be defined, separated by ':'
# 1. command - e.g lsainit - this is the name of the command as 
#    it will be documented and known to the user
# 2. invoke - e.g. $mwcore_dir/mw/bin-$mwos_optimized/mwlsainit -
#    this is the actual invocation line for executing this command
# 3. short description - a one liner explaining the command
##################################################################
#Start Commands
#version:cat "$mwcore_dir/tools/core_version":displays the version number of the MSC.
#help:cat "$mwcore_dir/tools/mwadm.txt":displays help on using mwadm and its commands.
#stop:mwcore stop:stops all MSC services in an orderly manner.
#start:mwcore start:manually starts all MSC services.
#status:mwstatus:provides vital signs of the MSC services.
#log:mwlog:administers the MSC logs.
#sec:mwsetsec:administers MSC DCOM security settings.
#port:mwsetport.sh:administers RPC endpoint 
#reg:mwreg:administers the MSC registry service.
#location:echo "$mwcore_inst":return MSC installation directory
#chadm:mwchadm:changes MSC Administrator
#End Commands
#################################################
PATH="$PATH:/bin:/usr/bin"
#PATH=/bin:/usr/bin:$PATH
export PATH
curdir=`dirname "$0"`
absolute=`expr "$0" : '/.*'`
if [ $absolute = 0 ];then
  curdir="`pwd`/$curdir"
fi

# if mwadm run from /usr/bin ( mwadm -> <core install path>/utils/mwadm ) we want to set 'curdir' to the real path 
is_sym=`ls -l "$0" |cut -c1`
if [ "$is_sym" = "l" ];then
  mwadm=`ls -l "$0"|sed 's/^.*-> //'`
  curdir=`dirname "$mwadm"`
fi

# The mwadm can run from mainsoft installation or from local installation of Core Services
type=""
if [ -f "$curdir/../setupmainwin" ];then
  type="mainwin"
else
  type="local"
fi

MWOS=`"$curdir/getplatinfo" os`
MWARCH=`"$curdir/getplatinfo" arch`
MWCONFIG_NAME=`"$curdir/getplatinfo" config`
export MWOS MWARCH MWCONFIG_NAME

if [ $MWOS = "linux" ];then
   MWENV="/usr/bin/env"
else
   MWENV="/bin/env"
fi
 
if [ ! -x $MWENV ];then
  MWENV="env"
fi

#Setting lib_path_name 
if [ $MWOS = "ux11" ];then
  lib_path_name="SHLIB_PATH"
elif [ $MWOS = "aix4" ];then
  lib_path_name="LIBPATH"
else
  lib_path_name="LD_LIBRARY_PATH"
fi

myPath="${curdir}:${curdir}/../bin-${MWCONFIG_NAME}:${curdir}/../bin-${MWCONFIG_NAME}_optimized:${PATH}"
if [ $type = "mainwin" ];then 
  eval libpath='"'"\${$lib_path_name}"'"'
else
  eval libpath='"'"$curdir/exe/$MWCONFIG_NAME:$curdir/../lib-${MWCONFIG_NAME}_optimized:\${$lib_path_name}"'"'
  if [ $MWOS = "linux" ];then
    libpath="${libpath}:$curdir/../../misc/linux/gcc/fixed3/lib"
  fi
fi

MWPERL="$curdir/../bin-${MWARCH}_${MWOS}/mwperl"
MWINCLUDE="-I$curdir/../bin-${MWARCH}_${MWOS} -I$curdir/../lib/stdperl"
if [ "$MWHOME" = "" ];then
  MWHOME="$curdir/.."
fi
if [ "$TZ" != "" ]; then
  SETTZ="TZ=$TZ"
fi
if [ $# -gt  0 ];then
  $MWENV -i HOME="$HOME" MWTEMP="$MWTEMP" MWRT_MODE=$MWRT_MODE MWCORE_PRIVATE_DATA="$MWCORE_PRIVATE_DATA" MWREGISTRY="$MWREGISTRY" MWHOME="$MWHOME" MWOS=$MWOS MWCONFIG_NAME=$MWCONFIG_NAME PATH="$myPath" MWDEBUG=$MWDEBUG MWINGNOR_ERRORS=$mwingnor $lib_path_name="$libpath" MSOFTLM_HOST=$MSOFTLM_HOST MWRPC_ENDPOINT="$MWRPC_ENDPOINT" MWUSER_DIRECTORY="$MWUSER_DIRECTORY" PERL_DL_NONLAZY=1 SPINLOOPTIME=$SPINLOOPTIME AIXTHREAD_MNRATIO=$AIXTHREAD_MNRATIO MWCS_AUTOMATIC=$MWCS_AUTOMATIC MWPERL="$MWPERL" $SETTZ MWNO_STATVFS=$MWNO_STATVFS "$MWPERL" "$MWINCLUDE" "$curdir/tools/mwadm.pl" $type $@
else
  $MWENV -i HOME="$HOME" MWTEMP="$MWTEMP" MWRT_MODE=$MWRT_MODE MWCORE_PRIVATE_DATA="$MWCORE_PRIVATE_DATA" MWREGISTRY="$MWREGISTRY" MWHOME="$MWHOME" MWOS=$MWOS MWCONFIG_NAME=$MWCONFIG_NAME PATH="$myPath" MWDEBUG=$MWDEBUG MWINGNOR_ERRORS=$mwingnor $lib_path_name="$libpath" MSOFTLM_HOST=$MSOFTLM_HOST MWRPC_ENDPOINT="$MWRPC_ENDPOINT" MWUSER_DIRECTORY="$MWUSER_DIRECTORY" PERL_DL_NONLAZY=1 SPINLOOPTIME=$SPINLOOPTIME AIXTHREAD_MNRATIO=$AIXTHREAD_MNRATIO MWCS_AUTOMATIC=$MWCS_AUTOMATIC MWPERL="$MWPERL" $SETTZ MWNO_STATVFS=$MWNO_STATVFS "$MWPERL" "$MWINCLUDE" "$curdir/tools/mwadm.pl" $type
fi
