forked from 0k/0k-charms
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.2 KiB
114 lines
3.2 KiB
#!/bin/bash
|
|
|
|
## XXXvlab: this hook should go into a generic odoo image
|
|
|
|
## XXXvlab: should get location of code
|
|
CONFIG=$SERVICE_CONFIGSTORE/etc/odoo-server.conf
|
|
|
|
. lib/common
|
|
|
|
set -e
|
|
|
|
PASSWORD="$(relation-get password)"
|
|
USER="$(relation-get user)"
|
|
DBNAME="$(relation-get dbname)"
|
|
HOST="$(relation-get host)"
|
|
PORT="$(relation-get port)"
|
|
ADMIN_PASSWORD=$(relation-base-compose-get admin-password 2>/dev/null) || {
|
|
if [ -e "$CONFIG" ]; then
|
|
ADMIN_PASSWORD=$(grep ^admin_passwd "$CONFIG" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g')
|
|
fi
|
|
if [ -z "$ADMIN_PASSWORD" ]; then
|
|
info "Generating odoo admin password"
|
|
ADMIN_PASSWORD=$(gen_password)
|
|
fi
|
|
}
|
|
|
|
control=$(p0 "$USER" "$DBNAME" "$PASSWORD" "$ADMIN_PASSWORD" "$HOST" "$PORT" | md5_compat)
|
|
|
|
database=$(options-get database 2>/dev/null) || true
|
|
database="${database:-$DBNAME}"
|
|
|
|
config-add "\
|
|
services:
|
|
$MASTER_BASE_SERVICE_NAME:
|
|
command:
|
|
- '--database=$database'
|
|
## All this is to please tecnativa image, but is quite redundant
|
|
environment:
|
|
PGHOST: \"$HOST\"
|
|
PGPORT: \"$PORT\"
|
|
PGDATABASE: \"$DBNAME\"
|
|
PGPASSWORD: \"$PASSWORD\"
|
|
PGUSER: \"$USER\"
|
|
ADMIN_PASSWORD: \"$ADMIN_PASSWORD\"
|
|
"
|
|
|
|
|
|
file_put $CONFIG <<EOF
|
|
[options]
|
|
admin_passwd = $ADMIN_PASSWORD
|
|
db_user = $USER
|
|
db_password = $PASSWORD
|
|
EOF
|
|
|
|
odoo_uid=$(get_odoo_uid)
|
|
|
|
chown "$odoo_uid" "$CONFIG" && chmod 600 "$CONFIG"
|
|
|
|
|
|
if ! out=$(echo "SELECT datname FROM pg_database;" | sql postgres 2>&1); then
|
|
warn "Failed to get database list" >&2
|
|
printf "%s\n" "$out" | prefix " " >&2
|
|
## We don't have access to database list, so...
|
|
|
|
## if we have a dbfilter set, complain.
|
|
if dbfilter=$(options-get dbfilter 2>&1) && [ -n "$dbfilter" ]; then
|
|
err "Cannot set ${WHITE}dbfilter${NORMAL} without access to db list"
|
|
echo " You don't seem to have access rights on" \
|
|
"${DARKYELLOW}$TARGET_SERVICE_NAME${NORMAL} to" \
|
|
"the database list" >&2
|
|
echo " So you cannot set" \
|
|
"${WHITE}dbfilter${NORMAL} option in" \
|
|
"${DARKYELLOW}$SERVICE_NAME${NORMAL} options." >&2
|
|
exit 1
|
|
fi
|
|
|
|
service_base_image_export_dir \
|
|
"$MASTER_BASE_SERVICE_NAME" \
|
|
/opt/odoo/custom/src/odoo/odoo/sql_db.py \
|
|
"$SERVICE_CONFIGSTORE/odoo-sql_db.py"
|
|
|
|
chown "$odoo_uid" "$SERVICE_CONFIGSTORE/odoo-sql_db.py"
|
|
|
|
patch -d "$SERVICE_CONFIGSTORE" -p0 <<EOF
|
|
--- odoo-sql_db.py 2024-09-14 20:44:40.540104600 +0200
|
|
+++ odoo-sql_db.py 2024-09-14 20:45:39.868394908 +0200
|
|
@@ -789,6 +789,9 @@
|
|
if _Pool is None:
|
|
_Pool = ConnectionPool(int(tools.config['db_maxconn']))
|
|
|
|
+ if to == 'postgres':
|
|
+ to = tools.config['db_name']
|
|
+
|
|
db, info = connection_info_for(to)
|
|
if not allow_uri and db != to:
|
|
raise ValueError('URI connections not allowed')
|
|
EOF
|
|
|
|
## We need to force DBFILTER to be empty as odoo-tecnativa image
|
|
## will set '.*' by default, which makes odoo switch to a mode
|
|
## where it ignores DBNAME.
|
|
config-add "\
|
|
services:
|
|
$MASTER_BASE_SERVICE_NAME:
|
|
volumes:
|
|
- '$SERVICE_CONFIGSTORE/odoo-sql_db.py:/opt/odoo/custom/src/odoo/odoo/sql_db.py'
|
|
environment:
|
|
DB_FILTER: ''
|
|
"
|
|
|
|
fi
|
|
|
|
|
|
info "Configured $SERVICE_NAME code for $HOST:$PORT access."
|