#!/bin/sh

. /opt/webservice/install/deployment.properties

deployment=`/opt/webservice/scripts/gethaipsetupentry.sh system.multiNodeSystem`
rc=$?
if [ "${rc}" != "0" ]; then
 echo "System is not a valid OpenScape 4000 installation"  >&2
 exit -1
fi 

sg_flag=`/opt/webservice/scripts/gethaipsetupentry.sh system-hidden.softGate`
# default is: no softgate
rc=0


if [ "${sg_flag}" != "" ]; then
  if [ "${sg_flag}" = "0" ]; then
    rc=0
  else
    rc=1
    # for Duplex only the Q can have a Softgate
    /opt/webservice/scripts/is_duplex >/dev/null
    node_is_duplex=$?
    if [ "${node_is_duplex}" = "0" ]; then
      # On Simplex the system-hidden.softGate can be taken immediately
      true
    else
      # Duplex check if Q
      /opt/webservice/scripts/is_quorum >/dev/null
      node_is_quorum=$?
      if [ "${node_is_quorum}" = "0" ]; then
        # a node_1 or node_2 of a Duplex can never have a SG
        echo "deployment has an active SoftGate according to haipsetup.xml, but central duplex host forces to false"
        rc=0
      else
        # we are on a Q, system-hidden.softGate can be taken
        true
      fi
    fi
  fi
fi


if [ ${rc} == "0" ]; then
    echo "deployment has no active SoftGate according to haipsetup.xml"
else
    echo "deployment has an active SoftGate according to haipsetup.xml"
fi

exit $rc
