#!/bin/bash
# Legacy entry point — kept for backward compatibility with deployments that set
# AWS_LAMBDA_EXEC_WRAPPER=/opt/setup_with_dynatrace.
# Preferred entry point is /opt/sealights-extension, which auto-detects Dynatrace.

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
dynatrace_handler_path="${SEALIGHTS_DYNATRACE_HANDLER_PATH:-/opt/dynatrace}"

if [[ ! -e "${dynatrace_handler_path}" ]]; then
    echo "Dynatrace script execution failed."
    exit 1
fi

if ! "${dynatrace_handler_path}"; then
    echo "Dynatrace script execution failed."
    exit 1
fi

# Prevent bootstrap from running Dynatrace a second time.
export DISABLE_DYNATRACE="true"
exec /bin/bash "${script_dir}/bootstrap" "$@"
