#!/bin/sh
#
# Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"$Revision: 1.5 $ SMI"
#



# This may be an old version of Solaris. In the latest Solaris
# CLIENT_BASEDIR won't be defined yet. In older version it is.
if [ -n "${CLIENT_BASEDIR}" ]
then
    #BASEDIR already include 'INSTALL_ROOT' if defined
	INSTALLATION_BASE=$BASEDIR
else
    # The base directory hasn't been processed yet
	INSTALLATION_BASE=${PKG_INSTALL_ROOT}$BASEDIR
fi

CACAO_TOOLS_DIR=$INSTALLATION_BASE/$CACAO_TOOLS_DIR
CACAOADM=$INSTALLATION_BASE/$CACAOADM

#robustness

if [ ! -d ${CACAO_TOOLS_DIR} ]; then
    exit 0
fi

. ${CACAO_TOOLS_DIR}/messages.cfg
. ${CACAO_TOOLS_DIR}/error_codes.cfg
. ${CACAO_TOOLS_DIR}/globals.cfg
. ${CACAO_TOOLS_DIR}/utils
. ${CACAO_TOOLS_DIR}/commands_definition.cfg

#case remote install
if [ -n "${PKG_INSTALL_ROOT}" ] 
then
    # Must not stop cacao, it is installed for an other host
    # Must not use smf services, it is installed for an other host
    if [ -f "${INSTALLATION_BASE}"/${CACAC_ETC_SUFFIX}/private/.configured ]
    then
        cacao_print_message "${CACAO_MSG_WARNING_UNINSTALL_REMOTE}"
    fi
    exit 0
fi

#Stops the default Cacao instance and any additional instances.
#Stops and remove also the startup services
${CACAOADM} prepare-uninstall
if [ ${?} -ne ${CACAO_CR_SUCCESS} ]
then
    cacao_print_error_message "${PRE_REMOVE_MSG2}"
fi

exit 0
