62 lines
1.4 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. config-add "\
  21. services:
  22. $MASTER_BASE_SERVICE_NAME:
  23. command:
  24. - '-i base,l10n_fr'
  25. - '--database=$DBNAME'
  26. ## All this is to please technativa image, but is quite redundant
  27. environment:
  28. PGHOST: $MASTER_TARGET_SERVICE_NAME
  29. PGDATABASE: $DBNAME
  30. PGPASSWORD: $PASSWORD
  31. PGUSER: $USER
  32. #DBFILTER: $DBNAME
  33. ADMIN_PASSWORD: $ADMIN_PASSWORD
  34. "
  35. [ "$control" == "$(relation-get control 2>/dev/null)" ] && exit 0
  36. file_put $CONFIG <<EOF
  37. [options]
  38. admin_passwd = $ADMIN_PASSWORD
  39. db_user = $USER
  40. db_password = $PASSWORD
  41. EOF
  42. odoo_uid=$(get_odoo_uid)
  43. chown "$odoo_uid" "$CONFIG" && chmod 600 "$CONFIG"
  44. relation-set control "$control"
  45. info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."