#! /bin/bash

# default libexecdir used to bootstrap scripts
libexecdir=${GLOBUS_LOCATION}/libexec

# load GRIS common code and initialization
. ${libexecdir}/grid-hostinfo-fs-common

#########################################################################

probe_resource_fs ()
{
    mounts=
    case "${_fs_type}" in
	scratch)
	    i=0
	    while [ $i -lt ${_fs_count} ]
	    do
		eval "mounts=\"$mounts \${_fs_${i}_mount}\""
		i=`$EXPR $i + 1`
	    done
	;;
    esac

    ${GRID_INFO_SH_DF_POSIX_KB} $mounts | \
    {
	i=0
	read header
	while read fs cap used avail percent mount
	do
	    if [ "X$cap" = "X" ]
	    then
		# assume multi-line format
		read cap used avail percent mount
	    fi
	    size_mbytes=`$EXPR $cap / 1024`
	    free_mbytes=`$EXPR $avail / 1024`
	    eval "_fs_${i}_size_mbytes=${size_mbytes}"
	    eval "_fs_${i}_free_mbytes=${free_mbytes}"
	    eval "_fs_${i}_mount=\"${mount}\""
	    _fs_total_size_mbytes=`$EXPR ${_fs_total_size_mbytes} + ${size_mbytes}`
	    _fs_total_free_mbytes=`$EXPR ${_fs_total_free_mbytes} + ${free_mbytes}`
	    i=`$EXPR $i + 1`
	done
	case "${_fs_type}" in
	    scratch) : ;;
	    *) _fs_count=$i ;;
	esac

	# run this in initialized subshell environment
	emit_resource_fs_descriptions
    }
}

#############
# do the work
probe_resource_fs
