#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61pkgha_r714 src/packages/cluster/es/server/rte/usr/cluster.es.server.rte.unconfig.sh 1.12.1.11 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1999,2013 
# 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 
# @(#)16	1.12.1.11 src/packages/cluster/es/server/rte/usr/cluster.es.server.rte.unconfig.sh, pkghacmp, 61pkgha_r714 9/12/13 09:22:57
#
###############################################################################
#
# USR part unconfig script 
#
###############################################################################

###############################################################################
#
#  Name:  onintr
#
#  Rudimentary signal handler
#
#  Arguments:    none
#  Returns:      5 - exit with error
#  Environment:  interrupt handler
#
###############################################################################
function onintr
{
    echo "$0: Caught signal - exiting"
    exit 5
}

###############################################################################
#
#  Name:  if_failed
#
#  Common exit method
#
#  Arguments:    status - return code from some operation
#                errmsg - error message to display (if operation failed)
#
#  Returns:      if status is non 0 exit with error
#  Environment:  installp
#
###############################################################################
if_failed()
{
    status=$1
    errmsg=$*
    if (( $status != 0 )); then
        echo Failed $errmsg
        STATUS=99
    fi
}

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

#
# Setup a rudimentary PATH
#
PATH=/bin:/usr/bin:/usr/sbin
export PATH

#
# Establish a signal handler
#
trap onintr 1 2 3

STATUS=0

#
# Remove symbolic links in the Classic locations.
# See the commentary in the config script for more information.
# 
ESDIR="/usr/es/sbin/cluster"
LNDIR="/usr/sbin/cluster"
if [[ -d ${ESDIR} && -d ${LNDIR} ]]; then
          cd ${ESDIR}
          for dir in $(ls | grep -v '^\.')
          do
              [[ $(LC_ALL=C file $dir | awk '{print $2}') != "directory" ]] && continue;
              LNFILE="${LNDIR}/${dir}"
              if [[ -L "${LNDIR}/${dir}" ]]; then
                 rm -f ${LNDIR}/${dir}
                 if (( $? != 0 )) ; then
                     echo "WARNING: Can not remove symbolic link ${LNDIR}/${dir}"
                 fi
              fi
          done
fi
   

# Clean up files that may be generated
HAES_DIR="/usr/es/sbin/cluster"
rm -f ${HAES_DIR}/.mig
rm -f ${HAES_DIR}/.restore_routes
rm -f ${HAES_DIR}/.telinit
rm -f ${HAES_DIR}/server.status
rm -f ${HAES_DIR}/etc/ClSm
rm -f ${HAES_DIR}/etc/clpol
rm -f ${HAES_DIR}/.esmig
rm -f ${HAES_DIR}/etc/key_md5_3des
rm -f ${HAES_DIR}/etc/key_md5_aes
rm -f ${HAES_DIR}/etc/key_md5_des
rm -f ${HAES_DIR}/etc/config/clip_config

# Clean up directories that may be generated
rm -rf ${HAES_DIR}/etc/objrepos
rm -rf ${HAES_DIR}/etc/vg

exit $STATUS
