#!/usr/bin/env bash
# Instala apps Odoo 16 necessárias à operação Ligbox (CRM + Sales + Invoicing)
# Spec 027 — VM123
set -euo pipefail

COMPOSE_DIR="${COMPOSE_DIR:-/opt/vm123-finance-stack}"
DB="${ODOO_DB:-ligbox}"
MODULES="${ODOO_INSTALL_MODULES:-crm,sale,sale_management,account,contacts}"

cd "$COMPOSE_DIR"
echo "=== Odoo install: $MODULES (db=$DB) ==="
docker compose stop odoo
docker compose run --rm odoo odoo -d "$DB" -i "$MODULES" --stop-after-init --without-demo=all
docker compose up -d odoo
sleep 6
curl -sf "http://127.0.0.1:8069/web/health" && echo " — Odoo OK"
