#! /bin/bash
#
# ST - 2012-05-15
#
# Create and start the front end.
#
# Get the directory of the script.
SCRIPT_PATH=`dirname $0`
# Get the script name.
SCRIPT_NAME=`basename $0`
# Source the common configuration variables.
. $SCRIPT_PATH/c-i-a-b.common
#
# Output file stuff: we write all the output to file descriptor #5
# If no argument is given to the script descriptor #5 is redirected to 
# STDOUT (descriptor #1)
# If an argument is given, output is rediected to the file having
# the name of the argument.
#
if [ "x$1" == "x" ] ; then
  exec 5>&1
else
  exec 5> $1
fi
# Localhost stuff.
echo "127.0.0.1 localhost" 1>&5
# Compute nodes stuff.
CNCSNP=1
for CNCSNP in `seq 1 $CONST_COMPUTE_NODE_MAX_NUM`  ; do
  echo -n "${CLUSTER_STATIC_NETWORK_PREFIX}.${CNCSNP} " 1>&5
  CNCSNP_STRING=$CNCSNP
  while [ ${#CNCSNP_STRING} -lt 3 ] ; do
    CNCSNP_STRING=0$CNCSNP_STRING
  done
  echo -n "${COMPUTE_NODE_NAME_PREFIX}${CNCSNP_STRING}.${CLUSTER_DOMAIN_NAME} " 1>&5
  echo "${COMPUTE_NODE_NAME_PREFIX}${CNCSNP_STRING}" 1>&5
done
# Front-end stuff.
echo -n "${CLUSTER_STATIC_NETWORK_PREFIX}.${CONST_FRONT_END_CLUSTER_STATIC_NETWORK_POSTFIX} " 1>&5
echo -n "${FRONT_END_CLUSTER_HOST_NAME}.${CLUSTER_DOMAIN_NAME} " 1>&5
echo "$FRONT_END_CLUSTER_HOST_NAME" 1>&5
# Compute node model stuff.
echo -n "${CLUSTER_STATIC_NETWORK_PREFIX}.${CONST_COMPUTE_NODE_MODEL_CLUSTER_STATIC_NETWORK_POSTFIX} " 1>&5
echo -n "${COMPUTE_NODE_MODEL_CLUSTER_HOST_NAME}.${CLUSTER_DOMAIN_NAME} " 1>&5
echo "$COMPUTE_NODE_MODEL_CLUSTER_HOST_NAME" 1>&5
#
# IPv6 stuff
echo "#" 1>&5
echo "# The following lines are desirable for IPv6 capable hosts" 1>&5
echo "::1 ip6-localhost ip6-loopback" 1>&5
echo "fe00::0 ip6-localnet" 1>&5
echo "ff00::0 ip6-mcastprefix" 1>&5
echo "ff02::1 ip6-allnodes" 1>&5
echo "ffO2::2 ip6-allrouters" 1>&5
exec 5>&-
exit 0
