#! /bin/bash

#
# Copyright (c) 2002 Hewlett-Packard Company.  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 HEWLETT-PACKARD CO. DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL HEWLETT-PACKARD
# COMPANY 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-hostinfo-cpu-common

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

#
# cpuinfo command
cpuinfo=${sbindir}/grid_info_cpu_hpux_helper

_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 build was successful, run executable and set up shell vars.
	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: ${cpuinfo} does not exist."
		return 1
	fi

	emit_resource_cpu_descriptions
	return 0
}

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