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.

37 lines
922 B

  1. #!/bin/bash
  2. set -e
  3. PASSWORD="$(relation-get password)"
  4. USER="$(relation-get user)"
  5. DBNAME="$(relation-get dbname)"
  6. HOST="$(relation-get host)"
  7. PORT="$(relation-get port)"
  8. control=$(p0 "$USER" "$DBNAME" "$PASSWORD" "$HOST" "$PORT" | md5_compat)
  9. config-add "\
  10. services:
  11. $MASTER_BASE_SERVICE_NAME:
  12. environment:
  13. DB_HOST: $HOST
  14. DB_PORT_NUMBER: $PORT
  15. MM_DBNAME: $DBNAME
  16. MM_PASSWORD: $PASSWORD
  17. MM_USERNAME: $USER
  18. "
  19. DATASOURCE="postgres://${USER}:${PASSWORD}@${HOST}:${PORT}/${DBNAME}?sslmode=disable\&connect_timeout=10"
  20. if [ -e "$SERVICE_CONFIGSTORE/mattermost/config/config.json" ]; then
  21. sed -ri 's|("DataSource": ")[^"]*(")|\1'"$DATASOURCE"'\2|' \
  22. "$SERVICE_CONFIGSTORE/mattermost/config/config.json" || exit 1
  23. fi
  24. [ "$control" == "$(relation-get control 2>/dev/null)" ] && exit 0
  25. relation-set control "$control"
  26. info "Configured $SERVICE_NAME code for $HOST:$PORT access."