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.

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