#!/bin/sh

#
#	Phoronix Test Suite "Trondheim"
#	URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
#	Copyright (C) 2008, Phoronix Media
#	Copyright (C) 2008, Michael Larabel
#	phoronix-test-suite: The Phoronix Test Suite is an extensible open-source testing platform for Linux.
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 3 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# Full path to root directory of the actual Phoronix Test Suite code
export PTS_DIR=`pwd`

if [ $PTS_DIR != `pwd` ]
then
	cd $PTS_DIR
fi

# Location to save results, download cache, results viewer, etc. Must have trailing slash.
export PTS_USER_DIR=$HOME'/.phoronix-test-suite/'

# Determine PHP binary location
if [ -x /usr/bin/php5 ] || [ -x /usr/local/bin/php5 ]
then
	export PHP_BIN="php5"
elif [ -x /usr/bin/php ] || [ -x /usr/local/bin/php ]
then
	export PHP_BIN="php"
else
	export PHP_BIN=""
fi

# Make sure PHP is installed
if [ "X$PHP_BIN" = "X" ]
then
	cat <<'EOT'

PHP5 CLI Must Be Installed To Run The Phoronix Test Suite!
Only PHP For The Command Line Is Needed, Not A Complete PHP w/ Web Server Installation
The PHP CLI package is usually called php-cli or php5-cli. Also required is the PHP GD library (php-gd)
For support visit: http://www.phoronix.com/forums/forumdisplay.php?f=49

EOT
exit
fi


case "$1" in
"install")
	$PHP_BIN pts-core/pts-run-cmd.php INSTALL_BENCHMARK $2
	;;
"force-install")
	$PHP_BIN pts-core/pts-run-cmd.php FORCE_INSTALL_BENCHMARK $2
	;;
"install-dependencies")
	$PHP_BIN pts-core/pts-run-cmd.php INSTALL_EXTERNAL_DEPENDENCIES $2
	;;
"install-all")
	$PHP_BIN pts-core/pts-run-cmd.php INSTALL_ALL
	;;
"force-install-all")
	$PHP_BIN pts-core/pts-run-cmd.php FORCE_INSTALL_ALL
	;;
"run")
	$PHP_BIN pts-core/pts-run-benchmark.php $2
	;;
"batch-run")
	$PHP_BIN pts-core/pts-run-benchmark.php $2 BATCH
	;;
"benchmark")
	export SILENT_INSTALL=1
	$PHP_BIN pts-core/pts-run-cmd.php INSTALL_BENCHMARK $2
	$PHP_BIN pts-core/pts-run-benchmark.php $2
	;;
"batch-benchmark")
	export SILENT_INSTALL=1
	$PHP_BIN pts-core/pts-run-cmd.php INSTALL_BENCHMARK $2
	$PHP_BIN pts-core/pts-run-benchmark.php $2 BATCH
	;;
"merge-results")
	$PHP_BIN pts-core/pts-run-cmd.php MERGE_RESULTS $2 $3 $4
	;;
"remove-result")
	$PHP_BIN pts-core/pts-run-cmd.php REMOVE_RESULT $2
	;;
"remove-all-results")
	$PHP_BIN pts-core/pts-run-cmd.php REMOVE_ALL_RESULTS
	;;
"upload")
	$PHP_BIN pts-core/pts-run-cmd.php UPLOAD_RESULT $2
	;;
"make-download-cache")
	$PHP_BIN pts-core/pts-run-cmd.php MAKE_DOWNLOAD_CACHE
	;;
"list-tests")
	$PHP_BIN pts-core/pts-run-cmd.php LIST_TESTS
	;;
"list-suites")
	$PHP_BIN pts-core/pts-run-cmd.php LIST_SUITES
	;;
"list-possible-dependencies")
	$PHP_BIN pts-core/pts-run-cmd.php LIST_POSSIBLE_EXTERNAL_DEPENDENCIES
	;;
"list-installed-tests")
	$PHP_BIN pts-core/pts-run-cmd.php LIST_INSTALLED_TESTS
	;;
"list-results" | "list-saved-results")
	$PHP_BIN pts-core/pts-run-cmd.php LIST_SAVED_RESULTS
	;;
"show-result")
	$PHP_BIN pts-core/pts-run-cmd.php SHOW_RESULT $2
	;;
"info" | "suite-info" | "suite-information" | "test-info" | "test-information")
	$PHP_BIN pts-core/pts-run-cmd.php INFO $2
	;;
"system-info" | "system-information")
	$PHP_BIN pts-core/pts-run-cmd.php SYS_INFO
	;;
"sensors")
	export MONITOR=all
	$PHP_BIN pts-core/pts-run-cmd.php SENSORS
	;;
"sensor-options")
	$PHP_BIN pts-core/pts-run-cmd.php SENSOR_OPTIONS
	;;
"diagnostics")
	$PHP_BIN pts-core/pts-run-cmd.php DIAGNOSTICS_DUMP
	;;
"initial-config")
	$PHP_BIN pts-core/pts-run-cmd.php INITIAL_CONFIG
	;;
"version")
	$PHP_BIN pts-core/pts-run-cmd.php VERSION
	;;
"login")
	$PHP_BIN pts-core/pts-run-cmd.php LOGIN
	;;
"batch-setup")
	$PHP_BIN pts-core/pts-run-cmd.php BATCH_SETUP
	;;
"refresh-graph" | "refresh-graphs")
	$PHP_BIN pts-core/pts-run-cmd.php REFRESH_GRAPHS $2
	;;
*)
	cat <<'EOT'

=================================
Phoronix Test Suite
URL: http://www.phoronix-test-suite.com/
=================================

Installation Options:
	install <suite / test>: Install or update the specified suite/test(s)
	install-dependencies <suite / test>: Install the external (distribution-level) dependencies
	install-all: Install or update all available tests
	list-installed-tests: List all tests that are installed

Testing Options:
	benchmark <suite / test / saved file / Global ID>: Install and then run the test(s)
	run <suite / test / saved file / Global ID>: Run the specified test(s)
	list-tests: List all tests and relevant information
	list-suites: List all suites and relevant information

Batch Testing Options:
	batch-setup: Setup the batch mode options
	batch-run <suite OR test>: Run the specified test(s) in batch mode
	batch-benchmark <suite OR test OR saved file>: Install and run the test(s) in batch mode

Result Viewing Options:
	list-results: List all saved results
	show-result <saved name>: Show this result file in your web browser
	remove-result <saved name>: Remove this saved result file
	remove-all-results: Removes all saved results
	merge-results <saved Name 1 / Global ID> <saved Name 2 / Global ID> <save name>: Merge two sets of results
	upload <saved name>: Upload a saved set of results to PTS Global
	login: Enter your PTS Global log-in information for uploading results

Miscellaneous Options:
	make-download-cache: Backup all downloaded test files to ~/.phoronix-test-suite/download-cache/
	info <suite / test>: Show detailed information about a test or suite
	system-info: Show detected software and hardware information
	sensor-options: Show system sensors that can be monitored
	diagnostics: Useful information when reporting a bug or problem
	version: Print the Phoronix Test Suite version and code-name
EOT
	;;
esac
