2016-10-08 13:02:43 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2016-10-28 09:15:57 -04:00
|
|
|
# set the postgres database host, port, user and password
|
|
|
|
: ${HOST:=${DB_PORT_5432_TCP_ADDR:='db'}}
|
|
|
|
: ${PORT:=${DB_PORT_5432_TCP_PORT:=5432}}
|
2016-11-03 06:42:54 -04:00
|
|
|
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}}
|
|
|
|
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}}
|
2016-11-05 13:17:05 -04:00
|
|
|
|
|
|
|
# pass them as arguments to the odoo process if not present in the config file
|
2016-10-28 09:15:57 -04:00
|
|
|
DB_ARGS=("--db_user" $USER "--db_password" $PASSWORD "--db_host" $HOST "--db_port" $PORT)
|
2016-10-08 13:02:43 -04:00
|
|
|
|
2016-11-05 13:17:05 -04:00
|
|
|
function is_in_config_file() {
|
|
|
|
if [[ ! -f ${ODOO_RC} ]] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
while read -r line ; do
|
|
|
|
if [[ ${line} == ${1}* ]] ; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done < "${ODOO_RC}"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in "${!DB_ARGS[@]}" ; do
|
|
|
|
# postgres credentials begins by `--` when used as odoo argument but it's not the
|
|
|
|
# case when they're set in the config file
|
|
|
|
if [[ "${DB_ARGS[$i]}" == --* ]] && is_in_config_file "${DB_ARGS[$i]:2}" ; then
|
|
|
|
unset "DB_ARGS[$i]" ; unset "DB_ARGS[$i+1]"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2016-10-08 13:02:43 -04:00
|
|
|
case "$1" in
|
2016-11-03 09:17:25 -04:00
|
|
|
-- | odoo)
|
2016-10-08 13:02:43 -04:00
|
|
|
shift
|
2016-10-28 09:15:57 -04:00
|
|
|
exec odoo "${DB_ARGS[@]}" "$@"
|
2016-10-08 13:02:43 -04:00
|
|
|
;;
|
|
|
|
-*)
|
2016-10-28 09:15:57 -04:00
|
|
|
exec odoo "${DB_ARGS[@]}" "$@"
|
2016-10-08 13:02:43 -04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exec "$@"
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 1
|