#!/usr/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2020,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/tds/sbin/cl_importtds.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2009,2010 
# 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 
# @(#)  7d4c34b 43haes/usr/sbin/cluster/sa/tds/sbin/cl_importtds.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM 
##############################################################################
##
## NAME:	cl_importtds
##
## DESCRIPTION:	
##    This command is a wrapper around the Smart Assistant 5.2 
## commands that creates an HACMP configuration for a Tivoli 
## Directory Server.
##
## SYNTAX:	
##    cl_importtds -a  -n takeovernodes -l serviceip -w tds_password -p tds_port -i dbinstance
##    cl_importtds -r  
##
## EXIT CODES:	
##    0 - success
##    1 - failure
##
## KLIB Functions:
##    KLIB_SA_add_metadata
##    KLIB_SA_delete_by_key_type_metadata 
##
###############################################################################

###############################################################################
#
# Name: usage
#
# Prints usage message and exits the program.
#
# Arguments:  none
#
# Returns:    does not return
#
################################################################################

function usage {
    set +u
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    set -u
    # message number needs to be changed.
    dspmsg -s $IMPORT_MSGSET $TDSSACAT 700 "Usage:\ncl_importtds -a -n takeovernode -l serviceip -w tds_password\n\
         -p tds_port -i dbinstance \n\n\
    cl_importtds -r \n"

    exit 1
}

################################################################################
# Name: AddResources
#
# Entries related to Tivoli Directory Server will be added 
# to the HACMPsa_metadata ODM.  
#
# Syntax:
#       AddResources
# 
# Arguments: None
# 
# Global Variables: None
#
# Returns:
#	0 on SUCCESS
#	1 on FAILURE
#
################################################################################

AddResources() {
    
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x


    claddsaapp -a "$APPLICATION_ID" SMARTASSIST_ID='TDS_5.2' COMPONENT_ID="$COMPONENT_ID" APPLICATION_NAME="$appname"
    if (( $? != 0 )); then
        dspmsg -s $CONF_MSGSET $TDSSACAT 390 "ERROR: Failed adding %1\$s %2\$s to the HACMPsa_metadata ODM.\n" "APPLICATION_NAME"  "$appname"
        return 1
    fi

    claddsaapp -a "$APPLICATION_ID" TDS_PASSWORD="$tds_password"
    if (( $? != 0 )); then
        dspmsg -s $CONF_MSGSET $TDSSACAT 390 "ERROR: Failed adding %1\$s %2\$s to the HACMPsa_metadata ODM.\n" "TDS_PASSWORD"  "$tds_password"
        return 1
    fi

	if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then

		claddsaapp -a "$APPLICATION_ID" NUM_INSTANCES="$num_instances"
    	if (( $? != 0 )); then
        	dspmsg -s $CONF_MSGSET $TDSSACAT 390 "ERROR: Failed adding %1\$s %2\$s to the HACMPsa_metadata ODM.\n" "TDS_TAKEOVER_NODE_NAME"  "$takeovernode"
        	return 1
   		fi
		maxnum=`echo ${#instanceList[*]}`
		let maxnum=${maxnum}+1
    	i=1;
    	while [[ $i -lt $maxnum ]];	
		do
  			INSTANCE="INSTANCE"$i
  			claddsaapp -a "$APPLICATION_ID" $INSTANCE="${instanceList[$i]}"
			INSTANCE_HOME="$INSTANCE""_HOME"
			claddsaapp -a "$APPLICATION_ID" $INSTANCE_HOME="${instanceHomeList[$i]}"
			let i=${i}+1
		done
		
	else

		claddsaapp -a "$APPLICATION_ID" TDS_TAKEOVER_NODE_NAME="$takeovernode"
    	
		if (( $? != 0 )); then
			dspmsg -s $CONF_MSGSET $TDSSACAT 390 "ERROR: Failed adding %1\$s %2\$s to the HACMPsa_metadata ODM.\n" "TDS_TAKEOVER_NODE_NAME"  "$takeovernode"
			return 1
		fi

		claddsaapp -a $APPLICATION_ID TDS_SERVICE_LABEL="${serviceip}"

		if (( $? != 0 )); then
			dspmsg -s $CONF_MSGSET $TDSSACAT 390 "ERROR: Failed adding %1\$s %2\$s to the HACMPsa_metadata ODM.\n" "TDS_SERVICE_LABEL" "$serviceip"
			return 1
		fi

		claddsaapp -a $APPLICATION_ID TDS_SERVICE_LABEL_PREFIX="${prefix}"

		if (( $? != 0 )); then
			dspmsg -s $CONF_MSGSET $TDSSACAT 390 "ERROR: Failed adding %1\$s %2\$s to the HACMPsa_metadata ODM.\n" "TDS_SERVICE_LABEL_PREFIX" "$prefix"
			return 1
		fi

		claddsaapp -a "$APPLICATION_ID" TDS_INSTANCE_NAME="$tds_instance"
		if (( $? != 0 )); then
            dspmsg -s $CONF_MSGSET $TDSSACAT 390 "ERROR: Failed adding %1\$s %2\$s to the HACMPsa_metadata ODM.\n" "TDS_INSTANCE_NAME" "$tds_instance"
            return 1
        fi
	fi

}

