This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
source.sh
419 lines (380 loc) · 10.8 KB
/
source.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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
clear
# Root check
[[ $(id -g) != '0' ]] && die 'Script must be run as root.'
# Declare variables
libiconvVersion='libiconv-1.15'
libgdVersion='libgd-2.2.5'
pcreVersion='pcre-8.41'
zlibVersion='zlib-1.2.11'
opensslVersion='openssl-1.1.0h'
phpVersion='php-7.2.4'
nginxVersion='nginx-1.14.0'
cpuNum=$(grep -c 'processor' < /proc/cpuinfo)
# Show notice
function showNotice() {
echo -e "\\n\\033[36m[NOTICE]\\033[0m $1"
}
# Pre-installation check
function preInstall() {
showNotice "Install packages ..."
if [ "$(rpm -qa epel-release | wc -l)" == "0" ]
then
yum install -y epel-release
yum makecache fast
fi
yum install -y make gcc gcc-c++ perl libpng-devel libjpeg-devel libwebp-devel libXpm-devel libtiff-devel libxml2-devel libcurl-devel libmcrypt-devel fontconfig-devel freetype-devel libzip-devel bzip2-devel gmp-devel readline-devel recode-devel GeoIP-devel bison re2c
[ -f /etc/ld.so.conf.d/custom-libs.conf ] && rm -rf /etc/ld.so.conf.d/custom-libs.conf
groupadd www
useradd -m -s /sbin/nologin -g www www
}
# Install package
function installPackage() {
if [ ! -d "/usr/local/$1" ]
then
first=$(echo "${1:0:1}" | tr '[:lower:]' '[:upper:]')
other="${1:1}"
func="install${first}${other}"
$func 'Install'
else
showNotice "$1 is installed"
fi
}
# Upgrade package
function upgradePackage() {
if [ -d "/usr/local/$1" ]
then
first=$(echo "${1:0:1}" | tr '[:lower:]' '[:upper:]')
other="${1:1}"
func="install${first}${other}"
$func 'Upgrade'
else
showNotice "$1 is not installed"
fi
}
# Install Libiconv
function installLibiconv() {
cd /tmp || exit
if [ ! -f "${libiconvVersion}.tar.gz" ]
then
showNotice "Download ${libiconvVersion} ..."
curl -O --retry 3 https://ftp.gnu.org/pub/gnu/libiconv/${libiconvVersion}.tar.gz
fi
showNotice "$1 ${libiconvVersion} ..."
tar -zxf ${libiconvVersion}.tar.gz
cd ${libiconvVersion} || exit
./configure --prefix=/usr/local/libiconv
make -j "$cpuNum"
make install
echo '/usr/local/libiconv/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
}
# Install Pcre
function installPcre() {
cd /tmp || exit
if [ ! -f "${pcreVersion}.tar.gz" ]
then
showNotice "Download ${pcreVersion} ..."
curl -O --retry 3 https://ftp.pcre.org/pub/pcre/${pcreVersion}.tar.gz
fi
showNotice "$1 ${pcreVersion} ..."
tar -zxf ${pcreVersion}.tar.gz -C /usr/local/src/
cd /usr/local/src/${pcreVersion} || exit
./configure \
--prefix=/usr/local/pcre \
--enable-jit \
--enable-utf \
--enable-unicode-properties
make -j "$cpuNum"
make install
echo '/usr/local/pcre/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
}
# Install Zlib
function installZlib() {
cd /tmp || exit
if [ ! -f "${zlibVersion}.tar.gz" ]
then
showNotice "Download ${zlibVersion} ..."
curl -O --retry 3 http://zlib.net/${zlibVersion}.tar.gz
fi
showNotice "$1 ${zlibVersion} ..."
tar -zxf ${zlibVersion}.tar.gz -C /usr/local/src/
cd /usr/local/src/${zlibVersion} || exit
./configure --prefix=/usr/local/zlib
make -j "$cpuNum"
make install
echo '/usr/local/zlib/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
}
# Install Libgd
function installLibgd() {
cd /tmp || exit
if [ ! -f "${libgdVersion}.tar.gz" ]
then
showNotice "Download ${libgdVersion} ..."
curl -O --retry 3 -L https://github.com/libgd/libgd/releases/download/${libgdVersion/lib/}/${libgdVersion}.tar.gz
fi
showNotice "$1 ${libgdVersion} ..."
tar -zxf ${libgdVersion}.tar.gz
cd ${libgdVersion} || exit
./configure \
--prefix=/usr/local/libgd \
--with-libiconv-prefix=/usr/local/libiconv \
--with-zlib=/usr/local/zlib \
--with-jpeg=/usr \
--with-png=/usr \
--with-webp=/usr \
--with-xpm=/usr \
--with-freetype=/usr \
--with-fontconfig=/usr \
--with-tiff=/usr
make -j "$cpuNum"
make install
echo '/usr/local/libgd/lib' >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
}
# Install OpenSSL
function installOpenssl() {
cd /tmp || exit
if [ ! -f "${opensslVersion}.tar.gz" ]
then
showNotice "Download ${opensslVersion} ..."
curl -O --retry 3 https://www.openssl.org/source/${opensslVersion}.tar.gz
fi
showNotice "$1 ${opensslVersion} ..."
tar -zxf ${opensslVersion}.tar.gz -C /usr/local/src/
cd /usr/local/src/${opensslVersion} || exit
./config --prefix=/usr/local/openssl -fPIC
make -j "$cpuNum"
make install
ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
}
# Install PHP
function installPhp {
cd /tmp || exit
if [ ! -f "${phpVersion}.tar.gz" ]
then
showNotice "Download ${phpVersion} ..."
curl -O --retry 3 http://php.net/distributions/${phpVersion}.tar.gz
fi
showNotice "$1 ${phpVersion} ..."
tar -zxf ${phpVersion}.tar.gz
cd ${phpVersion} || exit
./configure \
--prefix=/usr/local/php \
--sysconfdir=/etc/php \
--with-config-file-path=/etc/php \
--with-config-file-scan-dir=/etc/php/php-fpm.d \
--with-fpm-user=www \
--with-fpm-group=www \
--with-curl \
--with-mhash \
--with-gd \
--with-gmp \
--with-bz2 \
--with-recode \
--with-readline \
--with-gettext \
--with-pcre-jit \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl=/usr/local/openssl \
--with-openssl-dir=/usr/local/openssl \
--with-pcre-regex=/usr/local/pcre \
--with-pcre-dir=/usr/local/pcre \
--with-zlib=/usr/local/zlib \
--with-zlib-dir=/usr/local/zlib \
--with-iconv-dir=/usr/local/libiconv \
--with-libxml-dir=/usr \
--with-libzip=/usr \
--with-gd=/usr/local/libgd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-webp-dir=/usr \
--with-xpm-dir=/usr \
--with-freetype-dir=/usr \
--enable-fpm \
--enable-ftp \
--enable-gd-jis-conv \
--enable-calendar \
--enable-exif \
--enable-pcntl \
--enable-soap \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--enable-inline-optimization \
--enable-bcmath \
--enable-mbstring \
--enable-mbregex \
--enable-re2c-cgoto \
--enable-xml \
--enable-mysqlnd \
--enable-embedded-mysqli \
--enable-opcache \
--disable-fileinfo \
--disable-debug
make -j "$cpuNum"
make install
ln -sf /usr/local/php/bin/php /usr/bin/php
ln -sf /usr/local/php/bin/phpize /usr/bin/phpize
ln -sf /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
cp -v php.ini-production /etc/php/php.ini
}
# Install Nginx
function installNginx() {
cd /tmp || exit
if [ ! -f "${nginxVersion}.tar.gz" ]
then
showNotice "Download ${nginxVersion} ..."
curl -O --retry 3 http://nginx.org/download/${nginxVersion}.tar.gz
fi
showNotice "$1 ${nginxVersion} ..."
tar -zxf ${nginxVersion}.tar.gz
cd ${nginxVersion} || exit
mkdir -p /var/cache/nginx
./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=www \
--group=www \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_geoip_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre-jit \
--with-pcre=/usr/local/src/${pcreVersion} \
--with-zlib=/usr/local/src/${zlibVersion} \
--with-openssl=/usr/local/src/${opensslVersion}
make -j "$cpuNum"
make install
ln -sf /usr/local/nginx/sbin/nginx /usr/bin/nginx
}
# Clean files
function cleanFiles() {
showNotice "Clean files ..."
rm -rfv /tmp/${libiconvVersion}*
rm -rfv /tmp/${libgdVersion}*
rm -rfv /tmp/${pcreVersion}*
rm -rfv /tmp/${zlibVersion}*
rm -rfv /tmp/${opensslVersion}*
rm -rfv /tmp/${phpVersion}*
rm -rfv /tmp/${nginxVersion}*
}
while :
do
clear
echo ' _ _ _ __ __ ____ '
echo '| | | \ | | | \/ | | _ \ '
echo '| | | \| | | |\/| | | |_) |'
echo '| |___ | |\ | | | | | | __/ '
echo '|_____| |_| \_| |_| |_| |_| '
echo ''
echo -e 'For more details see \033[4mhttps://git.io/lnmp\033[0m'
echo ''
showNotice 'Please select your operation:'
echo '1) Install'
echo '2) Uninstall'
echo '3) Upgrade packages'
echo '4) Exit'
read -p 'Select an option [1-4]: ' -r -e operation
case $operation in
1)
clear
preInstall
installPackage 'libiconv'
installPackage 'pcre'
installPackage 'zlib'
installPackage 'libgd'
installPackage 'openssl'
installPackage 'php'
installPackage 'nginx'
cleanFiles
/usr/bin/openssl version
/usr/bin/php -v
/usr/bin/nginx -v
showNotice 'Install complete!'
exit
;;
2)
clear
rm -rfv /etc/ld.so.conf.d/custom-libs.conf
rm -rfv /usr/local/libiconv
rm -rfv /usr/local/pcre
rm -rfv /usr/local/zlib
rm -rfv /usr/local/libgd
rm -rfv /usr/local/openssl
rm -rfv /usr/local/php
rm -rfv /usr/local/nginx
rm -rfv /usr/bin/php
rm -rfv /usr/bin/phpize
rm -rfv /usr/bin/php-fpm
rm -rfv /usr/bin/nginx
rm -rfv /etc/php
rm -rfv /etc/nginx
rm -rfv /var/cache/nginx
rm -rfv /var/log/nginx
showNotice "All packages have been uninstalled"
exit
;;
3)
clear
showNotice "Checking, please wait..."
yum upgrade
if [ -f /etc/ld.so.conf.d/custom-libs.conf ]
then
rm -rf /etc/ld.so.conf.d/custom-libs.conf
fi
upgradePackage 'libiconv'
upgradePackage 'pcre'
upgradePackage 'zlib'
upgradePackage 'libgd'
upgradePackage 'openssl'
upgradePackage 'php'
upgradePackage 'nginx'
cleanFiles
exit
;;
4)
showNotice "Nothing to do..."
exit
;;
esac
done