#!/usr/bin/env bash
set -e

if [[ -z "$1" ]]; then
    echo "Error: <module> is required." >&2
    echo "Usage: update-module <module> [database]" >&2
    exit 1
fi

database="$DB_NAME"
if [[ -n "$2" ]]; then
    database="$2"
fi

if check-database-initialized "$database"; then
    odoo_init_lang="${ODOO_INIT_LANG:="en_US"}"

    log-entrypoint "Update module $1 on database $database."
    (exec odoo "${DB_ARGS[@]}" --database "$database" --update "$1" --config "$ODOO_RC" \
        --stop-after-init --no-http --load-language "$odoo_init_lang" --without-demo=all) || true
fi

