-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-gitlab.sh
132 lines (109 loc) · 3.55 KB
/
install-gitlab.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
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
129
130
131
132
#!/usr/bin/env bash
# Copyright (c) 2013-2016 Tuomo Tanskanen <[email protected]>
# Usage: Copy 'gitlab.rb.example' as 'gitlab.rb', then 'vagrant up'.
set -e
# these are normally passed via Vagrantfile to environment
# but if you run this on bare metal they need to be reset
GITLAB_HOSTNAME=${GITLAB_HOSTNAME:-192.168.10.10}
GITLAB_PORT=${GITLAB_PORT:-8443}
#
# --------------------------------
# Installation - no need to touch!
# --------------------------------
#
export DEBIAN_FRONTEND=noninteractive
fatal()
{
echo "fatal: $@" >&2
}
check_for_root()
{
if [[ $EUID != 0 ]]; then
fatal "need to be root"
exit 1
fi
}
check_for_gitlab_rb()
{
if [[ ! -e /vagrant/gitlab.rb ]]; then
fatal "gitlab.rb not found at /vagrant"
exit 1
fi
}
set_gitlab_edition()
{
if [[ $GITLAB_EDITION == "community" ]]; then
GITLAB_PACKAGE=gitlab-ce
elif [[ $GITLAB_EDITION == "enterprise" ]]; then
GITLAB_PACKAGE=gitlab-ee
else
fatal "\"${GITLAB_EDITION}\" is not a supported GitLab edition"
exit 1
fi
}
check_for_backwards_compatibility()
{
if egrep -q "^ci_external_url" /vagrant/gitlab.rb; then
fatal "ci_external_url setting detected in 'gitlab.rb'"
fatal "This setting is deprecated in Gitlab 8.0+, and will cause Chef to fail."
fatal "Check the 'gitlab.rb.example' for fresh set of settings."
exit 1
fi
}
set_apt_pdiff_off()
{
echo 'Acquire::PDiffs "false";' > /etc/apt/apt.conf.d/85pdiff-off
}
install_swap_file()
{
# "GITLAB_SWAP" is passed in environment by shell provisioner
if [[ $GITLAB_SWAP > 0 ]]; then
echo "Creating swap file of ${GITLAB_SWAP}G size"
SWAP_FILE=/.swap.file
dd if=/dev/zero of=$SWAP_FILE bs=1G count=$GITLAB_SWAP
mkswap $SWAP_FILE
echo "$SWAP_FILE none swap sw 0 0" >> /etc/fstab
chmod 600 $SWAP_FILE
swapon -a
else
echo "Skipped swap file creation due 'GITLAB_SWAP' set to 0"
fi
}
rewrite_hostname()
{
sed -i -e "s,^external_url.*,external_url 'https://${GITLAB_HOSTNAME}/'," /etc/gitlab/gitlab.rb
}
# All commands expect root access.
check_for_root
# Check that the GitLab edition which is defined is supported and set package name
set_gitlab_edition
# Check for configs that are not compatible anymore
check_for_gitlab_rb
check_for_backwards_compatibility
# install swap file for more memory
install_swap_file
# install tools to automate this install
apt-get -y update
apt-get -y install debconf-utils curl
# install the few dependencies we have
echo "postfix postfix/main_mailer_type select Internet Site" | debconf-set-selections
echo "postfix postfix/mailname string $GITLAB_HOSTNAME" | debconf-set-selections
apt-get -y install openssh-server postfix
# generate ssl keys
apt-get -y install ca-certificates ssl-cert
make-ssl-cert generate-default-snakeoil --force-overwrite
# download omnibus-gitlab package (300M) with apt
# vagrant-cachier plugin hightly recommended
echo "Setting up Gitlab deb repository ..."
set_apt_pdiff_off
curl https://packages.gitlab.com/install/repositories/gitlab/${GITLAB_PACKAGE}/script.deb.sh | sudo bash
echo "Installing ${GITLAB_PACKAGE} via apt ..."
apt-get install -y ${GITLAB_PACKAGE}
# fix the config and reconfigure
cp /vagrant/gitlab.rb /etc/gitlab/gitlab.rb
rewrite_hostname
gitlab-ctl reconfigure
# done
echo "Done!"
echo " Login at https://${GITLAB_HOSTNAME}:${GITLAB_PORT}/, username 'root'. Password will be reset on first login."
echo " Config found at /etc/gitlab/gitlab.rb and updated by 'sudo gitlab-ctl reconfigure'"