-
Notifications
You must be signed in to change notification settings - Fork 419
/
Copy pathubuntu_server_1204.sh
379 lines (312 loc) · 12.8 KB
/
ubuntu_server_1204.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/bin/bash
#
# 88 ,ad8888ba, 88 88 88
# "" d8"' `"8b "" ,d 88 88
# d8' 88 88 88
# 88 88 88 MM88MMM 88 ,adPPYYba, 88,dPPYba,
# 88 88 88888 88 88 88 "" `Y8 88P' "8a
# 88 Y8, 88 88 88 88 ,adPPPPP88 88 d8
# 88 Y8a. .a88 88 88, 88 88, ,88 88b, ,a8"
# 88 `"Y88888P" 88 "Y888 88888888888 `"8bbdP"Y8 8Y"Ybbd8"'
#
# Ubuntu/Debian Installer
# ------------------------------------------------------------------------------
# @author Myles McNamara
# @date 7.17.2013
# @version 1.0
# @source https://github.com/tripflex/igitlab
# ------------------------------------------------------------------------------
# @usage ./igetlab domain.com
# ------------------------------------------------------------------------------
# @copyright Copyright (C) 2013 Myles McNamara
# 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, either version 3 of the License, or
# (at your option) any later version.
# 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, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------------
# =============================================================================
# = Required Script Configuration Values =
# =============================================================================
# --------------------------------------------------------
# - GitHub branch to use. Use master for latest release -
# --------------------------------------------------------
# For versions <=5.0 or >=6.0 the Unicorn Gem is used, 5.1-5.9 uses Puma, if you used master Unicorn is required.
gitlab_release=5-4-stable
# -------------------------------------------------------
# - Unicorn or Puma, Puma default, set to 1 for Unicorn -
# -------------------------------------------------------
useunicorn=0
# -------------------------------------
# - Download URL for Ruby tar.gz file -
# -------------------------------------
# rubydlurl="ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz"
rubydlurl="http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz"
# --------------------------------------------------
# - MySQL Root Password, will prompt if left blank -
# --------------------------------------------------
mysqlpasswd=""
# ------------------------------
# - Optional apt-get arguments -
# ------------------------------
# -s = simulate
# -y = yes (no prompt)
# -q = quiet
# -qq = even more quiet (also implies -y, do not use with -s)
# ------------------------------
aptget_arguments="-qq"
APTLOG=apt.log
APTERRLOG=apterror.log
###########################
# That's far enough buddy #
###########################
# =============
# = Functions =
# =============
function givemeayes {
echo -n "$1 "
read answer
case "$answer" in
Y|y|yes|YES|Yes) return 0 ;;
*) echo -e "\nCaptain, we hit the eject button!\n"; exit ;;
esac
}
# ======================
# = General Start Code =
# ======================
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [[ $1 == -* ]]; then
echo "Usage: $0 domain.com" >&2
exit
fi
clear
# Check for domain
if [ "$#" -lt 1 ]; then
echo -e "\n[iGitLab] Domain was not specified, using localhost as default!"
domain_var=localhost
else
domain_var=$1
fi
# Check for MySQL root password
if [ -z "$mysqlpasswd" ]; then
echo -e "\n[iGitLab] MySQL root password not set in configuration, this will be required. If MySQL is not installed you will be prompted to set a password after this script installs MySQL. If MySQL is already installed you will need to set the root password and restart this script."
fi
echo -e "\n[iGitLab] Installing GitLab v5 (Release: $gitlab_release) for $domain_var"
givemeayes "Would you like to continue with the install? (y/n)"
# ====================
# = Install Packages =
# ====================
#
echo -e "\n[iGitLab] Updating package information..."
sudo apt-get update $aptget_arguments
echo -e "\n[iGitLab] Installing required packages, please wait this could take a minute..."
sudo apt-get install $aptget_arguments build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl wget git-core openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev makepasswd 1>>$APTLOG 2>>$APTERRLOG || (echo "apt-get install failed, check APTLOG and APTERRLOG" ; exit)
# ======================
# = MySQL Installation =
# ======================
#
# Install the database packages
sudo apt-get install $aptget_arguments mysql-server mysql-client libmysqlclient-dev
# Check for MySQL root password
if [ -z "$mysqlpasswd" ]; then
echo -e "\n[iGitLab] MySQL root password not provided, please enter the password you used now."
read mysqlpasswd
if [ -z "$mysqlpasswd" ]; then
echo -e "\n[iGitLab] MySQL root password not provided, exiting installer, please run again after you set the root password."
exit 0
fi
fi
# Generate a random gitlab MySQL password
gitlabpass=$(makepasswd --char=14)
if [ -z "$gitlabpass" ]; then
echo -e "\n[iGitLab] Random password generation failed, please enter a password to use for GitLab MySQL user:"
read gitlabpass
fi
# Create a user for GitLab.
mysql -uroot -p$mysqlpasswd -e "CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$gitlabpass';"
# Create the GitLab production database
mysql -uroot -p$mysqlpasswd -e "CREATE DATABASE IF NOT EXISTS \`gitlabhq_production\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;"
# Grant the GitLab user necessary permissons on the table.
mysql -uroot -p$mysqlpasswd -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`gitlabhq_production\`.* TO 'gitlab'@'localhost';"
# Quit the database session
mysql -uroot -p$mysqlpasswd -e "\\q;"
# Try connecting to the new database with the new user
# sudo -u git -H mysql -ugitlab -p$gitlabpass -D gitlabhq_production
# =======================
# = Python Installation =
# =======================
#
echo -e "\n[iGitLab] Installing Python..."
sudo apt-get install $aptget_arguments python
# Make sure that Python is 2.x (3.x is not supported at the moment)
python --version
# If it's Python 3 you might need to install Python 2 separately
sudo apt-get install $aptget_arguments python2.7
# Make sure you can access Python via python2
python2 --version
# If you get a "command not found" error create a link to the python binary
sudo ln -s /usr/bin/python /usr/bin/python2
# ===================
# = Postfix Install =
# ===================
#
sudo DEBIAN_FRONTEND='noninteractive' apt-get install $aptget_arguments postfix-policyd-spf-python postfix # Install postfix without prompting.
# =====================
# = Ruby Installation =
# =====================
#
# Remove Ruby1.8 if installed
echo -e "\n[iGitLab] Removing Ruby1.8 if installed..."
sudo apt-get remove $aptget_arguments ruby1.8
echo -e "\n[iGitLab] Downloading $rubydlurl..."
curl --progress-bar $rubydlurl | tar xz
cd ruby-*
echo -e "\n[iGitLab] Configuring Ruby..."
./configure --silent
echo -e "\n[iGitLab] Making Ruby..."
make --silent
echo -e "\n[iGitLab] Installing Ruby..."
sudo make install --silent
# Bundler Gem (-q for quiet)
echo -e "\n[iGitLab] Installing Bundler Gem..."
sudo gem install bundler --no-ri --no-rdoc -q
# ================
# = System Users =
# ================
#
# Create system git user for GitLab
echo -e "\n[iGitLab] Creating system git user for GitLab..."
sudo adduser --disabled-login --gecos 'GitLab' git
# =============================
# = GitLab Shell Installation =
# =============================
#
# Go to home directory
cd /home/git
# Clone gitlab shell
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
# switch to right version
sudo -u git -H git checkout v1.4.0
# copy example config to config.yml
sudo -u git -H cp config.yml.example config.yml
# Edit config and replace gitlab_url
sudo -u git -H sed -i "s/localhost/${domain_var}/g" config.yml
# Do setup
sudo -u git -H ./bin/install
# =======================
# = GitLab Installation =
# =======================
#
cd /home/git
# Clone GitLab repository
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
# Go to gitlab dir
cd /home/git/gitlab
# Checkout to release
sudo -u git -H git checkout $gitlab_release
# ========================
# = GitLab Configuration =
# ========================
#
cd /home/git/gitlab
# Copy the example GitLab config
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# Replace localhost with domain
sudo -u git -H sed -i "s/localhost/${domain_var}/g" config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/
# Create directory for satellites
sudo -u git -H mkdir /home/git/gitlab-satellites
# Create directories for sockets/pids and make sure GitLab can write to them
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
# Create public/uploads directory otherwise backup will fail
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX public/uploads
# Copy the example Unicorn config (Version < 5.1 use Unicorn, versions > 5.1 use Puma)
# sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
# Copy the example of Puma config
if [ "$useunicorn" -eq 1 ]; then
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
pumaorunicorn="puma"
else
sudo -u git -H cp config/puma.rb.example config/puma.rb
pumaorunicorn="unicorn"
fi
# Configure Git global settings for git user
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@$domain_var"
# =================================
# = GitLab Database Configuration =
# =================================
# Mysql
sudo -u git cp config/database.yml.mysql config/database.yml
# Insert database password into config
passwdph="secure password"
sed -i "s/${passwdph}/${gitlabpass}/g" config/database.yml
# Replace MySQL user root with gitlab
sed -i 's/root/gitlab/g' config/database.yml
# Make config/database.yml readable to git only
sudo -u git -H chmod o-rwx config/database.yml
# =======================
# = GitLab Gems Install =
# =======================
#
cd /home/git/gitlab
sudo gem install charlock_holmes --version '0.6.9.4'
# For MySQL (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws $pumaorunicorn
# ================================================
# = Initialize DB and Activate Advanced Features =
# ================================================
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# ======================
# = GitLab Init Script =
# ======================
#
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
# Set GitLab to start on boot
sudo update-rc.d gitlab defaults 21
# ===================
# = Apache Handling =
# ===================
#
if [ -f /etc/init.d/apache2 ]; then
echo -e "\n[iGitLab] Apache init found, attempting to stop"
sudo /etc/init.d/apache2 stop
echo -e "\n[iGitLab] Disabling apache from starting at boot"
sudo update-rc.d apache2 remove
fi
# =================
# = Install Nginx =
# =================
echo -e "\n[iGitLab] Attempting to install Nginx ..."
sudo apt-get install $aptget_arguments nginx
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
# 5-3-stable and prior has YOUR_SERVER_IP in nginx conf, post 5-3-stable does not
sudo sed -i 's/YOUR_SERVER_IP:80/*:80/g' /etc/nginx/sites-available/gitlab
# Replace YOUR_SERVER_FQDN with domain
sudo sed -i "s/YOUR_SERVER_FQDN/${domain_var}/g" /etc/nginx/sites-available/gitlab
# ===========================
# = Where the magic happens =
# ===========================
sudo service gitlab start
sudo service nginx start
echo "Install Complete."
echo -e "\n------------------------------------------------------------"
echo -e "\n[iGitLab] You can login at $domain_var"
echo -e "\n[iGitLab] Username: [email protected]"
echo -e "\n[iGitLab] Password: 5iveL!fe"
echo -e "\n------------------------------------------------------------"