Newer
Older
#!/bin/bash
set -e
# set the postgres database host, port, user and password according to the environment
# and pass them as arguments to the odoo process if not present in the config file
: ${HOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
: ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}}
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}}
DB_ARGS=()
function check_config() {
param="$1"
value="$2"
if ! grep -q -E "^\s*\b${param}\b\s*=" /opt/odoo/etc/odoo.conf ; then
DB_ARGS+=("--${param}")
DB_ARGS+=("${value}")
value=`grep "^\s*\b${param}\b\s*=" /opt/odoo/etc/odoo.conf | cut -d "=" -f 2 | xargs`
echo "waiting until postgres is listening at ${PGHOST}..."
while true; do
psql --list > /dev/null 2>&1 && break
sleep 1
done
if ! psql --list --no-align --tuples-only 2> /dev/null | grep ^$PGDATABASE\| > /dev/null 2>&1; then
echo "Database $PGDATABASE does not exist"
DB_ARGS+=("--load-language")
DB_ARGS+=("fr_FR")
case "$1" in
-- | odoo)
shift
if [[ "$1" == "scaffold" ]] ; then
exec /opt/odoo/odoo/odoo-bin -c /opt/odoo/etc/odoo.conf "$@"
else
exec /opt/odoo/odoo/odoo-bin -c /opt/odoo/etc/odoo.conf "$@" "${DB_ARGS[@]}"
fi
;;
-*)
exec /opt/odoo/odoo/odoo-bin -c /opt/odoo/etc/odoo.conf "$@" "${DB_ARGS[@]}"
;;
*)
exec "$@"
esac
exit 1