#! /bin/sh

########################################################################
#
# /u/sonmi/bin/set_environment
#
# sourced from the header if running from cron to get the full environment
# to run nssqa    - also used to unify all nssqa environments
#
# This is derived from the .cshrc file for the svbld account.  
#
########################################################################

if [ -z "$HOME" ] 
then
    HOME=/u/svbld
fi
if [ -z "$QASCRIPT_DIR" ]
then
    QASCRIPT_DIR=`dirname $0`
fi

os_name=`uname -s`
if [ "$os_name" != "Windows_95" -a \
    "$os_name" != "Windows_NT" -a \
    "$os_name" != "WINNT" -a \
    "$os_name" != "Windows" -a \
    "$os_name" != "Windows_98" -a \
    "$os_name" != "CYGWIN_NT-4.0" -a \
    "$os_name" != "CYGWIN_NT-5.0" -a \
    "$os_name" != "CYGWIN_95-4.0" -a \
    "$os_name" != "CYGWIN_98-4.10" ]
then
    PATH=.:$HOME/bin:/tools/ns/bin:/bin:/usr/bin:/usr/sbin:/usr/ccs/bin:/usr/dist/local/exe:/usr/bin/X11:/usr/audio/bin:/u/sonmi/bin:$PATH
    JAVA_HOME="D:/i386/jdk1.2.2"
    JAVA_HOME14="R:/jdk/1.4.0/WINNT"
fi

CVSROOT=:pserver:svbld@redcvs.red.iplanet.com:/m/src

os_name=`uname -s`
os_version=`uname -r`
#os_p=`uname -p`
os_full=""

if [ -f /u/svbld/bin/nsarch  ]
then
    os_full=`/u/svbld/bin/nsarch -f`    #FIXME
fi

MANPATH=/usr/share/man:/usr/openwin/man:/usr/local/man

RMAIL=rmail
BEFORE_CONTEXT_GREP=""
AFTER_CONTEXT_GREP=""

export CVSROOT HOME os_name os_version os_full MANPATH


if [ "$os_name" = "HP-UX" ]
then
    PATH=$PATH:/usr/local/bin:/opt/aCC/bin:/usr/local/bin/audio:/tools/ns/bin:/etc:/usr/contrib/bin:/usr/contrib/bin/X11:/usr/local/hpux/bin:/nfs/iapp1/hphome/bin:/etc:/u/svbld/bin/HP/perl/bin
    JAVA_HOME="/share/builds/components/cms_jdk/HP-UX/1.2.2.04"
    JAVA_HOME14=$JAVA_HOME
#    JAVA_HOME="/share/builds/components/cms_jdk/HP-UX/1.3.0.00"
elif [ "$os_name" = "SunOS" ]
then
    NATIVE_FLAG="-native"
    XAPPLRESDIR=/usr/openwin/lib/app-defaults:/usr/local/lib/X11/app-defaults
    OPENWINHOME=/usr/openwin
    LD_LIBRARY_PATH=$OPENWINHOME/lib
    if [ "$os_full" = "SOLARISx86 2.8" -o "$os_full" = "SOLARISx86 2.9" ] 
    then
        #PATH=/usr/ucb:/opt/usr/local/bin:$PATH
        JAVA_HOME="/usr/java1.2"
	JAVA_HOME14=/share/builds/components/jdk/1.4.0/SunOS_x86
        PATH=".:/usr/dist/share/forte_dev_i386,v6.2/SUNWspro/bin:/opt/usr/local/perl5/bin:/opt/SUNWspro/bin:/opt/usr/local/bin:/bin:/usr/bin:/usr/sbin:/usr/ccs/bin:/usr/dist/local/exe:/usr/ccs/bin:/usr/ucb/bin:/usr/ucb:/opt/SUNWwabi/bin:/usr/local/bin:/tools/ns/bin:/etc:/tools/contrib/bin"
    else
        PATH=/usr/ucb:$PATH
        JAVA_HOME="/share/builds/components/jdk/1.2.2/SunOS"
	JAVA_HOME14=/share/builds/components/jdk/1.4.0/SunOS64
        PATH=/tools/ns/bin:$PATH:/opt/SUNWspro/bin:/usr/bin/X11:/usr/openwin/bin:/usr/openwin/demo
    
        if [ "$os_version" = "5.8" -o "$os_version" = "5.7" -o \
             "$os_version" = "5.9" ]
        then
            PATH=$PATH:/usr/dist/pkgs/forte_dev,v6.2/SUNWspro/bin:/tools/ns/workshop/bin
        else
            PATH=$PATH:/usr/dist/share/devpro,v5.0/5.x-sparc/bin:/tools/ns/workshop/bin
        fi
        PATH=$PATH:/usr/ccs/bin:/usr/ucb/bin:/opt/SUNWwabi/bin:/usr/local/bin:/tools/ns/bin:/etc:/tools/contrib/bin
     fi
    export XAPPLRESDIR  OPENWINHOME LD_LIBRARY_PATH

