#!/bin/bash
set -u

# Try to get the correct version of the 'p4' client.
# If we can't be sure we have it, see if a reasonable
# default can be found.

if [[ -n "${SDP_INSTANCE:-}" && -n "${P4HOME:-}" ]]; then
   exec "${P4HOME}/bin/p4_${SDP_INSTANCE}" "$@"
   exit $?
elif [[ -x "/p4/sdp/helix_binaries/p4" ]]; then
   exec /p4/sdp/helix_binaries/p4 "$@"
   exit $?
else
   echo -e "\\nError: The SDP shell environment is not setup. The correct version of p4 cannot be determined."
   exit 1
fi