################################################################################
# Name: RemoveResources
#
# Entries related to Tivoli Directory Server will be removed from the 
# HACMPsa_metadata ODM.  
#
# Syntax:
#       RemoveResources
# 
# Arguments: None
# 
# Global Variables: None
#
# Returns:
#	0 on SUCCESS
#	1 on FAILURE
#
#################################################################################
RemoveResources() {

    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x

    clrmsaapp -a ${appname}

    return $?
}

#----------------------------------------------------------------------------
#
# Name:         importConfigFromFile
#
# Description:
#               This function will read the supplid config file and create HACMP
#               resources to configure TDS for HA.
#
# Arguments:
#               None
#
# Returns:
#               0 - on success
#               1 - on failure
#

importConfigFromFile() {
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    action="add"

    primary_node=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t PrimaryNode)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "PrimaryNode" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1

    }
    primary_node=$(echo $primary_node | cut -d"=" -f2)
    found=0
    for node in `/usr/es/sbin/cluster/utilities/clnodename`
    do
        [[ $node == $primary_node ]] && {
            found=1
        }
    done
    (( $found == 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 2 "Primary Node %s is not valid in the cluster.\n" $primary_node
        exit 1
    }
    appname="TDS_"$primary_node

    pwd=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t Server_Password)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "Server_Password" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1

    }
    tds_password=$(echo $pwd | cut -d"=" -f2)

    if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
    numinstances=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t NumInstances)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "TakeoverNodes" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1

    }
    num_instances=$(echo $numinstances | cut -d"=" -f2)

    else
    takover_nodes=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t TakeoverNodes)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "TakeoverNodes" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1

    }

    takover_nodes=$(echo $takover_nodes | cut -d"=" -f2)
    takeover_nodes=$(echo $takover_nodes  | tr ',' ' ')
    found=1
    for tnode in $takeover_nodes
    do
        flag=0
        for node in `/usr/es/sbin/cluster/utilities/clnodename`
        do
            [[ $node == $tnode ]] && {
                flag=1
            }
        done
        (( $flag == 0 )) && {
            found=0
        }
    done

    (( $found == 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 3 "One of the Takeover node from %s is not valid in the cluster.\n" $takeover_nodes
        exit 1
    }

    takeovernode=$takover_nodes

    port=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t Port_Number)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "Port_Number" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1

    }
    tds_port=$(echo $port | cut -d"=" -f2)

    inst=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t DBInstance)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "DBInstance" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1

    }
    dbinstance=$(echo $inst | cut -d"=" -f2)

   ipaddr=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t ServiceIP | grep IPAddress_or_name)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "ServiceIP\.IPAddress_or_name" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1
    }
    serviceip=$(echo $ipaddr | cut -d"=" -f2)

    netmask=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t ServiceIP | grep Prefix_or_Netmask)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "ServiceIP\.Prefix_or_Netmask" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1
    }
    prefix=$(echo $netmask | cut -d"=" -f2)

    tdsinstance=$(clsaxmlutil -s -x $CONFIG_FILE -m $TDS_MANUAL_CONFIG_SCHEMA -t TDSInstance)
    (( $? != 0 )) && {
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 4 "Problem in parsing %1$s tag in function %2$s\n" "DBInstance" "importConfigFromFile"
        dspmsg -s $MANUAL_CONFIG_SET $TDSSACAT 1 "Problem with XML configuration file. Ensure a valid XML file supplied.\n"
        exit 1

    }
    tds_instance=$(echo $tdsinstance | cut -d"=" -f2)

    fi
}



##########
# MAIN
##########

# Read in the message catalog entries

# Load the common functions, logmsg, dbgmsg, errmsg, abort
. /usr/es/lib/ksh93/common_functions.ksh93
. /usr/es/sbin/cluster/sa/tds/sbin/clhaws_functions

umask -S u=rw,g=,o=

PROGNAME=$(basename ${0})
PATH="$($(dirname ${0})/../../../utilities/cl_get_path all)"
PATH=/usr/bin:$PATH:/etc:/usr/sbin:/usr/ucb:/sbin:/usr/es/sbin/cluster/sa/sbin
FPATH_BASE=/usr/es/lib/ksh93
FPATH=$FPATH_BASE/hacmp:$FPATH_BASE/sa:$FPATH_BASE/aix:$FPATH_BASE/aix/odm
export PATH FPATH

