#!/usr/bin/env bash
set -euo pipefail

# As of 26 June 2024, self-hosted Maybe requires a Synth API key (https://synthfinance.com/) for basic multi-currency support.
# Ideally Maybe will support API key input via the UI in the future, but for now we create a persistent .env file for Advanced users to input their API key and restart Maybe.

PERSISTENT_ENV_FILE="$(dirname "${BASH_SOURCE[0]}")/../.env"
DESIRED_OWNER="1000:1000"

create_env_file() {
  cat <<EOF > "${PERSISTENT_ENV_FILE}"
# Uncomment the SYNTH_API_KEY line and replace YOUR_SYNTH_API_KEY with your personal Synth API key
# SYNTH_API_KEY=YOUR_SYNTH_API_KEY
EOF
  chown "${DESIRED_OWNER}" "${PERSISTENT_ENV_FILE}"
}

if [[ ! -f "${PERSISTENT_ENV_FILE}" ]]; then
  echo ".env file for Maybe has not been created yet. Creating one now..."
  create_env_file
fi