#!/bin/bash

script_path=`dirname $0`
script_name=`basename $0`
pbench_bin="`cd ${script_path}/..; /bin/pwd`"

# source the base script
. "$pbench_bin"/base

# This is a wrapper script to allow sysinfo-dump to be invoked remotely
# sending on stdout the contents of the sysinfo tar ball, capturing all
# other output and emitting that on stderr.

sysinfo_path=$1
sysinfo=$2
label=$3

mkdir -p $sysinfo_path
if [ ! -d $sysinfo_path ]; then
	echo "Failed to create $sysinfo_path" >&2
	exit 1
fi

pbench-sysinfo-dump $sysinfo_path "$sysinfo" $label
if [ $? -ne 0 ]; then
	echo "\"pbench-sysinfo-dump $sysinfo_path $label\" failed!" >&2
	exit 1
fi

cd $sysinfo_path >&2
echo "pbench-sysinfo-dump data size: $(du -sm $sysinfo_path | awk '{print $1}') MB" >&2
tar cf - *
exit_status=$?
rm -rf $sysinfo_path >&2
exit $exit_status
