#!/bin/sh
MYPATH="$(readlink -f "$0")"
NV_AGORA_PATH="$(dirname "$MYPATH")"
export NV_AGORA_PATH
export LD_LIBRARY_PATH="$NV_AGORA_PATH:$LD_LIBRARY_PATH"

if nm -D /lib64/libk5crypto.so.3 2>/dev/null | grep 'U\s\+EVP_KDF_ctrl' >/dev/null; then
  echo "libk5crypto.so.3 requires EVP_KDF_ctrl. Switching to system OpenSSL libraries" >&2
  export LD_PRELOAD=/lib64/libcrypto.so.1.1:/lib64/libssl.so.1.1
fi

AGORA_USE_MESA_FALLBACK=false
if ! "$NV_AGORA_PATH/OpenGLVersionChecker" "--minGLVersion=2.0.0"; then
    AGORA_USE_MESA_FALLBACK=true
fi

if [ "$AGORA_USE_MESA_FALLBACK" = true ]; then
    echo "Warning: OpenGL Version check failed. Falling back to Mesa software rendering." >&2
    export LD_LIBRARY_PATH="$NV_AGORA_PATH/Mesa:$LD_LIBRARY_PATH"
fi

if [ "${NV_AGORA_FORCE_BREAKPAD:-0}" -ge 0 ]; then
    "$NV_AGORA_PATH/CrashReporter" "NVIDIA Nsight Compute" "NVIDIA Nsight Compute" "2024.2.1.0 (build 34372528) (public-release)" "$NV_AGORA_PATH/ncu-ui.bin" "$@"
else
    "$NV_AGORA_PATH/ncu-ui.bin" "$@"
fi
