#!/bin/bash

set -e

if [[ -f /etc/default/ngcp-roles ]]; then
  # shellcheck disable=SC1091
  . /etc/default/ngcp-roles
fi
if [[ -f /etc/default/ngcp-ha ]]; then
  # shellcheck disable=SC1091
  . /etc/default/ngcp-ha
fi

# If we are on a NGCP CE node, we assume no HA, otherwise we default to the
# only HA currently supported.
case "${NGCP_TYPE}" in
  sppro|carrier)
    HACRM=${NGCP_HA_CRM:-pacemaker}
    ;;
  *)
    HACRM='none'
    ;;
esac

# Check whether we have the expected interfaces.
case "${HACRM}" in
  pacemaker)
    if ! which crm >/dev/null; then
      echo "error: missing pacemaker CRM" >&2
      exit 2
    fi
    ;;
esac

echo "${HACRM}"
