#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  Copyright (C) Altran ACT S.A.S. 2019,2020,2021.  All rights reserved.
#
#  ALTRAN_PROLOG_END_TAG
#
# @(#)  7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_snapshot.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM

# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_snapshot.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1990,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 

# 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_is_known_snapshot

=head1 SYNOPSIS

KLIB_HACMP_is_known_snapshot

=head1 DESCRIPTION

Determines if the specified snapshot exists on the local node.

=head1 ARGUMENTS

 1. snapshot [REQUIRED] [string]
    The name of the snapshot to search for on this node.

=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


=cut
} # End of POD-formatted documentation.


function KLIB_HACMP_is_known_snapshot {
    . $HALIBROOT/log_entry "$0()" "$CL"
    : version=@(#)  7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_snapshot.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
    : INPUTS: $*

    typeset snapshot=${1//\"/}

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

    #===================================
    : Declare and initialize variables
    #===================================
    typeset -i rc=$RC_UNKNOWN
    typeset -A list
    typeset name=

    #=================
    : Validate input
    #=================
    if [[ -z $snapshot ]]; then
        dspmsg -s $CLVT_SET $CLVT_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2
        rc=$RC_MISSING_INPUT

    else
        # Smit is not able to parse snapshot name when name has colon,
        # hence escaping : with readable characters.
        if [[ $CLMGR_GUI == "SMIT" ]];then
            snapshot=$(echo $snapshot | sed 's/:/#!:/g')
        fi

        print -- "$0()[$LINENO]($SECONDS): clsnapshot -l" >>$CLMGR_TMPLOG  # Always log commands
        clsnapshot -l |\
        while read name; do
            [[ $name == *([[:space:]])\#* ]] && continue
            if [[ -n $name ]]; then
                name=${name##+([[:space:]])}
                name=${name%%+([[:space:]])}

                if [[ "$name" == "$snapshot" ]]; then
                    rc=$RC_SUCCESS
                    break
                fi
            fi
        done
        (( $rc != RC_SUCCESS )) && rc=$RC_ERROR
    fi

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