elif [ "$os_name" = "IRIX" ]
then
    PATH=$PATH:/tools/ns/bin:/usr/local/bin:/etc:/usr/bsd
    MANPATH=/tools/ns/man:/usr/local/man
    JAVA_HOME="/share/builds/components/jdk/1.2.2/IRIX"
    JAVA_HOME14=$JAVA_HOME
elif [ "$os_name" = "IRIX64" ]
then
    PATH=$PATH:/tools/ns/bin:/usr/local/bin:/etc:/usr/bsd
    MANPATH=/tools/ns/man:/usr/local/man
    JAVA_HOME="/share/builds/components/jdk/1.2.2/IRIX"
    JAVA_HOME14=$JAVA_HOME
elif [ "$os_name" = "Linux" ]
then
    PATH=/lib:/usr/lib:/bin:/sbin:/usr/bin:/usr/sbin:$PATH
    RMAIL=sendmail
    #the gnu grep, on Linux can output 10 lines above and 3 lines below 
    #the errormessage
    BEFORE_CONTEXT_GREP="--before-context=10"
    AFTER_CONTEXT_GREP="--after-context=3"
    JAVA_HOME="/share/builds/components/jdk/1.2.2/Linux"
    JAVA_HOME14=/share/builds/components/jdk/1.4.0/Linux
elif [ "$os_name" = "AIX" ]
then
    PATH=$PATH:/tools/contrib/bin:/usr/local/bin 
    TERM=vt100
    export TERM
    JAVA_HOME="/share/builds/components/cms_jdk/AIX/1.3.0"
    JAVA_HOME14=$JAVA_HOME
elif [ "$os_name" = "OSF1" ]
then
    PATH=$PATH:/usr/local/bin
    JAVA_HOME="/share/builds/components/jdk/1.2.2/OSF1"
    JAVA_HOME14=$JAVA_HOME
fi

if [ "$os_name" = "IRIX" ]
then
    PATH=/tools/ns-arch/soft/perl-5.004_04/run/default/mips_sgi_irix5.3/bin:$PATH
elif [ "$os_name" = "IRIX64" ]
then
    PATH=/tools/ns-arch/soft/perl-5.004_04/run/default/mips_sgi_irix5.3/bin:$PATH
fi

O_CYGNUS=OFF
O_MKS=OFF
O_WIN=OFF

if [ "$os_name" = "CYGWIN_NT-4.0" -o \
    "$os_name" = "CYGWIN_NT-5.0" -o \
    "$os_name" = "CYGWIN_95-4.0" -o \
    "$os_name" = "CYGWIN_98-4.10" ]
then
    #FIXME net use, mount the neccessary pnetwork drives and partitiones first
    #FIXME - take MKS out of the PATH
    os_full=$os_name
    os_name="Windows"
    O_CYGNUS=ON
    O_WIN=ON
    PATH="`dirname $0`:.:/cygdrive/c/cygwin/bin:/cygdrive/z/nstools/bin:/cygdrive/z/nstools/perl5:/cygdrive/z/bin:/cygdrive/c/WINNT/System32:/cygdrive/c/WINNT"
    RM=/cygdrive/c/cygwin/bin/rm.exe    #FIXME - in case we cant cporrect 
                                        #these with the PATH alone
    PATH=`perl $QASCRIPT_DIR/path_uniq "$PATH"`
    RSH=/cygdrive/c/winnt/system32/rsh
