#! /bin/bash

#
# Copyright (c) 2002 Compaq Computer Corporation.  All Rights Reserved.
#
# Permission to use, copy, and modify this software and its documentation
# is hereby granted under the following terms and conditions.  The above
# copyright notice, this permission notice, and the following disclaimer
# must appear in all copies of the software, derivative works or modified
# versions.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND COMPAQ COMPUTER CORP. DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL COMPAQ COMPUTER
# CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
#

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

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

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

#
# cpuinfo command and its location.
cpuinfocmd=cpuinfo_tru64_helper
cpuinfodir=${GLOBUS_LOCATION}/sbin
cpuinfo=${cpuinfodir}/${cpuinfocmd}

_probe_cache_tmp=${localstatedir}/cpu-cache-$$.tmp

# set mode for cache file
umask 077

cleanup ()
{
	rm -f "$_probe_cache_tmp" 
}

trap cleanup 0

cleanup

report_resource_cpu ()
{
	#
	if [ -x "${cpuinfo}" ]; then
		if [ ! "X${_probe_cache}" = "X" ]; then
			"${cpuinfo}" > "${_probe_cache_tmp}" 2>/dev/null
			mv "${_probe_cache_tmp}" "${_probe_cache}" 2>/dev/null
			eval `cat ${_probe_cache}`
		else
			eval `"${cpuinfo}"`
		fi
	else
		ldap_shell_log_error "$0: ${cpuinfocmd} does not exist."
		return 1
	fi

	emit_resource_cpu_descriptions
	return 0
}

#############
# do the work
report_resource_cpu

