-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitlab.configure
128 lines (106 loc) · 3.95 KB
/
gitlab.configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh
#
# Copyright (C) 2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# This is a "morph deploy" configuration extension to fully configure
# a GitLab and GitLab CI instance at deployment time. It uses the
# following variables from the environment:
#
# * GITLAB_HOSTNAME
# * GITLAB_PORT
# * GITLAB_EMAIL
# * UNICORN_PORT
# * CI_PORT
# * UNICORN_CI_PORT
# * MAIL_SEND_TYPE
# * SMTP_ADDR
# * SMTP_PORT
# * SMTP_USER
# * SMTP_PASS
# * SMTP_DOMAIN
set -e
ROOT="$1"
##########################################################################
# Substitutions in configuration files
##########################################################################
echo "Creating /etc/gitlab-setup.sed"
cat <<EOF > "$ROOT"/etc/gitlab-setup.sed
s/##GITLAB_HOSTNAME##/$GITLAB_HOSTNAME/g
s/##GITLAB_PORT##/$GITLAB_PORT/g
s/##GITLAB_EMAIL##/$GITLAB_EMAIL/g
s/##UNICORN_PORT##/$UNICORN_PORT/g
s/##CI_PORT##/$CI_PORT/g
s/##UNICORN_CI_PORT##/$UNICORN_CI_PORT/g
EOF
echo "Performing substitutions in /usr/share/gitlab config"
sed -f "$ROOT"/etc/gitlab-setup.sed -i \
"$ROOT"/usr/share/gitlab-install/gitlab/config/gitlab.yml \
"$ROOT"/usr/share/gitlab-install/gitlab/config/unicorn.rb \
"$ROOT"/usr/share/gitlab-install/gitlab/lib/support/nginx/gitlab \
"$ROOT"/usr/share/gitlab-install/gitlab-shell/config.yml \
"$ROOT"/usr/share/gitlab-install/gitlab-ci/config/application.yml \
"$ROOT"/usr/share/gitlab-install/gitlab-ci/config/unicorn.rb \
"$ROOT"/usr/share/gitlab-install/gitlab-ci/lib/support/nginx/gitlab_ci \
"$ROOT"/usr/share/gitlab-install/nginx.conf
##########################################################################
echo "Create gitlab-setup unit file"
cat <<EOF > "$ROOT/etc/systemd/system/gitlab-setup.service"
[Unit]
Description=Run gitlab-setup (once)
Requires=network.target
After=network.target
Requires=local-fs.target
After=local-fs.target
ConditionPathExists=!/home/git/gitlab
[Service]
Type=oneshot
ExecStart=/usr/share/gitlab-setup
Restart=no
[Install]
WantedBy=multi-user.target
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