#!/bin/sh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/lpp/bosinst/samples/AE/AS/removeWASUnusedProfiles.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 

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

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

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


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

touch $CONFIGWAS7/.started

echodebug "Removing all unused profiles"
  
while [ $# -ne 0 ]
do
	case $1 in
		-type*)
		type=$2
		;;
		-profile_num*)
		profile_num=$2
		;;		
		*)
		;;
	esac
	shift 2
done

#echo all parameters
if [ $type ] ; then 
   echodebug "type=$type"
fi
if [ $profile_num ] ; then 
   echodebug "profile_num=$profile_num"
fi


# Delete the unused profiles
 
if [ $type != 'dmgr' ] ; then
	#------------------
	echodebug "Deleting the deployment manager"
    rm -rf $WAS_PROFILES/DefaultDmgr01
fi    

if [ $type != 'default' ] ; then
   echodebug "Deleting the default application server"
   rm -rf $WAS_PROFILES/DefaultAppSrv01
fi

if [ $type != 'custom' ] ; then
    echodebug "Deleting the custom profile"
    rm -rf $WAS_PROFILES/DefaultCustom01
fi

if [ $type != 'adminagent' ] ; then
    # Delete the other profiles
    echodebug "Deleting the administrative agent"
    rm -rf $WAS_PROFILES/DefaultAdminAgent01

   echodebug "Deleting the application server AA01"
   rm -rf $WAS_PROFILES/DefaultAppSrvAA01

   echodebug "Deleting the application server AA02"
   rm -rf $WAS_PROFILES/DefaultAppSrvAA02

   echodebug "Deleting the application server AA03"
   rm -rf $WAS_PROFILES/DefaultAppSrvAA03
   
   echodebug "Deleting the application server AA04"
   rm -rf $WAS_PROFILES/DefaultAppSrvAA04
else
   # this is an admin agent, remove any excess app servers defined 
   profile_index=4
   while [ $profile_num -lt $profile_index ]
   do    
      	AA=AA0$profile_index
        echodebug "Deleting the application server $AA"  
        rm -rf $WAS_PROFILES/DefaultAppSrv$AA    	
		let profile_index=$profile_index-1
   done  
fi


if [ $type != 'jmgr' ] ; then
   echodebug "Deleting the job manager"
   rm -rf $WAS_PROFILES/DefaultJobManager01
fi

if [ $type != 'cell' ] ; then
   echodebug "Deleting the cell deployment manager"
   rm -rf $WAS_PROFILES/DefaultCellDmgr01
   echodebug "Deleting the cell application server"
   rm -rf $WAS_PROFILES/DefaultCellAppSrv01
fi
 

echodebug "Validating the profile registry"
$WAS_HOME/bin/manageprofiles.sh -validateAndUpdateRegistry

echodebug "Done removing all unused profiles"