[[ "$VERBOSE_LOGGING" == "high" ]] && set -x

TDSSACAT="tdssa.cat"
CONF_MSGSET=7
IMPORT_MSGSET=8
MANUAL_CONFIG_SET=50


TDSSA_HOME="/usr/es/sbin/cluster/sa/tds"
TDSSA_ETC_PATH="$TDSSA_HOME/etc"
TDSSA_SBIN_DIR="$TDSSA_HOME/sbin"
HAWS_HOME="/usr/es/sbin/cluster/sa/tds"
HAWS_SBIN_DIR="$HAWS_HOME/sbin"
HAWS_SCRIPTS_DIR="$HAWS_HOME/scripts"

typeset MANUAL_CONFIG=false #Manual Configuration mode
typeset CONFIG_FILE=""
typeset TDS_MANUAL_CONFIG_SCHEMA="$TDSSA_HOME/config/tds_config.xsd"
typeset primary_node=""

HAWS_HOME="/usr/es/sbin/cluster/sa/tds"
TMPFILE=$HAWS_HOME"/tds_config_type"
TMP_INSTANCE_LIST_FILE=$HAWS_HOME"/instancelist"

TDS_CONFIG_TYPE=`cat $TMPFILE`

set -A instanceList
set -A instanceHomeList

#### END ####

# Get the arguments.
while getopts f:A:n:l:P:w:p:I:i:N:ardu c
	do
    case $c in

    	A)
           appname=$OPTARG
             ;;

        n)
           takeovernode=$OPTARG
                ;;

        l)
           serviceip=$OPTARG
             ;;

        P)
           prefix=$OPTARG
             ;;

        w)
           tds_password=$OPTARG
             ;;

        p)
           tds_port=$OPTARG
             ;;

        i)
           dbinstance=$OPTARG
             ;;

        a)
           action="add"
             ;;

        r)
           action="remove"
             ;;

        u)
           action="update"
             ;;

        d)
           action="deleteonly"
             ;;

        f) 
           MANUAL_CONFIG=true
           CONFIG_FILE=$OPTARG
             ;;

        I)
		   num_instances=$OPTARG
             ;;

		N)
		   tds_instance=$OPTARG
			 ;;

		\?)
		   logmsg HAWS_ERROR "$MSG_UNKNOWN_OPTION" "Unrecognized command line option specified\n"
             ;;
        esac
    done

shift $(($OPTIND - 1))
appid=$1

#
# Before handling anything else, check if we have to configure from XML
#
if [[ $MANUAL_CONFIG == true ]]; then
    if [[ ! -f $CONFIG_FILE ]]; then
        dspmsg -s 51 cluster.cat 26 "Unable to read the configuration file. Please ensure the correct path"
        return 1
    fi
    importConfigFromFile
fi

HACMP_HOME=/usr/es/sbin/cluster
if [[ -z $primary_node ]]; then
    PRIMARYNODE=$($HACMP_HOME/utilities/get_local_nodename)
else
    PRIMARYNODE=$primary_node
fi
COMPONENT_ID="TIVOLI_LDAP_SERVER"
if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
	APPLICATION_ID=TDS_$PRIMARYNODE
else
	APPLICATION_ID=TDS"_$PRIMARYNODE""_$tds_instance"
fi

#Call the Smart Assist 5.2 commands

#Check the Action argument.
if [[  -z $action ]]; then
   usage
   exit 1
fi


