-
Notifications
You must be signed in to change notification settings - Fork 4
/
install_gitlab
executable file
·194 lines (173 loc) · 6.89 KB
/
install_gitlab
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Install_gitlab - GitLab Installation Helper
# Prepare all the stuff excepted the configuration files
# 1. Launch the script
# 2. Modify the configuration files as suggested
# 3. Launch again the script
#
# 28/07/2014 - oloc - Version 0.4.0 - Installations in dedicated functions
# 28/07/2014 - oloc - Version 0.3.1 - curl insecure correction
# 18/06/2014 - oloc - Version 0.3.0 - Use of a temporary file for sql statement in order to set values
# 18/06/2014 - oloc - Version 0.2.0 - Force the usage of sudo
# 13/06/2014 - oloc - First version
Name=gitlab
User=${Name}
InstDir=/opt
MysqlPwdRoot=lqsym
MysqlPwdUser=baltig
GitlabUrl=https://github.com/gitlabhq/gitlabhq.git
RubyUrl=https://ftp.ruby-lang.org/pub/ruby
RubyFile=stable-snapshot.tar.gz
RubyTmpDir=/tmp/ruby
LogDir=/var/log
LogFile=${LogDir}/${Name}.$(date +%Y%m%d.%H%M%S).log
###########
if [ $USER != 'root' ] ; then
echo "Please use sudo or root account."
exit
fi
###########
# Functions
_echo() {
echo "$(date +%Y%m%d-%H%M%S) - $1" | tee -a ${LogFile}
}
_log() {
echo "$(date +%Y%m%d-%H%M%S) * $1" >> ${LogFile}
}
_createUser() {
_echo "Creation of user ${User}"
adduser --disabled-login --gecos 'GitLab' ${User}
mkdir ${LogDir}/${Name} && chown ${User}:${User} ${LogDir}/${Name}
}
_installPrerequisites() {
_echo "Installation of the prerequisites..."
apt-get update -y && apt-get upgrade -y
apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate cmake emacsen-common libxmlrpc-core-c3 2>&1 | tee -a ${LogFile}
apt-get install -y git-core 2>&1 | tee -a ${LogFile}
}
_installPython(){
_log "$(python2 --version)"
if [ "$(python2 --version)" != "Python 2.7.3" ] ; then
_echo "Installation of python..."
apt-get install -y python 2>&1 | tee -a ${LogFile}
apt-get install -y python2.7 2>&1 | tee -a ${LogFile}
ln -s /usr/bin/python /usr/bin/python2
fi
apt-get install -y python-docutils 2>&1 | tee -a ${LogFile}
}
_installRuby(){
typeset rubyFile=$(echo ${RubyFile} | cut -d. -f1)
_echo "Installation of Ruby..."
rm -Rf ${RubyTmpDir} 2>&1 1>/dev/null
mkdir ${RubyTmpDir} && cd ${RubyTmpDir}
_echo "Retrieving ${RubyUrl}/${RubyFile}..."
curl --progress --insecure ${RubyUrl}/${RubyFile} | tar xz
_log "$(ls -l ${rubyFile}*)"
cd ${RubyTmpDir}/${rubyFile}*
_echo "configure..."
./configure --disable-install-rdoc 2>&1 | tee -a ${LogFile}
_echo "make..."
make 2>&1 | tee -a ${LogFile}
_echo "make install..."
make install 2>&1 | tee -a ${LogFile}
gem install bundler --no-ri --no-rdoc 2>&1 | tee -a ${LogFile}
}
_installShell() {
_echo "Installation of the shell gitlab..."
cd ${InstDir}
mkdir -p ${InstDir}/gitlab-shell && chown ${User}:${USer} ${InstDir}/gitlab-shell
_log "$(ls -al ${InstDir})"
_echo "sudo -u ${User} -H git clone https://github.com/gitlabhq/gitlab-shell.git -b v2.5.3"
sudo -u ${User} -H git clone https://github.com/gitlabhq/gitlab-shell.git -b v2.5.3
cd gitlab-shell
sudo -u ${User} -H cp config.yml.example config.yml
}
_installMysql() {
_echo "Installation of Mysql..."
export DEBIAN_FRONTEND=noninteractive
apt-get install -q -y mysql-server mysql-client libmysqlclient-dev 2>&1 | tee -a ${LogFile}
sleep 3
cat > /tmp/mysql.inst <<EOSQL
UPDATE mysql.user SET Password=PASSWORD('${MysqlPwdRoot}') WHERE User='root';
FLUSH PRIVILEGES;
SET storage_engine=INNODB;
CREATE DATABASE IF NOT EXISTS \`gitlabhq_production\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`gitlabhq_production\`.* TO '${User}'@'localhost' IDENTIFIED BY '${MysqlPwdUser}';
EOSQL
_log "SQL Statement to run :"
cat /tmp/mysql.inst >> ${LogFile}
mysql -uroot </tmp/mysql.inst
if [ $? -eq 0 ] ; then
_echo "Second try with the password..."
mysql -uroot -p${MysqlPwdRoot} </tmp/mysql.inst
fi
#mysql_secure_installation 2>&1 | tee -a ${LogFile}
}
_installGitlab() {
_echo "Installation of GitLab..."
cd $InstDir
mkdir -p ${InstDir}/${Name} && chown ${User}:${USer} ${InstDir}/${Name}
_log "$(ls -al ${InstDir})"
_echo "sudo -u ${User} -H git clone ${GitlabUrl} -b 7-8-stable ${Name}"
sudo -u ${User} -H git clone ${GitlabUrl} -b 7-8-stable ${Name}
cd ${InstDir}/${Name}
sudo -u ${User} -H mkdir tmp/pids/ && chmod -R u+rwX tmp/pids/
sudo -u ${User} -H mkdir tmp/sockets/ && chmod -R u+rwX tmp/sockets/
sudo -u ${User} -H mkdir public/uploads && chmod -R u+rwX public/uploads
sudo -u ${User} -H mv log log.old && sudo -u ${User} -H ln -s /var/log/${Name}/ log
mkdir ${InstDir}/gitlab-satellites && chown ${User}:${USer} ${InstDir}/gitlab-satellites
sudo -u ${User} -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u ${User} -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u ${User} -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u ${User} -H cp config/database.yml.mysql config/database.yml
sudo -u ${User} -H chmod o-rwx config/database.yml
}
_installNginx() {
_echo "Installation of Nginx..."
apt-get install -y nginx
cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
}
###################
# Start annoucement
_log "${Name} - start."
_log "Log is here: ${LogFile}"
if [ ! -f /tmp/${Name}.flag ] ; then
_createUser
_installPrerequisites
_installPython
_installRuby
_installShell
_installMysql
_installGitlab
_installNginx
_echo "****************************************************************************"
_echo "*** You have to modify the configuration of :"
_echo "${InstDir}/gitlab-shell/config.yml"
_echo "${InstDir}/${Name}/config/gitlab.yml"
_echo "${InstDir}/${Name}/config/unicorn.rb"
_echo "${InstDir}/${Name}/config/database.yml"
_echo "/etc/nginx/sites-enabled/gitlab"
_echo "Then rerun the script (or delete the flag /tmp/${Name}.flag ) "
_echo "****************************************************************************"
touch /tmp/${Name}.flag
else
###################
_echo "Gitlab deploiement..."
_echo "bundle install --deployment --without development test postgres aws"
sudo -u ${User} -H bundle install --deployment --without development test postgres aws
_echo "bundle exec rake gitlab:setup RAILS_ENV=production"
sudo -u ${User} -H bundle exec rake gitlab:setup RAILS_ENV=production
cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
update-rc.d gitlab defaults 21
cp lib/support/logrotate/${Name} /etc/logrotate.d/${Name}
###################
_echo "Starting..."
service gitlab start
service nginx restart
_echo "Status:"
sudo -u ${User} -H bundle exec rake gitlab:check RAILS_ENV=production
_echo "On your web browser try the login : admin@local.host and password : 5iveL!fe"
_echo "****************************************************************************"
rm /tmp/${Name}.flag 2>/dev/null
fi