#!/bin/sh
####################################################################
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development, LP.
# (C) Copyright 2006-2015 Hewlett-Packard Development Company, L.P.
# @(#) Product Name                :  HP Serviceguard
# @(#) Product Version             :  A.12.10.00
# @(#) Patch Name                  :  
#
###################################################################
#
# Shell script for the cmdisklockcheck command.
#
# Description:  cmdisklockcheck is a wrapper script for checking the
#               current state of the cluster lock disk, if any.
#               It is used as part of cmapplyconf(1m).
#
# Returns:         0       if successful
#                  1       if failed
#
#
# (C) Copyright 2006-2006 Hewlett-Packard Development Company, L.P.
#

. /etc/cmcluster.conf

CONF_DATA=`${SGSBIN}/cmviewcl -s config -v -f line | grep '_lock|'`
if [ $? -ne 0 ]
then
    exit 1
fi

function get_config_value {
    echo "$CONF_DATA" | grep $1 | cut -f2 -d'='
}

function check {
    ${SGSBIN}/cmdisklock check $1
    if [ $? != 0 ]
    then
        exit 1
    fi
}

HOSTNAME=$(hostname)
LOCAL_NODE=${HOSTNAME%%\.*}

PATTERN='^first_cluster_lock|volume_group='
VG=`get_config_value $PATTERN`
if [ "X$VG" != "X" ]
then
    PATTERN="^first_cluster_lock|node:${LOCAL_NODE}|physical_volume="
    PV=`get_config_value $PATTERN`
    check $VG:$PV
fi

PATTERN='^second_cluster_lock|volume_group='
VG=`get_config_value $PATTERN`
if [ "X$VG" != "X" ]
then
    PATTERN="^second_cluster_lock|node:${LOCAL_NODE}|physical_volume="
    PV=`get_config_value $PATTERN`
    check $VG:$PV
fi

PATTERN="^cluster_lock|node:${LOCAL_NODE}|lun="
LUN=`get_config_value $PATTERN`
if [ "X$LUN" != "X" ]
then
    check $LUN
fi

exit 0
