# -*- mode: shell-script -*-
prefix=/opt/pbench-agent

if [[ ! -f ${prefix}/profile ]]
then
    if [[ -f ${PWD}/profile ]]
    then
	prefix=$PWD
    else
	# last ditch attempt
	prefix=$TOP
    fi
fi

pathins() {
    if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
        PATH="$1:$PATH"
    fi
}

if [[ ! -f ${prefix}/util-scripts/pbench-register-tool-set ]]
then
    echo "*** WARNING *** Something wrong in the pbench base profile:" >&2
    echo "                Setup has failed - could not determine the proper environment prefix: \"$prefix\"" >&2
    echo "                You will need to fix it before working with pbench." >&2
else
    export PYTHONPATH=${prefix}/lib:${PYTHONPATH}
    export _PBENCH_AGENT_CONFIG=${prefix}/config/pbench-agent.cfg

    pathins ${prefix}/bench-scripts
    pathins ${prefix}/util-scripts
fi

unset prefix
unset -f pathins
