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.

51 lines
1.1 KiB

  1. #!/bin/bash
  2. ## XXXvlab: this hook should go into a generic odoo image
  3. ## XXXvlab: should get location of code
  4. CONFIG=$SERVICE_CONFIGSTORE/etc/odoo-server.conf
  5. . lib/common
  6. set -e
  7. PASSWORD="$(relation-get password)"
  8. USER="$(relation-get user)"
  9. DBNAME="$(relation-get dbname)"
  10. ADMIN_PASSWORD=$(relation-base-compose-get admin-password)
  11. control=$(echo -en "$USER\0$DBNAME\0$PASSWORD\0$ADMIN_PASSWORD" | md5_compat)
  12. config-add "\
  13. services:
  14. $MASTER_BASE_CHARM_NAME:
  15. command:
  16. - '--database=$DBNAME'
  17. ## All this is to please technativa image, but is quite redundant
  18. environment:
  19. PGHOST: $MASTER_TARGET_CHARM_NAME
  20. PGDATABASE: $DBNAME
  21. PGPASSWORD: $PASSWORD
  22. PGUSER: $USER
  23. #DBFILTER: $DBNAME
  24. ADMIN_PASSWORD: $ADMIN_PASSWORD
  25. "
  26. [ "$control" == "$(relation-get control 2>/dev/null)" ] && exit 0
  27. file_put $CONFIG <<EOF
  28. [options]
  29. admin_passwd = $ADMIN_PASSWORD
  30. db_user = $USER
  31. db_password = $PASSWORD
  32. EOF
  33. odoo_uid=$(get_odoo_uid)
  34. chown "$odoo_uid" "$CONFIG" && chmod 600 "$CONFIG"
  35. relation-set control "$control"
  36. info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."