fork 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.

62 lines
1.5 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 2>/dev/null) || {
  11. if [ -e "$CONFIG" ]; then
  12. ADMIN_PASSWORD=$(grep ^admin_passwd "$CONFIG" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g')
  13. fi
  14. if [ -z "$ADMIN_PASSWORD" ]; then
  15. info "Generating odoo admin password"
  16. ADMIN_PASSWORD=$(gen_password)
  17. fi
  18. }
  19. control=$(echo -en "$USER\0$DBNAME\0$PASSWORD\0$ADMIN_PASSWORD" | md5_compat)
  20. database=$(options-get database 2>/dev/null) || true
  21. database="${database:-$DBNAME}"
  22. config-add "\
  23. services:
  24. $MASTER_BASE_SERVICE_NAME:
  25. command:
  26. - '--database=$database'
  27. ## All this is to please tecnativa image, but is quite redundant
  28. environment:
  29. PGHOST: \"$MASTER_TARGET_SERVICE_NAME\"
  30. PGDATABASE: \"$DBNAME\"
  31. PGPASSWORD: \"$PASSWORD\"
  32. PGUSER: \"$USER\"
  33. #DBFILTER: $DBNAME
  34. ADMIN_PASSWORD: \"$ADMIN_PASSWORD\"
  35. "
  36. [ "$control" == "$(relation-get control 2>/dev/null)" ] && exit 0
  37. file_put $CONFIG <<EOF
  38. [options]
  39. admin_passwd = $ADMIN_PASSWORD
  40. db_user = $USER
  41. db_password = $PASSWORD
  42. EOF
  43. odoo_uid=$(get_odoo_uid)
  44. chown "$odoo_uid" "$CONFIG" && chmod 600 "$CONFIG"
  45. relation-set control "$control"
  46. info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."