#!/bin/ksh

#/* Part of the Maestro sequencer software package.
# * Copyright (C) 2011-2015  Operations division of the Canadian Meteorological Centre
# *                          Environment Canada
# *
# * Maestro is free software; you can redistribute it and/or
# * modify it under the terms of the GNU Lesser General Public
# * License as published by the Free Software Foundation,
# * version 2.1 of the License.
# *
# * Maestro is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# * Lesser General Public License for more details.
# *
# * You should have received a copy of the GNU Lesser General Public
# * License along with this library; if not, write to the
# * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# * Boston, MA 02111-1307, USA.
# */

#
usage='usage: node_resource -n node'

msgjob=' node resource file not available: '

if [ "${SEQ_EXP_HOME}" == "" ]; then
   echo "ERROR: SEQ_EXP_HOME not defined!\n"
   exit 1
fi

# echo usage if no parameters are passed
test $# = 0 && echo $usage && exit 1

case $1
in
  -h)# display help
     echo "$usage"
     exit 0
     ;;
  -n)
     if [ "$2" ]
     then
       node=$2
     else
       echo $usage
       exit 1
     fi
     ;;
   *)# default
     echo "$usage"
     exit 1
     ;;
esac

if [[ "${SEQ_BIN}" = "" ]]; then
   test $(which nodeinfo) || (echo nodeinfo not found; exit 1)
   resourcePath=$(nodeinfo -n $node -f res_path)
   nodeinfo -n $node -f res_path
else
   resourcePath=$($SEQ_BIN/nodeinfo -n $node -f res_path)
   $SEQ_BIN/nodeinfo -n $node -f res_path
fi

eval resourcePath=${resourcePath##*=}
if [[ -r ${resourcePath} ]] ; then
   cat ${resourcePath}
fi
