#!/bin/bash
####################################################################
# (C) Copyright 2007-2015 Hewlett-Packard Development Company, L.P.
# @(#) Serviceguard feature verification script
# @(#) Product Name              :  HP Serviceguard
# @(#) Product Version           :  A.12.10.00
# @(#) Patch Name                :  
####################################################################

# Do not modify or delete.
# This script is used to verify required features are installed
# within the cluster. The script is called with a list of feature
# names and exits with non-zero to indicate that one or more of the
# features are not available. Alternatively, the script may exit with
# zero, indicating that all required features are available.

. /etc/cmcluster.conf

PATH="/usr/bin:/bin:/sbin:/usr/sbin"
export PATH

erac_script="/usr/sbin/gmscheckfeature"
erac_arg="sites"
erac_msg="SGeRAC subclustering functionality is not installed."

mcrac_script="/opt/drenabler/utils/mccheckfeature"
mcrac_arg="Site_Controller"
mcrac_msg="Metrocluster Site Controller feature is not installed"
license_linux_msg="Required licenses are not installed. 
To configure a site aware cluster, an Enterprise license 
is required. You can order HP Serviceguard for Linux through 
formal HP channels. Please contact the account team for further details.
For more information on Serviceguard for Linux, please visit:
http://www.hp.com/go/sglx" 

print_mcrac_msg=0

(( return_value = 0 ))

ostype=$(uname)

for feature in $*
do
    case $feature in

	sites)
	    # Sites are supported on both HP-UX and Linux. 
	    ;;

	cross-subnet)
	    # Cross subnet is supported on both HP-UX and Linux
	    ;;
	
        erac-subclusters) 
	    if [[ -z "$SG_ALLOW_SITES" ]]; then
		if [[ $ostype = "HP-UX" ]]; then
		    
		    # Verify SGeRAC subclustering is installed
		    if [ -x $erac_script ]; then
			if ! $erac_script $erac_arg > /dev/null
			then
			    echo "$erac_msg"
			    (( return_value = 1 ))
			fi
		    else
			echo "$erac_msg"
			(( return_value = 1 ))
		    fi
		else
		    echo "SGeRAC subclustering functionality is only supported on HP-UX"
		    (( return_value = 1))
		fi
	    fi
	    ;;

        mcrac)
	    if [[ $ostype = "HP-UX" ]]; then 
               if [[ -z "$SG_ALLOW_SITES" ]]; then
               # Verify MetroRAC functionality is available
                  if [ -x $mcrac_script ]; then
                     if ! $mcrac_script $mcrac_arg > /dev/null
                     then
                        print_mcrac_msg=1
                     fi
                  else
                     print_mcrac_msg=1
                  fi
            
                  if [ 1 -eq "$print_mcrac_msg" ]; then
                     echo "$mcrac_msg"
                     (( return_value = 1 )) 
                  fi
               fi 
            else
                # Check only if product bits  
                lic_check=`$SGSBIN/cmgetlicense -f line`
                if [[ $? -ne 99 ]]
                then
                    license_type=`echo "$lic_check" | head -n 1 | cut -f 2 -d '='` 
                    if [[ "$license_type" != "Enterprise" && "$license_type" != "Instant_ON" && "$license_type" != "Temporary" ]]
                    then 
                       echo "$license_linux_msg"
                       (( return_value = 1 )) 
                    fi  
                fi
	    fi
	    ;;

	*)  
	    echo "Feature not installed"
	    (( return_value = 1 ))
	    ;;
    esac
done

exit $return_value

