#!/bin/bash

# @file ralf
#
# Copyright (C) Metaswitch Networks 2015
# If license terms are provided to you in a COPYING file in the root directory
# of the source code repository by which you are accessing this code, then
# the license outlined in that COPYING file applies to your use.
# Otherwise no rights are granted except for those provided to you by
# Metaswitch Networks in a separate written agreement.

ralf_listen_port=3869
ralf_secure_listen_port=5659
acl_required=false
check_destination_host=true
ralf_diameter_watchdog_timer=6
. /etc/clearwater/config

# Allow a specific FQDN for Ralf to be set (in case this is an
# all-in-one node running both ralf and homestead Diameter stacks).
# Otherwise, fall back to the public hostname.

identity=$ralf_diameteridentity

if [ -n "$ralf_hostname" ] && [ -n "$public_hostname" ];
then
  if [[ -z "$identity" ]];
  then
    identity=$public_hostname
  fi

  # Strip any characters not valid in an FQDN out of ralf_hostname (for
  # example, it might be an IPv6 address)
  realm=$(echo $ralf_hostname | sed -e 's/:[^:]*$//g' | sed -e 's/^\[//g' | sed -e 's/\]$//g')
  /usr/share/clearwater/bin/generic_create_diameterconf ralf $identity $realm $ralf_listen_port $ralf_secure_listen_port $acl_required $check_destination_host $ralf_diameter_watchdog_timer
fi
