#!/bin/bash

set -euo pipefail # Ensures strict error handling

WORKING_DIR="$(pwd)"
ENV_FILE="${WORKING_DIR}/.env"
SOURCE_FILE="${WORKING_DIR}/.env.example"

# Ensure .env file exists
if [[ ! -f "${ENV_FILE}" ]]; then
  echo "Creating ${ENV_FILE} from ${SOURCE_FILE}..."
  cp "${SOURCE_FILE}" "${ENV_FILE}"
else
  echo "${ENV_FILE} already exists."
fi

# Load environment variables
# shellcheck source=/dev/null
source "${ENV_FILE}"

# Set the timezone of the container
TZ=$(timedatectl show --property=Timezone | awk -F= '{print $2}')
export TZ

# Start Docker Compose with Bake support
COMPOSE_BAKE=true docker compose up -d
