#!/bin/sh
# Copyright(c) Sybase, Inc.
#
# This script is only used by agent clients.
#

UA_ENV_STATUS=

#
# Determine the opearting system and other variables to make some
# choices about JRE Selection and shared library locations
#

if [ -x "/bin/uname" ]; then
  nodename=`/bin/uname -n`
  osname=`/bin/uname -s`
  osarch=`/bin/uname -m`
  osversion=`/bin/uname -r`
else
  if [ -x "/usr/bin/uname" ]; then
    nodename=`/usr/bin/uname -n`
    osname=`/usr/bin/uname -s`
    osarch=`/usr/bin/uname -m`
    osversion=`/usr/bin/uname -r`
  else
    echo Failed to discover operating environment
    UA_ENV_STATUS=1
    exit 1
  fi
fi

# strip domain name from the node name

if [ -x "/bin/awk" ]; then
  AWK=/bin/awk
else
  if [ -x "/usr/bin/awk" ]; then
    AWK=/usr/bin/awk
  else
    echo Failed to find awk executable
    UA_ENV_STATUS=1
    exit 1
  fi
fi

if [ -x "/bin/domainname" ]; then
  DOMAINNAME=`/bin/domainname`
else
  if [ -x "/usr/bin/domainname" ]; then
    DOMAINNAME=`/usr/bin/domainname`
  else
    echo Failed to find domainname executable
    UA_ENV_STATUS=1
    exit 1
  fi
fi

nodename=`echo $nodename | $AWK -F"."$DOMAINNAME '{print $1}'`

if [ ${SYBASE_UA} ]; then
  echo ""
else
  echo SYBASE_UA environment variable not set
  UA_ENV_STATUS=1
  exit 1
fi

#CR 500290-3: restrict to Java6 and later
if [ -z "$SYBASE_JRE6" ]; then
    echo The $osname $osarch platform requires one of the following environment variables
    echo to be set: SYBASE_JRE6
    UA_ENV_STATUS=1
    exit 1;
fi

SYBASE_JRE=${SYBASE_JRE6}

bitwidth=

if [ $osname = "SunOS" ]; then
    bitwidth=-d64
fi

if [ $osname = "HP-UX" ]; then
    bitwidth=-d64
fi

##
## Build the classpath from common/lib
##
CLASSPATH=.
for j in `ls -1 ${SYBASE_UA}/common/lib/*.jar`
do
   CLASSPATH=$CLASSPATH:$j
done

UA_ENV_STATUS=0

