#!/bin/ksh
# Copyright Business Objects 2005
#
# wdeploy script, designed to be installed in $BOINSTALLDIR/deployment
# This is a utility to call ant for the xml build file $1.xml

usage()
{
cat << EOF

usage : wdeploy help
        wdeploy version
        wdeploy [appservertype] listapps
        wdeploy [appservertype] deployall
        wdeploy [appservertype] buildall
        wdeploy [appservertype] predeployall
        wdeploy [appservertype] deployonlyall
        wdeploy [appservertype] -DAPP=[appname] buildwar
        wdeploy [appservertype] -DAPP=[appname] predeploy
        wdeploy [appservertype] -DAPP=[appname] deploy
        wdeploy [appservertype] -DAPP=[appname] deployonly

See README for details
You must edit file config.[appservertype]
    to specify your appserver location and parameters
EOF
}

cd `dirname $0`
HERE=`pwd`
BODIR=`dirname $HERE`
BOBJE=$BODIR/bobje/enterprise115
EPMDIR=$BODIR/Performance_Management_115

export BOBJE BODIR EPMDIR 

case `uname` in
SunOS)  platform=solaris_sparc
	libvar=LD_LIBRARY_PATH;;
AIX)    platform=aix_rs6000
	libvar=LIBPATH;;
HP-UX)  platform=hpux_pa-risc
	libvar=SHLIB_PATH;;
Linux)  platform=linux_x86
	libvar=LD_LIBRARY_PATH;;
esac
export platform libvar

OLAPDIR=$BODIR/bobje/enterprise115/$platform/olap
OLAPBINDIR=$BODIR/bobje/enterprise115/$platform/olap/bin
export OLAPDIR OLAPBINDIR

if [ -z "$1" ] ; then
  usage
  exit 3
fi

as_type=$1
shift

if [ "$as_type" = "help" ] ; then
  usage
  exit 3
fi

if [ "$as_type" = "version" ] ; then
  cat ProductID.txt
  exit 0
fi

if [ ! -r $as_type.xml ] ; then
  usage
  exit 3
fi

if [ -r ./config.properties ] ; then
  propsfile=config.properties
elif [ -r ./config.$as_type ] ; then
  propsfile=config.$as_type
fi

. ./$propsfile

cmdline=""

for i in "$@"
do
    as_dir_from_cmdline=`echo $i | awk '/^\-Das_dir=.*\$/ {print;}' | sed "s/\-Das_dir=//"`;
    if [ -n "$as_dir_from_cmdline" ] ; then
	as_dir=$as_dir_from_cmdline
    fi
    case $i in
    -D*) cmdline="$cmdline $i"
	;;
    *) cmdline="$cmdline -Dtoptarget=$i $i"
	;;
    esac
done

if [ -z "$JAVA_HOME" ] ; then
    echo JAVA_HOME Not set, trying to guess it depending on "$as_type", the command line and the content of "$propsfile"
    case $as_type in
    sunone*)	`grep asenv.conf $as_dir/bin/asadmin | sed 's|"||g' `
		JAVA_HOME=$AS_JAVA
		export JAVA_HOME
		export AS_JAVA
		export SUNONE_ENV_SOURCED=1
	;;
    weblogic8*)	if [ -r $as_dir/setEnv.sh ] ; then
		    eval `grep "JAVA_HOME=" $as_dir/setEnv.sh`
		else
		    eval `grep "JAVA_HOME=" $as_dir/startWebLogic.sh`
		fi
		export JAVA_HOME
	;;
    weblogic9*) if [ -r $as_dir/bin/setDomainEnv.sh ] ; then
		    . $as_dir/bin/setDomainEnv.sh
		fi
		cd $HERE
		export JAVA_HOME
		export WL_HOME
		export WL_ENV_SOURCED=1
	;;
    websphere*)	JAVA_HOME=$as_dir/java
		export JAVA_HOME
	;;
    esac

    if [ -z "$JAVA_HOME" ] ; then
	  echo JAVA_HOME not set
	  exit 1
    fi
fi

echo JAVA_HOME=$JAVA_HOME
export JAVA_HOME

case $as_type in
    weblogic8*)	if [ -r $as_dir/setEnv.sh ] ; then
		    eval `grep "WL_HOME=" $as_dir/setEnv.sh`
		else
		    eval `grep "WL_HOME=" $as_dir/startWebLogic.sh`
		fi
		export WL_HOME
		if [ -z "$WL_HOME" ] ; then
		    echo WL_HOME not found in $as_dir/setEnv.sh or $as_dir/startWebLogic.sh. \'deploy\' will NOT work
		else
		    echo WL_HOME=$WL_HOME
		fi
	;;
    weblogic9*) if [ -z "$WL_ENV_SOURCED" ] ; then
		    if [ -r $as_dir/bin/setDomainEnv.sh ] ; then
			. $as_dir/bin/setDomainEnv.sh
		    fi
# setDomainEnv does a cd to $as_dir
		    cd $HERE
		    export WL_HOME
		fi
	;;
    sunone*)	if [ -z "$SUNONE_ENV_SOURCED" ] ; then
		    `grep asenv.conf $as_dir/bin/asadmin | sed 's|"||g' `
		    export AS_JAVA
		fi
	;;
esac

ANT_HOME=$BODIR/deployment/ant
export ANT_HOME

PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
export PATH

ANT_OPTS="-Xmx1024m"
export ANT_OPTS

ant --noconfig -f wcommon.xml -Das_type=$as_type -emacs -Dbo.dir=$BODIR -Depm.dir=$EPMDIR -Dolap.dir=$OLAPDIR -Dolap.bin.dir=$OLAPBINDIR -DBOBJE=$BOBJE -Dplatform=$platform -Dproperties.file=$propsfile $cmdline

