#!/bin/sh

export RELEASE_DISTRIBUTION="${RELEASE_DISTRIBUTION:-name}"

if [ -z "${RELEASE_NODE:-}" ]; then
  if [ -n "${CLUSTER_INTERFACE:-}" ]; then
    release_ip=$(
      ip -o -4 address show dev "$CLUSTER_INTERFACE" scope global |
        awk 'NR == 1 {sub(/\/.*/, "", $4); print $4}'
    )

    if [ -z "$release_ip" ]; then
      echo "No global IPv4 address found on CLUSTER_INTERFACE=$CLUSTER_INTERFACE." >&2
      exit 1
    fi
  else
    release_ip=$(hostname -i)
    release_ip=${release_ip%% *}
  fi

  export RELEASE_NODE="who_need_help@$release_ip"
  unset release_ip
fi
