#!/bin/bash

# Adds a gear to the haproxy configuration.

# Exit on any errors
set -e

source "/etc/openshift/node.conf"
source ${CARTRIDGE_BASE_PATH}/abstract/info/lib/util

CART_NS=$(get_cartridge_namespace_from_path)

list=
kvargs=$(echo "${@:4}" | tr -d "\n" )
for arg in $kvargs; do
    ip=$(echo "$arg" | cut -f 2 -d '=' | tr -d "'")
    ip=`echo "$ip" | sed "s/:/[/g"`
    if [ -z "$list" ]; then
        list="$ip]"
    else
        list="$list,$ip]"
    fi
done

echo "export OPENSHIFT_${CART_NS}_REMOTING=$list" > /var/lib/openshift/$3/.env/OPENSHIFT_${CART_NS}_REMOTING

