#!/usr/bin/env bash
#
# Copyright 2016-2024 Confluent Inc.
#
set -eu
if [ "${DEBUG_ENTRYPOINT}" -ne 0 ]; then
  set -xv
fi

_caas_err() {
    printf "ERROR: %s!\n" "$*" >&2
    exit 1
}
export -f _caas_err

echo "===> Started as user:"
id

echo "===> Configuring ..."
# source this, as it EXPORTs some environment variables needed in the launch script
. /opt/caas/bin/configure

echo "===> Running preflight checks ... "
/opt/caas/bin/ensure

if [ "${DEBUG_ENTRYPOINT}" -ne 0 ]; then
    echo "===> Environment variables:"
    env | sort
fi

echo "===> Launching ... "
exec /opt/caas/bin/launch
