#!/bin/sh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/lpp/bosinst/samples/AE/AS/ConfigWAS.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2008,2009 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 

# @(#)37        1.1  src/bos/usr/lpp/bosinst/samples/AE/AS/ConfigWAS.sh, bosinst, bos720 3/29/09 15:20:17

#
# A utility for config WAS.
#
# usage: sh ConfigWAS  <parameters>

# source include for debug output
. /opt/IBM/AE/AS/debugWAS

touch $CONFIGWAS7/.started

WAS=/opt/IBM/WebSphere
WAS_HOME=$WAS/AppServer
WAS_PROFILES=$WAS/Profiles

ALL_PARMS=$@

#parse common parms, the rest will be parsed out as needed by the called scripts 
while [ $# -ne 0 ]
do
	case $1 in
		-type*)
		type=$2
		;;
		-profile_num*)
		profile_num=$2
		;;
		-password*)
		password=$2
		;;
		-autostart*)
		autostart=$2
		;;
		*)
		;;
	esac
	shift 2
done

#echo all parameters
echodebug "ConfigWAS started with parms: $ALL_PARMS"


echodebug "Calling script to validate the parameters."
# /opt/IBM/AE/AS/validateParams $ALL_PARMS

if [ $? -gt 0 ]; then 
 echodebug "ConfigWAS called with invalid key-value configuration parameters. Exiting"
 exit 
fi

if [ -r "$WAS_PROFILES/.ibm/password" ]
then
    export WAS_PASSWORD=`cat $WAS_PROFILES/.ibm/password`
else
    export WAS_PASSWORD=$password
fi
if [ -r "$WAS_PROFILES/.ibm/username" ]
then
    export WAS_USERNAME=`cat $WAS_PROFILES/.ibm/username`
else
    export WAS_USERNAME="virtuser"
fi

echodebug "Calling the script to remove the unused profiles"
if [ $profile_num > 0 ] ; then
    /opt/IBM/AE/AS/removeWASUnusedProfiles -type $type  -profile_num $profile_num
else
    /opt/IBM/AE/AS/removeWASUnusedProfiles -type $type
fi    

if [ $type == "reset" ] ; then
  echodebug "Calling the script to reset the profiles back to the original"
  /opt/IBM/AE/AS/resetWASProfiles
else
  echodebug "Calling the script to update the WAS profiles with new values"
  /opt/IBM/AE/AS/updateWASProfile $ALL_PARMS

  echodebug "Calling the script to tune the WAS profile"
  /opt/IBM/AE/AS/tuneWASProfile  $ALL_PARMS
  
fi  

if [ "$autostart" = "true" ] ; then
  echodebug "Calling the script to autostart the profile" 
  if [ $profile_num > 0 ] ; then
	/opt/IBM/AE/AS/startWASService -type $type -profile_num $profile_num
  else
	/opt/IBM/AE/AS/startWASService -type $type
  fi
fi

echo "ConfigWAS done"


