#!/bin/sh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/bin/cdat/types/psrasremove/psrasremove.sh 1.3 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 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 

phase_check()
{
    # Only AIX LPARs are valid CA clients
    [ "$CDAT_TYPE" = 'LPAR' ] || {
        mlog -1 "psrasremove is not supported on $CDAT_TYPE"
        exit 1	# IGNORE
    }

    # Check that the pureScale.client.rte fileset is installed
    fileset="pureScale.client.rte"
    remote_cmd "/usr/bin/lslpp -lq $fileset 2> /dev/null | grep -wq COMMITTED"
    [ $? -ne 0 ] && {
        mlog -1 "Fileset $fileset not installed on $CDAT_HOST"
        exit 1	# IGNORE
    }

    # Check that we have the ibm.ps.client.bind authorization required by
    # "psbind remove".
    remote_cmd "/usr/bin/ckauth -A ibm.ps.client.bind"
    [ $? -ne 0 ] && {
        mlog -1 "ibm.ps.client.bind authorization required"
        exit 1	# IGNORE
    }
}

phase_init()
{
    # Install our client unconfiguration script onto the remote node
    push_file "$CDAT_TYPE_DIR/unconfig.sh" /tmp/ca_unconfig.sh
    [ $? -ne 0 ] && {
        mlog -1 "Cannot install configuration script on $CDAT_HOST"
	exit 128
    }
}

phase_execute()
{
    # Run our unconfiguration script
    remote_cmd "/bin/sh /tmp/ca_unconfig.sh"
    [ $? -ne 0 ] && {
        mlog -1 "Configuration script failed on $CDAT_HOST"
	exit 128
    }
}

phase_clean()
{
    # Remove our unconfiguration script from the remote node
    remote_cmd "rm -f /tmp/ca_unconfig.sh"
}

PATH=$CDAT_SRVC_DIR:${PATH}

case $CDAT_PHASE in
check)
    phase_check
    ;;
init)
    phase_init
    ;;
execute)
    phase_execute
    ;;
clean)
    phase_clean
    ;;
esac

exit 0
