#!/bin/sh

umask 0

DLC=${DLC-#ENVDLC#}		# where is OpenEdge installed?
PROTOP=#ENVPT3#			# where is ProTop installed?
LOGDIR=#ENVLOG#			# location of log files
TMPDIR=#ENVTMP#			# location of temp files
RPTDIR=#ENVRPT#			# report output
PROXY=#PROXY#			# proxy server -- i.e. proxy.xyzzy.com:8080

# bin/portalenv should handle these now
#

# PTHOST=#PTHOST#		# the ProTop portal
# PTUPD=#PTUPD#			# the ProTop update server -- might be the portal, but not necessarily

TERM=${TERM-xterm}
PROPATH=${PROTOP}
PT3=${PROTOP}
pt3=${PROTOP}

# If you see a message in ${TMPDIR}/*.err about not knowing your own PID and
# thus refusing to create a bogus flag file it might be because your default
# shell (from cron's POV) does not support $PPID.  Add the following line to
# bin/dbaenv (uncommented) to fix that:
#
# SHELL=/usr/bin/bash ; export SHELL

# Linux, SunOS and HP-UX dynamically handle li# & co# via the "ws" attribute.
# So for those operating systems the base xterm has no li# or co#.
# 
# (Progress reads the number of lines and columns at *startup* -- it will
#  not recognize geometry changes once a session is running.)
#
# AIX (and possibly others) do not honor "ws".  Thus the multiple OS specific
# files and code in this script to pick the right one.
#
# The default is "safe" but li# & co# are hard coded.

PROTERMCAP=${PROTOP}/etc/protermcap.protop

if [ -f ${PROTOP}/etc/protermcap.protop.`uname -s` ]
then
	PROTERMCAP=${PROTOP}/etc/protermcap.protop.`uname -s`
fi

PROVERSION=`cat $DLC/version | awk '{print $3}' | awk -F. '{print $1}'`

PTTMP=${TMPDIR}		# TMPDIR gets whacked by _progres, OS-GETENV( "TMPDIR" ) results in ?

export DLC PROTOP PROTERMCAP PROPATH LOGDIR TMPDIR RPTDIR TERM PTHOST PTUPD PT3 pt3 PROVERSION PTTMP PROXY

# Some proutil options (such as dbanalys) call _dbutil and if $DLC/bin is not in the PATH those options fail
#

if [ -z "`echo ${PATH} | grep ${DLC}/bin`" ]
then
	# echo "{DLC}/bin was missing!"
	# echo $PATH
	# echo $DLC
	PATH=${PATH}:${DLC}/bin
fi

if [ -z "`echo ${PATH} | grep ${PROTOP}/bin`" ]
then
        # echo "${PROTOP}/bin was missing!"
        # echo $PATH
        PATH=${PATH}:${PROTOP}/bin
fi

# backend portal specific stuff

if [ -f ${PROTOP}/bin/portalenv ]
then
	. ${PROTOP}/bin/portalenv
fi

# dbappraise specific stuff (if present)
#

if [ -f ${PROTOP}/bin/dbaenv ]
then
	. ${PROTOP}/bin/dbaenv
fi

# local environment (if present)
#
# bin/localenv will not be created or updated by pt3inst.sh -- it is safe to put anything
# unique to the local environment in here

if [ -f ${PROTOP}/bin/localenv ]
then
	. ${PROTOP}/bin/localenv
fi

# Setup the perl libraries location - might change in future version (this is related to using perl in bin/maintenance.sh)
#

if [ $PROVERSION = "12" ]
then 
   PERL5LIB="$DLC/perl/lib/5.26.1"
else	
   PERL5LIB="$DLC/perl/lib/5.6.1"
fi	
export PERL5LIB

getDBPATH() {

	if [ -f ${PROTOP}/etc/dblist.cfg ]      # search using "pipe" as the delimiter
	then
		DBPATH=`grep "^${1}|" ${PROTOP}/etc/dblist.cfg | awk -F"|" '{print $2}' 2>/dev/null`
		RESRCTYPE=`grep "^${1}|" ${PROTOP}/etc/dblist.cfg | awk -F"|" '{print $6}' 2>/dev/null`
	else
		echo "No ${PROTOP}/etc/dblist.cfg!  You must use bin/dbmaint.sh to create friendly names first!"
		exit
	fi

}
