#!/bin/bash

# TODO(nf): container currently built with Debian due to musl incompatibilities, but still avoiding bash-isms
set -eu

if [ "$1" = "dx" ]; then
  if [ "${DX_PROFILE_MODE-}" = "volume" ] && [ -n "${DX_PROFILE_ROOT-}" ]; then
    export HOME=$DX_PROFILE_ROOT
  fi

  export LOG_FILTER=${LOG_FILTER:-info}
  # TODO(nf): handle global arguments and other invocations?
  if [ "$2" = "agent" ]; then
    if [ -n "${DXOS_AGENT_IDENTITY_KEY-}" ]; then
      echo "Starting DXOS agent for $DXOS_AGENT_IDENTITY_KEY"
    else
      echo "Starting DXOS agent"
    fi
  fi
fi

exec "$@"
