Skip to content
Snippets Groups Projects
entrypoint.sh 1.74 KiB
Newer Older
  • Learn to ignore specific revisions
  • remi-filament's avatar
    remi-filament committed
    #!/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}")
    
    Rémi - Le Filament's avatar
    Rémi - Le Filament committed
        else
    
    remi-filament's avatar
    remi-filament committed
            value=`grep "^\s*\b${param}\b\s*=" /opt/odoo/etc/odoo.conf | cut -d "=" -f 2 | xargs`
    
    remi-filament's avatar
    remi-filament committed
    }
    
    remi-filament's avatar
    remi-filament committed
    check_config "db_host" "$HOST"
    
    export PGHOST=$value
    
    remi-filament's avatar
    remi-filament committed
    check_config "db_port" "$PORT"
    
    export PGPORT=$value
    
    remi-filament's avatar
    remi-filament committed
    check_config "db_user" "$USER"
    
    export PGUSER=$value
    
    remi-filament's avatar
    remi-filament committed
    check_config "db_password" "$PASSWORD"
    
    export PGPASSWORD=$value
    
    
    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
    
    Rémi - Le Filament's avatar
    Rémi - Le Filament committed
      	echo "Database $PGDATABASE does not exist"
      	DB_ARGS+=("--load-language")
      	DB_ARGS+=("fr_FR")
    
    Rémi - Le Filament's avatar
    Rémi - Le Filament committed
        psql -qc 'CREATE EXTENSION IF NOT EXISTS unaccent'
    
    remi-filament's avatar
    remi-filament committed
    
    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