#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r721 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_respond_site.sh 1.2.1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2013,2016 
# 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 
# @(#)77	1.2.1.1  src/43haes/lib/ksh93/hacmp/KLIB_HACMP_respond_site.sh, hacmp.assist, 61haes_r721, 1612A_hacmp721 3/10/16 01:03:26

#================================================
# The following, commented line enforces coding
# standards when this file is edited via vim.
#================================================
# vim:tabstop=4:shiftwidth=4:expandtab:smarttab
#================================================

# Start of POD-formatted documentation. Viewing suggestions:
#      perldoc <FILENAME>
#      pod2text -c <FILENAME>
#      pod2text -c --code <FILENAME>
#      pod2html <FILENAME>
function devDoc {
    : <<'=cut' >/dev/null 2>&1

=head1 NAME

KLIB_HACMP_respond_site

=head1 VERSION

 Version Number:  1.2.1.1
 Last Extracted:  3/23/16 01:09:00
 Last Changed:    3/10/16 01:03:26

 Path, Component, Release(, Level):
 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_respond_site.sh, hacmp.assist, 61haes_r721, 1612A_hacmp721

=head1 SYNOPSIS

clmgr manage site respond {continue|recover}

=head1 DESCRIPTION

Allows a manual response to a split or merge event.

=head1 ARGUMENTS

1. response [REQUIRED] [set]

   The response to take for a split or merge event.

   Valid values: continue, recover

=head1 RETURN

 0: no errors were detected; the operation appears to have been successful
 1: a general error has occurred
 2: a specified resource does not exist, or could not be found
 3: some required input was missing
 4: some detected input was incorrect in some way
 5: a required dependency does not exist
 6: a specified search failed to match any data

=head1 COPYRIGHT

COPYRIGHT International Business Machines Corp. 2013
All Rights Reserved

=cut
} # End of POD-formatted documentation.


function KLIB_HACMP_respond_site {
    LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL"
    : version=1.2.1.1, src/43haes/lib/ksh93/hacmp/KLIB_HACMP_respond_site.sh, hacmp.assist, 61haes_r721, 1612A_hacmp721
    : INPUTS: $*

    typeset -l response=${1//\"/}

    [[ $CLMGR_LOGGING == 'med' ]] && set +x  # Only trace param values

    #===================================
    # Declare and initialize variables
    #===================================
    typeset -i rc=$RC_UNKNOWN

    #=================
    # Validate input
    #=================
    if [[ $response == *([[:space:]]) ]]; then
        /usr/bin/dspmsg -s $CLVT_SET $CLVT_MSGS 101 "\nERROR: this operation requires the \"%1\$s\" attribute.\n\n" NETWORK 1>&2
        rc=$RC_MISSING_INPUT
    else
        CL=$LINENO verify_in_set RESPONSE "$response" "Continue, Recover" response
        (( $? != RC_SUCCESS )) && rc=$RC_INCORRECT_INPUT
    fi

    if (( rc == RC_UNKNOWN )); then
        #============================================
        : Handle the response, $response, if needed
        #============================================
        typeset continue=$(dspmsg -s 58 cluster.cat 77 'Continue\n')
        cl_smm_check >$TMPDIR/clmgr.KHrs.$$ 2>&1
        rc=$?
        if (( $rc != RC_SUCCESS )); then
            if (( rc == RC_NOT_FOUND )); then
                # No manual response was required
                rc=$RC_INCORRECT_INPUT
                cat $TMPDIR/clmgr.KHrs.$$
            else
                rc=$RC_ERROR
                cat $TMPDIR/clmgr.KHrs.$$ 1>&2
            fi

        elif [[ $response == $continue ]]
        then
            #
            :   This node *is* part of the chosen surviving site
            #
            CL=$LINENO cl_dspmsg -s 58 cluster.cat 79 "You have chosen for this side of the partitioned cluster to continue. You must now specify, on a node on the other side of the partitioned cluster, that it recover for PowerHA SystemMirror to completely recover from the split or merge."
            /usr/es/sbin/cluster/utilities/cl_sm_continue # you win some
            rc=$?

        else
            #
            :   This node is *not* part of the chosen surviving site
            #
            CL=$LINENO cl_dspmsg -s 58 cluster.cat 80 "You have chosen for this side of the partitioned cluster to recover. You must now specify, on a node on the other side of the partitioned cluster, that it continue for PowerHA SystemMirror to completely recover from the split or merge."
            /usr/es/sbin/cluster/utilities/cl_sm_recover # you lose some
            rc=$?
        fi

        [[ -f $TMPDIR/clmgr.KHrs.$$ ]] && rm -f $TMPDIR/clmgr.KHrs.$$
    fi

    log_return_msg "$rc" "$0()" "$LINENO"
    return $?
} # End of "KLIB_HACMP_respond_site()"
