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.

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