# Configuring Tivoli Directory Server
if [[ "$action" == "add" || "$action" == "update" ]]; then

	if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
		if [[ -z $tds_password ]]; then
	       	usage
        	exit 1
		fi
	else
   #Check all the arguments are specified.
    	if [[ -z $takeovernode || -z $serviceip || -z $tds_password || -z $tds_port || -z $dbinstance ]] ; then
        	usage
        	exit 1
    	fi
	fi

    # If updating remove old stuff.
    if [[ "$action" == "update" ]]; then
        
        #Check all the arguments are specified.
        if [[ -z $appname ]] ; then
            usage
            exit 1
        fi

        # Remove old HACMP resources
        /usr/es/sbin/cluster/sa/sbin/clrmrgs -a "$appname"
        
        # Remove HACMPsa_metadata odm entries.  If this fails, attempt the add anyway.
        RemoveResources

        # Remove the entries created for configuring Tivoli Directory Server
		if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
            $HAWS_SCRIPTS_DIR"/"tds_import_delete
        else
            script="tds_"$tds_instance"_import_delete"
            $HAWS_SCRIPTS_DIR"/"$script
        fi 
        if (( $? != 0 )) then        
            exit 1
        fi

		if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
			typeset NUM_INSTANCES
			eval $(clquerysaapp -a $APPLICATION_NAME NUM_INSTANCES)
			if [[ $NUM_INSTANCES != $num_instances ]] then
				get_instance_list
			fi
    	fi
	fi

	if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
		$HAWS_SBIN_DIR"/"clhaws_import -w "$tds_password" -s $PRIMARYNODE -I "$num_instances" -A $APPLICATION_ID  > /dev/null
		# Discover and create directory instance list
    	get_instance_list
		
    elif [[ -z $prefix ]]; then 
        $HAWS_SBIN_DIR"/"clhaws_import -n "$takeovernode" -l "$serviceip" -w "$tds_password" -p "$tds_port" -i "$dbinstance" -s $PRIMARYNODE -N "$tds_instance" -A $APPLICATION_ID > /dev/null 
    else
        $HAWS_SBIN_DIR"/"clhaws_import -n "$takeovernode" -l "$serviceip" -P "$prefix" -w "$tds_password" -p "$tds_port" -i "$dbinstance" -s $PRIMARYNODE -N "$tds_instance" -A $APPLICATION_ID  > /dev/null 
    fi
    if (( $? != 0 )) then
        dspmsg -s $IMPORT_MSGSET $TDSSACAT 710 "ERROR: Failed to create import scripts.\n"
        exit 1
    fi
   
    # run the created import script
	if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
		$HAWS_SCRIPTS_DIR"/"tds_import_create
	else
		script="tds_"$tds_instance"_import_create"
    	$HAWS_SCRIPTS_DIR"/"$script
	fi 
    rc=$?
    if (( $rc != 0 )) then	

        if (( $rc == 2 )) then
           dspmsg -s $CONF_MSGSET $TDSSACAT 99999  "ERROR: Already existing resources found.  No changes made.\n"
           exit 1
        fi

        dspmsg -s $CONF_MSGSET $TDSSACAT 999  "ERROR: Import Failed. Removing all added entries.\n"
        # In case of error, remove all the added entries
		if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
			$HAWS_SCRIPTS_DIR"/"tds_import_delete
		else
			script="tds_"$tds_instance"_import_delete"
        	$HAWS_SCRIPTS_DIR"/"$script
		fi 
        exit 1
    fi
   
    # Add the metadata resources    
    AddResources
    if (( $? != 0 )) then	
        dspmsg -s $CONF_MSGSET $TDSSACAT 410  "ERROR: Failed updating HACMPsa_metadata ODM.\n"
        dspmsg -s $CONF_MSGSET $TDSSACAT 99999  "ERROR: Import Failed. Removing all added entries.\n"

        # remove all the added entries.
		if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
            $HAWS_SCRIPTS_DIR"/"tds_import_delete
        else
			script="tds_"$tds_instance"_import_delete"
        	$HAWS_SCRIPTS_DIR"/"$script
		fi 

        RemoveResources > /dev/null 2>&1
        if (( $? != 0 )) then	
            dspmsg -s $CONF_MSGSET $TDSSACAT 410  "ERROR: Failed updating HACMPsa_metadata ODM.\n"
            exit 1
        fi
    fi

# UnConfiguring Tivoli Directory Server
elif [[ "$action" == "remove" ]]; then

    # Remove the entries created for configuring Tivoli Directory Server
	if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
        $HAWS_SCRIPTS_DIR"/"tds_import_delete
    else
		typeset TDS_INSTANCE_NAME
		set -a
		eval $(clquerysaapp -a $appid TDS_INSTANCE_NAME)
		set +a
		echo $TDS_INSTANCE_NAME
		script="tds_"$TDS_INSTANCE_NAME"_import_delete"
    	$HAWS_SCRIPTS_DIR"/"$script
	fi
    if (( $? != 0 )) then	
        exit 1
    fi

    # Remove the entries created in Metadata odm for configuring Tivoli Directory Server
    RemoveResources  > /dev/null 2>&1
    if (( $? != 0 )) then	
        dspmsg -s $CONF_MSGSET $TDSSACAT 410  "ERROR: Failed updating HACMPsa_metadata ODM.\n"
        exit 1
    fi

elif [[ "$action" == "deleteonly" ]]; then

    # Remove the entries created for configuring Tivoli Directory Server
	if [[ "$TDS_CONFIG_TYPE" = "DISTRIBUTED"  ||  "$TDS_CONFIG_TYPE" = "PEERTOPEER" ]]; then
        $HAWS_SCRIPTS_DIR"/"tds_import_delete
    else
        typeset TDS_INSTANCE_NAME
        set -a
        eval $(clquerysaapp -a $appid TDS_INSTANCE_NAME)
        set +a
        echo $TDS_INSTANCE_NAME
        script="tds_"$TDS_INSTANCE_NAME"_import_delete"
    	$HAWS_SCRIPTS_DIR"/"$script
	fi
    if (( $? != 0 )) then	
        exit 1
    fi
fi

exit 0
