#!/bin/bash -e
# regenerate odoo pgsql password

. /etc/default/inithooks

CONF=/etc/odoo/odoo.conf
DB_USER=odoo

# Create new password
DB_PASS=$(mcookie)

# Set new password in config file
sed -i "s|db_password =.*|db_password = $DB_PASS|" $CONF

# Update the pastgres user password
$INITHOOKS_PATH/bin/pgsqlconf.py --user=$DB_USER --pass="$DB_PASS"

# Since we reset the password, reload Odoo
# Don't use systemd/systemctl right now as lxc/ovz does not
# use systemd
service odoo restart

# Webserver will error if postgresql is not restarted
service postgresql restart
