#!/bin/bash

_realpath=$(realpath ${0})
_dirname=$(dirname ${_realpath})
_basename=$(basename ${0})
if [[ ! ":${PATH}:" =~ ":${_dirname}:" ]]; then
   PATH=${_dirname}${PATH:+:}${PATH}; export PATH
fi
if command -v python3.9 > /dev/null 2>&1 ;then
    _pythoncmd=""
else
    printf -- "${_basename}: pbench-trampoline needs python3.9\n" >&2
    exit 1
fi
_installdir=$(dirname ${_dirname})
export PYTHONPATH=${_installdir}/lib:${_installdir}/lib/python3.9/site-packages:${_installdir}/lib64/python3.9/site-packages:${PYTHONPATH}
if [[ -e ${_dirname}/${_basename}.py ]]; then
    # We don't use pbench-base.py to invoke python programs, they can use the
    # PbenchConfig class directly.
    ${_pythoncmd} ${_dirname}/${_basename}.py ${@}
else
    export PROG=${_basename}
    export dir=${_dirname}
    ${_pythoncmd} ${_dirname}/pbench-base.py ${0} ${@}
fi
