#! /bin/bash
#
# Copyright (c) 2002-2003 Northwestern University
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#
# NOTE: You MUST export the location of the output .html file
# generated by running the teragrid-setup-test script written
# by Jim Basney.
#
# It must be exported in env. var TSHTML_OUTPUT
# e.g. TSHTML_OUTPUT=/teragrid-info/output.html


# If TSHTML_OUTPUT is defined, use it
if [ ! "x${TSHTML_OUTPUT}" = "x" ]; then
    INPUT_FILE=${TSHTML_OUTPUT}
else

    # 3) Use a hard-coded default
    INTPUT_FILE="index.html"
fi

# Make sure this is pointing to the correct corresponding perl script
GRID_INFO_TERAGRIDSETUP_POSIX_PL="/opt/globus/libexec/grid-info-teragridsetup-posix"

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

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

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


emit_teragrid_setup_summary ()
{
    if [ ! "x$1" = "x" ] && [ ! "x$2" = "x" ]; then
        ${GLOBUS_SH_PERL-perl} ${GRID_INFO_TERAGRIDSETUP_POSIX_PL} -s $1 $2 ${INPUT_FILE}
    else
        echo "Cannot emit data without proper inputs!"
        echo "Please re-configure your MDS installation."
    fi
}

emit_teragrid_setup_descriptions ()
{
    probe_mds_object_timestamps
    emit_mds_object_timestamps > ${timestamp_loc}

    if [ "X${_dump_devclass_object}" = "Xtrue" ]
    then
        emit_teragrid_setup_summary "${_suffix}" "${timestamp_loc}"
    fi

    if [ "X${_dump_dev_objects}" = "Xtrue" ]
    then
        emit_teragrid_setup_details "${_suffix}" "${timestamp_loc}"
    fi

    rm -f ${timestamp_loc}
}

emit_teragrid_setup_details ()
{
    ${GLOBUS_SH_PERL-perl} ${GRID_INFO_TERAGRIDSETUP_POSIX_PL} $1 $2 ${INPUT_FILE}
}

probe_teragrid_setup ()
{
    # need a tmp file to stash timestamps in
    timestamp_loc="/tmp/__tmstmp.tmp"

    emit_teragrid_setup_descriptions
}

#############
# do the work
probe_teragrid_setup

