-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlab_user_data.sh
65 lines (52 loc) · 2.18 KB
/
gitlab_user_data.sh
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
#! /bin/bash
function get-registration-token {
# Directly add code into GitLab to write the registration token into some file.
# A FIFO (named pipe) is used here to make this shell script blocked for waiting
# the starting process of GitLab to finish.
# The FIFO is write-only for security concern, and is deleted after receiving the token.
SED_CMD='5a \
open("/opt/gitlab/REGISTRATION_TOKEN", "w") { |f| \
f.puts REGISTRATION_TOKEN \
} \
'
sed -e "$SED_CMD" -i~ /opt/gitlab/embedded/service/gitlab-rails/config/initializers/4_ci_app.rb
mkfifo /opt/gitlab/REGISTRATION_TOKEN
chmod 222 /opt/gitlab/REGISTRATION_TOKEN
gitlab-ctl restart
cat /opt/gitlab/REGISTRATION_TOKEN > /dev/null
REGISTRATION_TOKEN=`cat /opt/gitlab/REGISTRATION_TOKEN`
mv -f /opt/gitlab/embedded/service/gitlab-rails/config/initializers/4_ci_app.rb~ /opt/gitlab/embedded/service/gitlab-rails/config/initializers/4_ci_app.rb
rm -f /opt/gitlab/REGISTRATION_TOKEN
}
function install-gitlab {
# Update repositary
apt-get update
# Install required dependencies
echo postfix postfix/mailname string gitlab.nctucs.net | debconf-set-selections
echo postfix postfix/main_mailer_type select Internet Site | debconf-set-selections
apt-get install -y curl openssh-server ca-certificates postfix
# Execute installation script & install
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
apt-get install -y gitlab-ce
}
function config-gitlab {
curl -o /etc/gitlab/gitlab.rb https://raw.githubusercontent.com/cyliang/GitLab-template/master/gitlab.rb
sed -e "6s#GITLAB_EXTERNAL_URL#$1#g" -i /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
}
function set-gitlab-password {
# Change the password of root and cancel the expiration of the password to
# make the GitLab instance available immediately.
gitlab-rails console production <<EOF
user = User.where(id: 1).first
user.password = '$1'
user.password_confirmation = '$1'
user.password_expires_at = nil
user.save!
EOF
}
install-gitlab
config-gitlab "http://$INSTANCE_FLOATING_IP/"
get-registration-token
set-gitlab-password '$GITLAB_ROOT_PASSWORD'
wc_notify --data-binary "{\"data\": \"$REGISTRATION_TOKEN\", \"id\": \"registration token\"}"