elif [ "$os_name" = "Windows_95" -o \
    "$os_name" = "Windows_NT" -o \
    "$os_name" = "WINNT" -o \
    "$os_name" = "Windows" -o \
    "$os_name" = "Windows_98" ]
then
    #FIXME net use, mount the neccessary pnetwork drives and partitiones first
    PATH=`echo $SHELL | sed -e "s/.[kK][sS][Hh].[Ee][Xx][Ee]//g"  \
				-e "s/.[sS][Hh].[Ee][Xx][Ee]//g"`
    MOZTOOLS_IN_PATH=NO
    if [ -n "$MOZ_TOOLS" -a -d  "$MOZ_TOOLS" ] ; then
        MOZ_TOOLS=`ls -d "$MOZ_TOOLS" | sed -e 's/\\\/\//g'`
        #echo "MOZ_TOOLS reformated to $MOZ_TOOLS"
        if [ -d "$MOZ_TOOLS" ] ; then #still exist after reformating?
            MOZTOOLS_IN_PATH=OK
        fi
    fi
    if [ -n "$MOZTOOLS_IN_PATH" -a "$MOZTOOLS_IN_PATH" = "OK" ] ; then
        #echo "Use MOZTOOLS in PATH"
        PATH="$MOZ_TOOLS/bin;$MOZ_TOOLS/perl5;$PATH"
    elif [ -d Z:/nstools/bin ] ; then
        PATH="Z:/nstools/bin;Z:/nstools/perl5;$PATH"
    elif [ -d C:/nstools/bin ] ; then
        PATH="C:/nstools/bin;C:/nstools/perl5;$PATH"
    elif [ -d D:/nstools/bin ] ; then
        PATH="D:/nstools/bin;D:/nstools/perl5;$PATH"
    elif [ -d D:/i386/nstools/bin ] ; then
        PATH="D:/i386/nstools/bin;D:/i386/nstools/perl5;$PATH"
    else
        echo "FATAL: Can't find nstools"
        exit
    fi

    if [  "$os_name" = "Windows_NT" -o \
        "$os_name" = "WINNT" ]
    then
        PATH="${PATH};C:/WINNT/System32;C:/WINNT;.;"
    fi
    PATH="`dirname $0`;$PATH"
    
    PATH=`perl $QASCRIPT_DIR/path_uniq -d ';' "$PATH"`
    echo $PATH
    os_full=$os_name
    os_name="Windows"
    O_MKS=ON
    O_WIN=ON
    if [ -z $RSH ] ; then 
        RSH=c:/winnt/system32/rsh
    fi
    
else
    EDITOR=vi
    EMACSLOADPATH=/u/svbld/emacs
    PYTHONPATH=.:/tools/ns/lib/python1.4
    PAGER=less
    XMCD_LIBDIR=/usr/local/lib/xmcd
    DISPLAY=:0.0
    PATH=`perl $QASCRIPT_DIR/path_uniq "$PATH"`
    RSH=rsh
fi

BASEPATH=$PATH    # in  case we we set and reset DIST directories the PATH 
                # needs to change accordingly
export PATH EDITOR EMACSLOADPATH PYTHONPATH PAGER XMCD_LIBDIR DISPLAY MANPATH os_full os_name BASEPATH RSH O_WIN

umask 022

system=`uname -n`        # name of this system.

JAVAC=$JAVA_HOME/bin/javac
JAVA=$JAVA_HOME/bin/java
JAVAC14=$JAVA_HOME14/bin/javac
JAVA14=$JAVA_HOME14/bin/java
#JAVA=$JAVA_HOME/jre/bin/java
export JAVAC JAVA JAVA_HOME JAVAC14 JAVA_HOME14 JAVA14