#!/bin/sh -e

##########################################################################
#   Script description:
#       Report the node type based on hostname
#       
#   History:
#   Date        Name        Modification
#   2020-12-31  Charlie &   Begin
##########################################################################

usage()
{
    printf "Usage: $0 [hostname]\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

LOCALBASE=$(cluster-localbase)

case $# in
0)
    if [ -e $LOCALBASE/etc/spcm/my-node-type ]; then
	cat $LOCALBASE/etc/spcm/my-node-type
    fi
    ;;

1)
    if [ -e $LOCALBASE/etc/spcm/node-types ]; then
	short_host=$(echo $1 | cut -d . -f 1)
	awk -v hostname=$short_host '$1 == hostname { print $2 }' \
	    $LOCALBASE/etc/spcm/node-types
    fi
    ;;

*)
    usage
    ;;

esac
