#!/bin/bash

if [ -n "$SSH_CONNECTION" ] && \
   [ -n "$SSH_TTY" ]; then
  ### Include ymclibnettools
  . /usr/lib/lib-fliwi/ymc-networktools.bash
  force_use_hostname=$1
  force_use_clusterid=$2

  ymc_connected_to_name=$(hostname -s)
  if [ "$force_use_hostname" != 'force_use_hostname' ]; then
    TEMP_YMC_SSH_TARGET_IP=$(echo $SSH_CONNECTION | cut -d ' ' -f 3 | sed -r 's/[^0-9.]//g')
    if [ -n "$TEMP_YMC_SSH_TARGET_IP" ]; then
      temp_ptr_lookup=$(ymc_get_ptr_full_hostname_for_ip $TEMP_YMC_SSH_TARGET_IP)
      if [ $? -eq 0 ] && \
         [ -n "$temp_ptr_lookup" ]; then
        ymc_connected_to_name=$(echo $temp_ptr_lookup | cut -d '.' -f 1)
      fi
    fi
  fi

  ymc_prefix=$(ymc_caluclated_cluster_id)
  if [ "$force_use_clusterid" != 'force_use_clusterid' ]; then
    temp_txt_lookup=$(dig +short TXT cluster-shortest-possible-name.basics)
    if [ $? -eq 0 ] && \
       [ -n "$temp_txt_lookup" ]; then
      temp_txt_lookup=$(echo $temp_txt_lookup | sed -r 's/[^0-9a-zA-Z_-]+//g')
      if [ -n "$temp_txt_lookup" ]; then
        ymc_prefix="$temp_txt_lookup"
      fi
    fi
  fi

  echo -ne "\033]0;$ymc_prefix:$ymc_connected_to_name\007"
fi






