#!/bin/bash

. /usr/local/lib/gce-funcs

while [ "$1" != "" ];
do
    case "$1" in
	--state)
	    DO_STATE=yes
	    ;;
	--results)
	    DO_RESULTS=yes
	    ;;
	--both|--all)
	    DO_STATE=yes
	    DO_RESULTS=yes
	    ;;
	*)
	    echo "Uknown option: $1"
	    exit 1
	    ;;
    esac
    shift
done

if test -z "$DO_STATE" -a -z "$DO_RESULTS" ; then
    echo "Please specify either --state or --results"
    exit 1
fi

if test -n "$DO_STATE" ; then
    tar -C /pts --exclude=fiofile -cJf /tmp/pts-state.tar.xz phoronix-test-suite
    gsutil cp /tmp/pts-state.tar.xz "gs://$GS_BUCKET/${instance}-state.tar.xz"
fi

if test -n "$DO_RESULTS" ; then
    tar -C /pts/phoronix-test-suite -cJf /tmp/pts-results.tar.xz test-results
    gsutil cp /tmp/pts-results.tar.xz "gs://$GS_BUCKET/${instance}-results.tar.xz"
fi

