-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_script.sh
349 lines (246 loc) · 10.5 KB
/
install_script.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
#!/bin/bash
# INSTALLATION SCRIPT FOR:
#
# Linux 3.16.0-4-amd64 x86_64
#
# PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
# NAME="Debian GNU/Linux"
# VERSION_ID="8"
# VERSION="8 (jessie)"
# ID=debian
uname -srm
cat /etc/*-release
# SSH Authentication by Password - yes
sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
service sshd restart
# VERSIONS
NODE_VERSION=7
SPHINX_VERSION=2.2.11-release-1
DEPLOYER_RVM_RUBY_VERSION=ruby-2.3.3
DEPLOYER_RVM_GEMSET_NAME=rails_app
# DEFINE PASSWORDS
ROOT_PASSWORD=`openssl rand -hex 15`
DEPLOYER_PASSWORD=`openssl rand -hex 15`
ROOT_MYSQL_PASSWORD=`openssl rand -hex 15`
DEPLOYER_MYSQL_PASSWORD=`openssl rand -hex 15`
ROOT_PSQL_PASSWORD=`openssl rand -hex 15`
DEPLOYER_PSQL_PASSWORD=`openssl rand -hex 15`
# SET LANG VARS
echo 'export LC_ALL="en_US.UTF-8"' >> ~/.bashrc
echo 'export LANGUAGE="en_US:en"' >> ~/.bashrc
echo 'export LANG="en_US.UTF-8"' >> ~/.bashrc
echo 'export LC_CTYPE="en_US.UTF-8"' >> ~/.bashrc
source ~/.bashrc
# VIM OPTIONS
echo "set nocompatible" > ~/.vimrc
echo ":set backspace=indent,eol,start" >> ~/.vimrc
# APT UPDATE AND CORE UTILS
mv /etc/apt/sources.list /etc/apt/sources.list.backup
echo "deb http://httpredir.debian.org/debian/ stable main contrib non-free
deb http://httpredir.debian.org/debian/ stable-updates main contrib non-free
deb http://security.debian.org/ stable/updates main contrib non-free
deb-src http://httpredir.debian.org/debian/ stable main contrib non-free
deb-src http://httpredir.debian.org/debian/ stable-updates main contrib non-free
deb-src http://security.debian.org/ stable/updates main contrib non-free
deb http://httpredir.debian.org/debian jessie-backports main contrib non-free
deb-src http://httpredir.debian.org/debian jessie-backports main contrib non-free
" > /etc/apt/sources.list
# ALT WAY
# wget http://debian.mirror.vu.lt/debian-sources.list && mv debian-sources.list /etc/apt/sources.list
apt-get clean
apt-get update && apt-get install -y coreutils
##################################################################
# `ROOT` USER
##################################################################
echo "root:$ROOT_PASSWORD" | chpasswd
##################################################################
# `RAILS` USER
##################################################################
adduser rails --home /home/rails --shell /bin/bash --disabled-password --gecos ''
echo "rails:$DEPLOYER_PASSWORD" | chpasswd
chown -R rails:rails /home/rails/
# FOR SSH
mkdir -p /home/rails/.ssh
chown rails:rails /home/rails/.ssh
chmod 0700 /home/rails/.ssh
# FOR NGINX
mkdir -p /home/rails/www
chown rails:rails /home/rails/www
chmod 0755 /home/rails/www
# FOR GEM INSTALL
echo 'gem: --no-document' >> /home/rails/.gemrc
chown rails:rails /home/rails/.gemrc
chmod -R 0644 /home/rails/.gemrc
# FOR VIM
echo "set nocompatible" >> /home/rails/.vimrc
echo ":set backspace=indent,eol,start" >> /home/rails/.vimrc
chown rails:rails /home/rails/.vimrc
chmod 0644 /home/rails/.vimrc
##################################################################
# `RAILS` USER
##################################################################
# CREATE SWAP
dd if=/dev/zero of=/swapfile bs=1024 count=2048k
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
echo 10 | tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | tee -a /etc/sysctl.conf
sysctl --system
# MINIMAL SOFT PACK
apt-get install -y sudo screen dialog apt-transport-https ca-certificates \
man-db deborphan aptitude bc bash-completion command-not-found \
python-software-properties htop nmon iotop dstat vnstat unzip zip unar pigz \
p7zip-full logrotate wget curl w3m lftp rsync openssh-server telnet nano mc \
pv less sysstat ncdu ethtool dnsutils mtr-tiny rkhunter ntpdate ntp vim tree
# REQUIREMENTS LIBS
apt-get install -y build-essential autoconf bison checkinstall git-core \
libodbc1 libc6-dev libreadline6 libreadline6-dev libsqlite3-0 libsqlite3-dev \
libssl-dev libxml2 libxml2-dev libxslt-dev libxslt1-dev libxslt1.1 \
libyaml-dev openssl sqlite3 zlib1g zlib1g-dev
# NEW RELIC MONITOR
echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list
wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add -
apt-get update
apt-get install -y newrelic-sysmond
### LETS ENCRIPT
apt-get install -y letsencrypt -t jessie-backports
# NODE
# https://github.com/nodesource/distributions
curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash -
apt-get install -y nodejs
# IMAGE OPTIMIZERS
apt-get install -y advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngquant
# PNGCRUSH. SEE FAILED BINS LIST
# http://www.rubydoc.info/gems/image_optim/ImageOptim/BinResolver/Bin
cd /tmp/
wget https://netcologne.dl.sourceforge.net/project/pmt/pngcrush/1.8.11/pngcrush-1.8.11.tar.gz
tar -xvf pngcrush-1.8.11.tar.gz
cd pngcrush-1.8.11
make pngcrush
cp /tmp/pngcrush-1.8.11/pngcrush /usr/local/bin/pngcrush
rm -rf ./pngcrush-1.8.11
cd ~
# PNGOUT
cd /tmp/
wget http://static.jonof.id.au/dl/kenutils/pngout-20150319-linux.tar.gz
tar -xvf pngout-20150319-linux.tar.gz
cp /tmp/pngout-20150319-linux/x86_64/pngout /usr/local/bin/pngout
rm -rf ./pngout-20150319*
cd ~
# SVGO
npm install -g svgo
# IMAGE MAGICK
apt-get install -y imagemagick libmagickwand-dev
convert --version
# REDIS
apt-get install -y redis-server
# NGINX
curl http://nginx.org/keys/nginx_signing.key | apt-key add -
echo 'deb http://nginx.org/packages/debian/ jessie nginx' >> /etc/apt/sources.list.d/nginx.list
echo 'deb-src http://nginx.org/packages/debian/ jessie nginx' >> /etc/apt/sources.list.d/nginx.list
apt-get update
apt-get install -y nginx
# PYTHON / PIP / PYGMENTS
apt-get install -y python-pip
pip install --upgrade Pygments
# MYSQL
export DEBIAN_FRONTEND=noninteractive
debconf-set-selections <<< "mysql-server mysql-server/root_password password $ROOT_MYSQL_PASSWORD"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $ROOT_MYSQL_PASSWORD"
apt-get install -y mysql-server mysql-common mysql-client libmysqlclient-dev ruby-mysql
unset DEBIAN_FRONTEND
echo "[client]
user=root
password=$ROOT_MYSQL_PASSWORD
" >> ~/.my.cnf
chmod 600 ~/.my.cnf
mysql -D mysql -r -B -N -e "CREATE USER 'rails'@'localhost' IDENTIFIED BY '$DEPLOYER_MYSQL_PASSWORD'"
mysql -D mysql -r -B -N -e "CREATE DATABASE rails_app_db CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql -D mysql -r -B -N -e "GRANT ALL PRIVILEGES ON rails_app_db.* TO 'rails'@'localhost' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0"
mysql -D mysql -r -B -N -e "SHOW GRANTS FOR 'rails'@'localhost'"
# PSQL
# apt-cache pkgnames postgresql
apt-get install -y postgresql libpq-dev
su -s /bin/bash -l postgres -c "psql -U postgres -c \"CREATE USER rails WITH PASSWORD '$DEPLOYER_PSQL_PASSWORD';\""
su -s /bin/bash -l postgres -c "psql -U postgres -c \"ALTER ROLE rails WITH CREATEDB;\""
su -s /bin/bash -l postgres -c "createdb -E UTF8 -O rails rails_app_db"
su -s /bin/bash -l postgres -c "psql -U postgres -c \"GRANT ALL PRIVILEGES ON DATABASE rails_app_db TO rails;\""
# SPHINX SEARCH
cd /tmp
wget http://sphinxsearch.com/files/sphinxsearch_$SPHINX_VERSION~jessie_amd64.deb
dpkg -i sphinxsearch_$SPHINX_VERSION~jessie_amd64.deb
rm -rf ./sphinxsearch*
cd ~
# RVM REQUIREMENTS
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash
/usr/local/rvm/bin/rvm requirements
(echo 'yes') | (/usr/local/rvm/bin/rvm implode)
### RAILS USER ###
su -s /bin/bash -l rails -c "echo 'export LC_ALL=\"en_US.UTF-8\"' >> ~/.bashrc"
su -s /bin/bash -l rails -c "echo 'export LANGUAGE=\"en_US:en\"' >> ~/.bashrc"
su -s /bin/bash -l rails -c "echo 'export LANG=\"en_US.UTF-8\"' >> ~/.bashrc"
su -s /bin/bash -l rails -c "echo 'export LC_CTYPE=\"en_US.UTF-8\"' >> ~/.bashrc"
su -s /bin/bash -l rails -c "source ~/.bashrc"
su -s /bin/bash -l rails -c "\curl -sSL https://get.rvm.io | bash"
su -s /bin/bash -l rails -c "source ~/.bash_profile"
su -s /bin/bash -l rails -c "which rvm"
su -s /bin/bash -l rails -c "rvm autolibs disable & rvm install $DEPLOYER_RVM_RUBY_VERSION"
su -s /bin/bash -l rails -c "(rvm use $DEPLOYER_RVM_RUBY_VERSION) && (rvm gemset use $DEPLOYER_RVM_GEMSET_NAME --create)"
su -s /bin/bash -l rails -c "rvm $DEPLOYER_RVM_RUBY_VERSION@$DEPLOYER_RVM_GEMSET_NAME do gem install bundler"
echo "--------------------------------------------------" >> ~/credentials.txt
echo "ROOT CREDENTIALS" >> ~/credentials.txt
echo "--------------------------------------------------" >> ~/credentials.txt
echo "
DROPLET:
username: root
password: $ROOT_PASSWORD
POSTGRESQL
username: root
password: $ROOT_PSQL_PASSWORD
MYSQL
username: root
password: $ROOT_MYSQL_PASSWORD
" >> ~/credentials.txt
echo "--------------------------------------------------" >> /home/rails/credentials.txt
echo "DEPLOYER LOGIN/PASSWORD" >> /home/rails/credentials.txt
echo "--------------------------------------------------" >> /home/rails/credentials.txt
echo "
LOGIN: rails
PASSWORD: $DEPLOYER_PASSWORD
" >> /home/rails/credentials.txt
echo "--------------------------------------------------" >> /home/rails/credentials.txt
echo "PSQL DATABASE CONNECTION PARAMS" >> /home/rails/credentials.txt
echo "--------------------------------------------------" >> /home/rails/credentials.txt
echo "
production:
adapter: postgresql
encoding: unicode
pool: 5
username: rails
database: rails_app_db
password: $DEPLOYER_PSQL_PASSWORD
" >> /home/rails/credentials.txt
echo "--------------------------------------------------" >> /home/rails/credentials.txt
echo "MYSQL DATABASE CONNECTION PARAMS" >> /home/rails/credentials.txt
echo "--------------------------------------------------" >> /home/rails/credentials.txt
echo "
production:
adapter: mysql2
encoding: utf8
pool: 5
username: rails
database: rails_app_db
password: $DEPLOYER_MYSQL_PASSWORD
" >> /home/rails/credentials.txt
echo "--------------------------------------------------" >> /home/rails/credentials.txt
echo "SERVER IP ADDRESS PARAMS" >> /home/rails/credentials.txt
echo "--------------------------------------------------" >> /home/rails/credentials.txt
echo "" >> /home/rails/credentials.txt
ifconfig eth0 | grep inet | awk "{print $2}" | sed "s/addr://" >> /home/rails/credentials.txt
cat ~/credentials.txt
cat /home/rails/credentials.txt
# NOTES:
# checkinstall -y