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

source ./0.variables.env

# Recupération du Dockerfile d'odoo 18
ODOO_DEST_DIR="./config-odoo/"
FILES=(Dockerfile entrypoint.sh odoo.conf wait-for-psql.py)

mkdir -p "${ODOO_DEST_DIR}"
for f in "${FILES[@]}"; do
  curl -fsSL "${BASE}/${f}" -o "${ODOO_DEST_DIR}/${f}"
done
chmod +x "${ODOO_DEST_DIR}/entrypoint.sh" "${ODOO_DEST_DIR}/wait-for-psql.py"

sed -i 's/curl \\/curl vim \\/' "${ODOO_DEST_DIR}/Dockerfile"
sed -i 's|^COPY \./entrypoint\.sh /$|COPY ./requirements.txt /tmp/requirements.txt\nRUN pip install --no-cache-dir --break-system-packages -r /tmp/requirements.txt\nCOPY ./entrypoint.sh /|' "${ODOO_DEST_DIR}/Dockerfile"
