summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2014-07-04 09:22:54 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2014-07-04 16:33:12 +0100
commit2c28e07681d3c2e28d261dbebb89721e0819fedc (patch)
treedb811593a768a0db707bc104eda5e9df7c7d9b09
parentb55c8552a68bf045199e8ca77849b7c6fd279ca7 (diff)
downloaddefinitions-2c28e07681d3c2e28d261dbebb89721e0819fedc.tar.gz
Allow SMTP details to be configured.
This lets us configure a gitlab system to send e-mail at deploy time. It uses the following environment variables: * MAIL_SEND_TYPE * SMTP_ADDR * SMTP_PORT * SMTP_USER * SMTP_PASS * SMTP_DOMAIN
-rw-r--r--gitlab.configure44
1 files changed, 44 insertions, 0 deletions
diff --git a/gitlab.configure b/gitlab.configure
index ab4ef561..9798c775 100644
--- a/gitlab.configure
+++ b/gitlab.configure
@@ -25,6 +25,12 @@
# * UNICORN_PORT
# * CI_PORT
# * UNICORN_CI_PORT
+# * MAIL_SEND_TYPE
+# * SMTP_ADDR
+# * SMTP_PORT
+# * SMTP_USER
+# * SMTP_PASS
+# * SMTP_DOMAIN
set -e
@@ -82,3 +88,41 @@ EOF
ln -s "/etc/systemd/system/gitlab-setup.service" \
"$ROOT/etc/systemd/system/multi-user.target.wants/gitlab-setup.service"
+
+##########################################################################
+
+rubyescape() {
+ # In ruby, single quoted strings need \ and ' escaping
+ printf "%s\n" "$1" | sed -e "s/['\\]/\\\&/g" \
+ -e "s/^/'/" \
+ -e "s/$/'/"
+}
+
+sedescape() {
+ # Escape all non-alphanumeric characters
+ printf "%s\n" "$1" | sed -e 's/\W/\\&/g'
+}
+
+do_escapes() {
+ printf "%s\n" "$(sedescape "$(rubyescape "$1")")"
+}
+
+if [ "$MAIL_SEND_TYPE" = "smtp" ]; then
+
+ echo "Setting up SMTP for sending e-mail"
+
+ for CONFIG_PATH in \
+ "/usr/share/gitlab-ce/config" "/usr/share/gitlab-ci/config"
+ do
+ sed -i 's/sendmail/smtp/' \
+ "$ROOT$CONFIG_PATH/environments/production.rb"
+
+ sed -e s/\"email.server.com\"/"$(do_escapes "$SMTP_ADDR")/g" \
+ -e s/\"smtp\"/"$(do_escapes "$SMTP_USER")/g" \
+ -e s/\"123456\"/"$(do_escapes "$SMTP_PASS")/g" \
+ -e s/\"gitlab.company.com\"/"$(do_escapes "$SMTP_DOMAIN")/g" \
+ -e s/456/$SMTP_PORT/g \
+ <"$ROOT$CONFIG_PATH/initializers/smtp_settings.rb.sample" \
+ >"$ROOT$CONFIG_PATH/initializers/smtp_settings.rb"
+ done
+fi