31 lines
772 B
31 lines
772 B
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
PASSWORD="$(relation-get password)"
|
|
USER="$(relation-get user)"
|
|
DBNAME="$(relation-get dbname)"
|
|
|
|
control=$(echo -en "$USER\0$DBNAME\0$PASSWORD" | md5_compat)
|
|
|
|
config-add "\
|
|
services:
|
|
$MASTER_BASE_SERVICE_NAME:
|
|
environment:
|
|
DB_HOST: $MASTER_TARGET_SERVICE_NAME
|
|
MM_DBNAME: $DBNAME
|
|
MM_PASSWORD: $PASSWORD
|
|
MM_USERNAME: $USER
|
|
"
|
|
|
|
if [ -e "$SERVICE_CONFIGSTORE/mattermost/config/config.json" ]; then
|
|
sed -ri 's/(^\s+"DataSource": "postgres:[^:]+:)([^@]+)@/\1'"$PASSWORD"'@/' \
|
|
"$SERVICE_CONFIGSTORE/mattermost/config/config.json" || exit 1
|
|
fi
|
|
|
|
[ "$control" == "$(relation-get control 2>/dev/null)" ] && exit 0
|
|
|
|
|
|
relation-set control "$control"
|
|
|
|
info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."
|