-
Notifications
You must be signed in to change notification settings - Fork 1
/
centmin.sh
2015 lines (1599 loc) · 60.1 KB
/
centmin.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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
ZONEINFO=Etc/UTC # Set Timezone
NGINX_IPV='n' #NGINX IPV6 compile support for unattended mode only
USEEDITOR='nano' # choice between nano or vim text editors for cmd shortcuts
CUSTOMSERVERNAME='y'
CUSTOMSERVERSTRING='nginx centminmod'
PHPFPMCONFDIR='/usr/local/nginx/conf/phpfpmd'
UNATTENDED='y' # please leave at 'y' for best compatibility as at .07 release
CMVERSION_CHECK='n'
#####################################################
DT=`date +"%d%m%y-%H%M%S"`
SCRIPT_MAJORVER='1.2.3'
SCRIPT_MINORVER='07'
SCRIPT_VERSION="${SCRIPT_MAJORVER}-eva2000.${SCRIPT_MINORVER}"
SCRIPT_DATE='30/06/2014'
SCRIPT_AUTHOR='eva2000 (vbtechsupport.com)'
SCRIPT_MODIFICATION_AUTHOR='eva2000 (vbtechsupport.com)'
SCRIPT_URL='http://centminmod.com'
COPYRIGHT="Copyright 2011-2014 CentminMod.com"
DISCLAIMER='This software is provided "as is" in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.'
#####################################################
#
# 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. See the included license.txt for futher details.
#
# PLEASE MODIFY VALUES BELOW THIS LINE ++++++++++++++++++++++++++++++++++++++
# Note: Please enter y for yes or n for no.
#####################################################
HN=$(uname -n)
# Pre-Checks to prevent screw ups
DIR_TMP='/svr-setup'
SCRIPT_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
source "inc/memcheck.inc"
TMPFSLIMIT=2900000
if [ ! -d "$DIR_TMP" ]; then
if [[ "$TOTALMEM" -ge "$TMPFSLIMIT" ]]; then
TMPFSENABLED=1
RAMDISKTMPFS='y'
echo "setting up $DIR_TMP on tmpfs ramdisk for initial install"
mkdir -p $DIR_TMP
mount -t tmpfs -o size=2200M,mode=0755 tmpfs $DIR_TMP
df -hT
else
mkdir -p $DIR_TMP
fi
fi
if [[ -z $(cat /etc/resolv.conf) ]]; then
echo ""
echo "/etc/resolv.conf is empty. No nameserver resolvers detected !! "
echo "Please configure your /etc/resolv.conf correctly or you will not"
echo "be able to use the internet or download from your server."
echo "aborting script... please re-run centmin.sh"
echo ""
exit
fi
if [ ! -f /usr/bin/wget ]; then
echo "wget not found !! "
echo "installing wget"
yum -y -q install wget
echo "aborting script... please re-run centmin.sh"
exit
fi
if [ ! -f /usr/bin/unzip ]; then
yum -y -q install unzip
fi
if [ ! -f /usr/bin/bc ]; then
echo "bc not found !! "
echo "installing bc"
yum -y -q install bc
echo "bc installed"
echo "aborting script... "
echo "please re-run centmin.sh again for install"
exit
fi
if [ ! -f /usr/bin/tee ]; then
#echo "tee not found !! "
#echo "installing tee"
yum -y -q install coreutils
fi
if [ -f /var/cpanel/cpanel.config ]; then
echo "WHM/Cpanel detected.. centmin mod NOT compatible"
echo "aborting script..."
exit
fi
if [ -f /etc/psa/.psa.shadow ]; then
echo "Plesk detected.. centmin mod NOT compatible"
echo "aborting script..."
exit
fi
if [ -f /etc/init.d/directadmin ]; then
echo "DirectAdmin detected.. centmin mod NOT compatible"
echo "aborting script..."
exit
fi
TESTEDCENTOSVER='6.5'
CENTOSVER=`cat /etc/redhat-release | awk '{ print $3 }'`
if [ "$CENTOSVER" == 'release' ]; then
CENTOSVER=`cat /etc/redhat-release | awk '{ print $4 }'`
fi
if [ "$CENTOSVER" == 'Enterprise' ]; then
CENTOSVER=`cat /etc/redhat-release | awk '{ print $7 }'`
OLS='y'
fi
if [ -f /proc/user_beancounters ]; then
# CPUS='1'
# MAKETHREADS=" -j$CPUS"
# speed up make
CPUS=`cat "/proc/cpuinfo" | grep "processor"|wc -l`
CPUS=$(echo $CPUS+1 | bc)
MAKETHREADS=" -j$CPUS"
else
# speed up make
CPUS=`cat "/proc/cpuinfo" | grep "processor"|wc -l`
CPUS=$(echo $CPUS+1 | bc)
MAKETHREADS=" -j$CPUS"
fi
# configure .ini directory
CONFIGSCANBASE='/etc/centminmod'
CONFIGSCANDIR="${CONFIGSCANBASE}/php.d"
if [ ! -d "$CONFIGSCANBASE" ]; then
mkdir -p $CONFIGSCANBASE
fi
if [ ! -d "$CONFIGSCANDIR" ]; then
mkdir -p $CONFIGSCANDIR
if [ -d /root/centminmod/php.d/ ]; then
cp -a /root/centminmod/php.d/* ${CONFIGSCANDIR}/
fi
fi
# MySQL non-tmpfs based tmpdir for MySQL temp files
if [ ! -d "/home/mysqltmp" ]; then
mkdir -p /home/mysqltmp
chmod 1777 /home/mysqltmp
CHOWNMYSQL=y
fi
#####################################################
# Enable or disable menu mode
ENABLE_MENU='y'
#####################################################
# CCACHE Configuration
CCACHEINSTALL='y'
CCACHESIZE='2G'
# Disable installed services by default
# The service is still installed but disabled by default
# can be re-enabled with commands
# service servicename start; chkconfig servicename on
NSD_DISABLED=n # NSD disabled by default with chkconfig off
MEMCACHED_DISABLED=n # Memcached server disabled by default via chkconfig off
PHP_DISABLED=n # PHP-FPM disabled by default with chkconfig off
MYSQLSERVICE_DISABLED=n # MariaDB MySQL service disabled by default with chkconfig off
# General Configuration
NGINXUPGRADESLEEP='6'
NSD_INSTALL=y # Install NSD (DNS Server)
NSD_VERSION='3.2.17' # NSD Version
NTP_INSTALL=y # Install Network time protocol daemon
NGINXPATCH=n # Set to y to allow 30 seconds time before Nginx configure and patching Nginx
NGINX_INSTALL=y # Install Nginx (Webserver)
NGINX_GEOIP=n # Nginx GEOIP module install
NGINX_SPDY=y # Nginx SPDY support
NGINX_PAGESPEED=y # Install ngx_pagespeed
NGINX_PAGESPEEDGITMASTER=y # Install ngx_pagespeed from official github master instead
NGXPGSPEED_VER='1.9.32.1-beta'
NGINX_PAGESPEEDPSOL_VER='1.9.32.1'
NGINX_PASSENGER='n' # Install Phusion Passenger requires installing addons/passenger.sh before hand
NGINX_WEBDAV=y # Nginx WebDAV and nginx-dav-ext-module
NGINX_EXTWEBDAVVER='0.0.3' # nginx-dav-ext-module version
NGINX_LIBATOMIC=y # Nginx configured with libatomic support
NGINX_PCREJIT=y # Nginx configured with pcre & pcre-jit support
NGINX_PCREVER='8.35' # Version of PCRE used for pcre-jit support in Nginx
NGINX_HEADERSMORE='0.25'
NGINX_OPENRESTY=n # Agentzh's openresty Nginx modules
PHP_INSTALL=y # Install PHP /w Fast Process Manager
PHPMAKETEST=n # set to y to enable make test after PHP make for diagnostic purposes
PHPFINFO=n # Disable or Enable PHP File Info extension
PHPPCNTL=y # Disable or Enable PHP Process Control extension
PHPRECODE=n # Disable or Enable PHP Recode extension
PHPSNMP=y # Disable or Enable PHP SNMP extension
SHORTCUTS=y # shortcuts
########################################################
# Choice of installing MariaDB 5.2 via RPM or via MariaDB 5.2 CentOS YUM Repo
# If MDB_YUMREPOINSTALL=y and MDB_INSTALL=n then MDB_VERONLY version
# number won't have any effect in determining version of MariaDB 5.2.x to install.
# YUM Repo will install whatever is latest MariaDB 5.2.x version available via the YUM REPO
MDB_INSTALL=n # Install via RPM MariaDB MySQL Server replacement (Not recommended for VPS with less than 256MB RAM!)
MDB_YUMREPOINSTALL=y # Install MariaDB 5.5 via CentOS YUM Repo
# Define current MariaDB version
MDB_VERONLY='5.2.14'
MDB_BUILD='122'
MDB_VERSION="${MDB_VERONLY}-${MDB_BUILD}" # Use this version of MariaDB ${MDB_VERONLY}
# Define previous MariaDB version for proper upgrade
MDB_PREVERONLY='5.2.12'
MDB_PREBUILD='115'
MDB_PREVERSION="${MDB_PREVERONLY}-${MDB_PREBUILD}" # Use this version of MariaDB ${MDB_VERONLY}
########################################################
# Optionally, if you want to install MariaDB instead of standard MySQL you can do.
# Set MDB_INSTALL=y and MYSQL_INSTALL=n
MYSQL_INSTALL=n # Install official Oracle MySQL Server (MariaDB alternative recommended)
SENDMAIL_INSTALL=n # Install Sendmail (and mailx) set to y and POSTFIX_INSTALL=n for sendmail
POSTFIX_INSTALL=y # Install Postfix (and mailx) set to n and SENDMAIL_INSTALL=y for sendmail
# Nginx
NGINX_VERSION='1.7.5' # Use this version of Nginx
NGINXBACKUP='y'
NGINXDIR='/usr/local/nginx'
NGINXCONFDIR="${NGINXDIR}/conf"
NGINXBACKUPDIR='/usr/local/nginxbackup'
NOSOURCEOPENSSL='y' # set to 'y' to disable OpenSSL source compile for system default YUM package setup
OPENSSL_VERSION='1.0.1i' # Use this version of OpenSSL
# Choose whether to compile Nginx --with-google_perftools_module
# no longer used in Centmin Mod v1.2.3-eva2000.01 and higher
GPERFTOOLS_SOURCEINSTALL=n
LIBUNWIND_VERSION='0.99' # note google perftool specifically requies v0.99 and no other
GPERFTOOLS_VERSION='1.8.3' # Use this version of google-perftools
# Choose whether to compile PCRE from source. Note PHP 5.3.8 already includes PCRE v8.12
PCRE_SOURCEINSTALL=n
PCRE_VERSION='8.35' # NO longer used/ignored
# PHP and Cache/Acceleration
IMAGICKPHP_VER='3.1.2' # PHP extension for imagick
MEMCACHED_INSTALL=y # Install Memcached
LIBEVENT_VERSION='2.0.21' # Use this version of Libevent
MEMCACHED_VERSION='1.4.20' # Use this version of Memcached server
MEMCACHE_VERSION='3.0.8' # Use this version of Memcache
MEMCACHEDPHP_VER='2.2.0' # Memcached PHP extension not server
LIBMEMCACHED_YUM='n' # switch to YUM install instead of source compile
LIBMEMCACHED_VER='1.0.18' # libmemcached version for source compile
TWEMPERF_VER='0.1.1'
FFMPEGVER='0.6.0'
SUHOSINVER='0.9.36'
PHP_VERSION='5.4.32' # Use this version of PHP
PHP_MIRRORURL='http://php.net'
PHPUPGRADE_MIRRORURL='http://php.net'
XCACHE_VERSION='3.1.0' # Use this version of Xcache
APCCACHE_VERSION='3.1.13' # Use this version of APC Cache
IGBINARY_VERSION='1.1.1'
IGBINARYGIT='y'
ZOPCACHEDFT='n'
ZOPCACHECACHE_VERSION='7.0.3'
# Python
PYTHON_VERSION='2.7.8' # Use this version of Python
SIEGE_VERSION='3.0.6'
WGETOPT='-cnv --no-dns-cache -4'
###############################################################
# experimental custom RPM compiled packages to replace source
# compiled versions for 64bit systems only
FPMRPM_LIBEVENT=n
FPMRPM_MEMCACHED=n
CENTALTREPO_DISABLE=y
AXIVOREPO_DISABLE=y
###############################################################
MACHINE_TYPE=`uname -m` # Used to detect if OS is 64bit or not.
if [ "${ARCH_OVERRIDE}" != '' ]
then
ARCH=${ARCH_OVERRIDE}
else
if [ ${MACHINE_TYPE} == 'x86_64' ];
then
ARCH='x86_64'
MDB_ARCH='amd64'
else
ARCH='i386'
fi
fi
# source "inc/mainmenu.inc"
# source "inc/mainmenu_cli.inc"
# source "inc/ramdisk.inc"
source "inc/gcc.inc"
source "inc/entropy.inc"
source "inc/cpucount.inc"
source "inc/motd.inc"
source "inc/cpcheck.inc"
source "inc/memcheck.inc"
source "inc/ccache.inc"
source "inc/bookmark.inc"
source "inc/centminlogs.inc"
source "inc/yumskip.inc"
source "inc/questions.inc"
source "inc/downloadlinks.inc"
source "inc/downloads.inc"
source "inc/yumpriorities.inc"
source "inc/yuminstall.inc"
source "inc/centoscheck.inc"
source "inc/axelsetup.inc"
source "inc/phpfpmdir.inc"
source "inc/nginx_backup.inc"
source "inc/nsd_install.inc"
source "inc/nsdsetup.inc"
source "inc/nsd_reinstall.inc"
source "inc/logrotate_nginx.inc"
source "inc/logrotate_phpfpm.inc"
source "inc/nginx_mimetype.inc"
source "inc/openssl_install.inc"
source "inc/nginx_configure.inc"
source "inc/nginx_configure_openresty.inc"
source "inc/nginx_install.inc"
source "inc/nginx_upgrade.inc"
source "inc/imagick_install.inc"
source "inc/memcached_install.inc"
source "inc/mysql_proclimit.inc"
source "inc/mysqltmp.inc"
source "inc/mariadb_install.inc"
source "inc/mysql_install.inc"
source "inc/mariadb_submenu.inc"
source "inc/php_configure.inc"
source "inc/php_upgrade.inc"
source "inc/suhosin_setup.inc"
source "inc/nginx_pagespeed.inc"
source "inc/nginx_modules.inc"
source "inc/nginx_modules_openresty.inc"
source "inc/sshd.inc"
source "inc/openvz_stack.inc"
source "inc/siegeinstall.inc"
source "inc/python_install.inc"
source "inc/nginx_addvhost.inc"
source "inc/mariadb_upgrade.inc"
source "inc/mariadb_upgrade53.inc"
source "inc/mariadb_upgrade55.inc"
source "inc/mariadb_upgrade10.inc"
source "inc/nginx_errorpage.inc"
source "inc/sendmail.inc"
source "inc/postfix.inc"
source "inc/compress.inc"
source "inc/diskalert.inc"
source "inc/phpsededit.inc"
source "inc/csfinstall.inc"
source "inc/csftweaks.inc"
source "inc/xcache_installask.inc"
source "inc/xcache_install.inc"
source "inc/xcache_reinstall.inc"
source "inc/igbinary.inc"
source "inc/apcprotect.inc"
source "inc/apcinstall.inc"
source "inc/apcreinstall.inc"
source "inc/zendopcache_55ini.inc"
source "inc/zendopcache_install.inc"
source "inc/zendopcache_upgrade.inc"
source "inc/zendopcache_reinstall.inc"
source "inc/zendopcache_submenu.inc"
source "inc/ffmpeginstall.inc"
source "inc/shortcuts_install.inc"
source "inc/memcacheadmin.inc"
source "inc/mysqlsecure.inc"
source "inc/centminfinish.inc"
checkcentosver
mysqltmpdir
if [ ! -f /etc/centminmod-release ];then
echo "$SCRIPT_VERSION" > /etc/centminmod-release
else
if [[ "$SCRIPT_VERSION" != "$(cat /etc/centminmod-release)" ]]; then
echo "$SCRIPT_VERSION" > /etc/centminmod-release
fi
fi
if [ -f /etc/centminmod-versionlog ];then
if [[ "$SCRIPT_VERSION" != "$(cat /etc/centminmod-versionlog)" ]]; then
echo "$SCRIPT_VERSION #`date`" >> /etc/centminmod-versionlog
fi
else
echo "$SCRIPT_VERSION #`date`" >> /etc/centminmod-versionlog
fi
###############################################################
# The default is stable, you can change this to development if you wish
#ARCH_OVERRIDE='i386'
# Uncomment the above line if you are running a 32bit Paravirtulized Xen VPS
# on a 64bit host node.
# YOU SHOULD NOT NEED TO MODIFY ANYTHING BELOW THIS LINE +++++++++++++++++++
# JUST RUN chmod +x ./centmin.sh && ./centmin.sh
#
###############################################################
KEYPRESS_PARAM='-s -n1 -p' # Read a keypress without hitting ENTER.
# -s means do not echo input.
# -n means accept only N characters of input.
# -p means echo the following prompt before reading input
ASKCMD="read $KEYPRESS_PARAM "
# MACHINE_TYPE=`uname -m` # Used to detect if OS is 64bit or not.
CUR_DIR=`pwd` # Get current directory.
CM_INSTALLDIR=$CUR_DIR
###############################################################
# FUNCTIONS
if [[ "$CENTOSVER" = '6.0' || "$CENTOSVER" = '6.1' || "$CENTOSVER" = '6.2' || "$CENTOSVER" = '6.3' || "$CENTOSVER" = '6.4' || "$CENTOSVER" = '6.5' ]]; then
DOWNLOADAPP='axel -a'
WGETRETRY=''
AXELPHPTARGZ="-o php-${PHP_VERSION}.tar.gz"
AXELPHPUPGRADETARGZ="-o php-${phpver}.tar.gz"
else
DOWNLOADAPP="wget ${WGETOPT} --progress=bar"
WGETRETRY='--tries=3'
AXELPHPTARGZ=''
AXELPHPUPGRADETARGZ=''
fi
# if [ "${ARCH_OVERRIDE}" != '' ]
# then
# ARCH=${ARCH_OVERRIDE}
# else
# if [ ${MACHINE_TYPE} == 'x86_64' ];
# then
# ARCH='x86_64'
# MDB_ARCH='amd64'
# else
# ARCH='i386'
# fi
# fi
ASK () {
keystroke=''
while [[ "$keystroke" != [yYnN] ]]
do
$ASKCMD "$1" keystroke
echo "$keystroke";
done
key=$(echo $keystroke)
}
# Setup Colours
black='\E[30;40m'
red='\E[31;40m'
green='\E[32;40m'
yellow='\E[33;40m'
blue='\E[34;40m'
magenta='\E[35;40m'
cyan='\E[36;40m'
white='\E[37;40m'
boldblack='\E[1;30;40m'
boldred='\E[1;31;40m'
boldgreen='\E[1;32;40m'
boldyellow='\E[1;33;40m'
boldblue='\E[1;34;40m'
boldmagenta='\E[1;35;40m'
boldcyan='\E[1;36;40m'
boldwhite='\E[1;37;40m'
Reset="tput sgr0" # Reset text attributes to normal
#+ without clearing screen.
cecho () # Coloured-echo.
# Argument $1 = message
# Argument $2 = color
{
message=$1
color=$2
echo -e "$color$message" ; $Reset
return
}
###
unsetramdisk() {
if [[ "$RAMDISKTMPFS" = [yY] && "$TMPFSENABLED" = '1' ]]; then
echo
cecho "unmount $DIR_TMP tmpfs ramdisk & copy back to disk" $boldyellow
mkdir -p ${DIR_TMP}_disk
\cp -R ${DIR_TMP}/* ${DIR_TMP}_disk
# ls -lah ${DIR_TMP}_disk
diff -qr ${DIR_TMP} ${DIR_TMP}_disk
/etc/init.d/nginx stop
/etc/init.d/php-fpm stop
/etc/init.d/memcached stop
sleep 5
# lsof | grep /svr-setup
umount -l ${DIR_TMP}
/etc/init.d/nginx start
/etc/init.d/php-fpm start
/etc/init.d/memcached start
\cp -R ${DIR_TMP}_disk/* ${DIR_TMP}
# ls -lahrt ${DIR_TMP}
df -hT
cecho "unmounted $DIR_TMP tmpfs ramdisk" $boldyellow
fi
}
###
function funct_centmininstall {
#check centmin install previously
run_once() {
# If OpenVZ user add user/group 500 - else various folders and devices will end up with an odd user/group name for some reason
if [ -f /proc/user_beancounters ];
then
groupadd 500
useradd -g 500 -s /sbin/nologin -M 500
fi
#ASK "Would you like to update any pre-installed software? (Recommended) [y/n] "
#if [[ "$key" = [yY] ]];
#then
# echo "Let's do that then..."
# yum${CACHESKIP} -q clean all
# yum${CACHESKIP} -y update glibc\*
# yum${CACHESKIP} -y update yum\* rpm\* python\*
# yum${CACHESKIP} -q clean all
# yum${CACHESKIP} -y update
#fi
if [ ${ARCH} == 'x86_64' ];
then
if [ "$UNATTENDED" == 'n' ]; then
ASK "Would you like to exclude installation of 32bit Yum packages? (Recommended for 64bit CentOS) [y/n] "
else
key='y'
fi #unattended
if [[ "$key" = [yY] ]];
then
mv /etc/yum.conf /etc/yum.bak
cp $CUR_DIR/config/yum/yum.conf /etc/yum.conf
echo "Your origional yum configuration has been backed up to /etc/yum.bak"
else
rm -rf $CUR_DIR/config/yum
fi
fi
if [ "$UNATTENDED" == 'n' ]; then
ASK "Would you like to secure /tmp and /var/tmp? (Highly recommended) [y/n] "
else
key='y'
fi #unattended
if [[ "$key" = [yY] ]];
then
echo "Centmin Mod secure /tmp completed # `date`" > ${DIR_TMP}/securedtmp.log
echo "*************************************************"
cecho "* Secured /tmp and /var/tmp" $boldgreen
echo "*************************************************"
rm -rf /tmp
mkdir /tmp
mount -t tmpfs -o rw,noexec,nosuid tmpfs /tmp
chmod 1777 /tmp
echo "tmpfs /tmp tmpfs rw,noexec,nosuid 0 0" >> /etc/fstab
rm -rf /var/tmp
ln -s /tmp /var/tmp
fi
#questions
#yuminstall
if [ "$UNATTENDED" == 'n' ]; then
ASK "Would you like to set the server localtime? [y/n] "
else
key='y'
fi #unattended
if [[ "$key" = [yY] ]];
then
echo "*************************************************"
cecho "* Setting preferred localtime for VPS" $boldgreen
echo "*************************************************"
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/$ZONEINFO /etc/localtime
echo "Current date & time for the zone you selected is:"
date
fi
}
# END FUNCTIONS
################################################################
# SCRIPT START
#
clear
cecho "**********************************************************************" $boldyellow
cecho "* Centmin, an nginx, MariaDB/MySQL, PHP & DNS Install script for CentOS" $boldgreen
cecho "* Version: $SCRIPT_VERSION - Date: $SCRIPT_DATE" $boldgreen
cecho "* $COPYRIGHT $SCRIPT_MODIFICATION_AUTHOR" $boldgreen
cecho "**********************************************************************" $boldyellow
echo " "
cecho "This software comes with no warranty of any kind. You are free to use" $boldyellow
cecho "it for both personal and commercial use as licensed under the GPL." $boldyellow
echo " "
cecho "Please read the included readme.txt before using this script." $boldmagenta
echo " "
if [ "$UNATTENDED" == 'n' ]; then
ASK "Would you like to continue? [y/n] "
if [[ "$key" = [nN] ]];
then
exit 0
fi
fi #unattended
# Set LIBDIR
if [ ${ARCH} == 'x86_64' ];
then
LIBDIR='lib64'
else
LIBDIR='lib'
fi
#DIR_TMP="/svr-setup"
#if [ -a "$DIR_TMP" ];
#then
# ASK "It seems that you have run this script before, would you like to start from after setting the timezone? [y/n] "
# if [[ "$key" = [nN] ]];
# then
# run_once
# fi
#else
# mkdir $DIR_TMP
# run_once
#fi
if [ ! -f "${DIR_TMP}/securedtmp.log" ]; then
run_once
fi
if [ -f /proc/user_beancounters ];
then
cecho "OpenVZ system detected, NTP not installed" $boldgreen
else
if [[ "$NTP_INSTALL" = [yY] ]];
then
echo "*************************************************"
cecho "* Installing NTP (and syncing time)" $boldgreen
echo "*************************************************"
yum${CACHESKIP} -y install ntp
chkconfig --levels 235 ntpd on
ntpdate pool.ntp.org
echo "The date/time is now:"
date
echo "If this is correct, then everything is working properly"
echo "*************************************************"
cecho "* NTP installed" $boldgreen
echo "*************************************************"
fi
fi
ngxinstallmain
mariadbinstallfunct
mysqlinstallfunct
if [[ "$PHP_INSTALL" = [yY] ]];
then
echo "*************************************************"
cecho "* Installing PHP" $boldgreen
echo "*************************************************"
funct_centos6check
export PHP_AUTOCONF=/usr/bin/autoconf
export PHP_AUTOHEADER=/usr/bin/autoheader
cd $DIR_TMP
if [ "$(rpm -qa | grep php*)" ]; then
# IMPORTANT Erase any PHP installations first, otherwise conflicts may arise
echo "yum -y erase php*"
yum${CACHESKIP} -y erase php*
fi
#download php tarball
#tar xzvf php-${PHP_VERSION}.tar.gz
cd php-${PHP_VERSION}
./buildconf --force
mkdir fpm-build && cd fpm-build
mkdir -p /usr/${LIBDIR}/mysql
ln -s /usr/${LIBDIR}/libmysqlclient.so /usr/${LIBDIR}/mysql/libmysqlclient.so
funct_phpconfigure
cd ../
#######################################################
# check to see if centmin custom php.ini already in place
CUSTOMPHPINICHECK=`grep 'realpath_cache_size = 1024k' /usr/local/lib/php.ini 2>/dev/null`
if [[ -z $CUSTOMPHPINICHECK ]]; then
cp -f php.ini-production /usr/local/lib/php.ini
chmod 644 /usr/local/lib/php.ini
phpsededit
fi # check to see if centmin custom php.ini already in place
echo
#read -ep "Does this server have less than <=2048MB of memory installed ? [y/n]: " lessphpmem
#echo
#echo
if [[ "$lessphpmem" = [yY] ]]; then
echo $lessphpmem
echo -e "\nCopying php-fpm-min.conf /usr/local/etc/php-fpm.conf\n"
cp $CUR_DIR/config/php-fpm/php-fpm-min.conf /usr/local/etc/php-fpm.conf
else
echo $lessphpmem
echo -e "\nCopying php-fpm.conf /usr/local/etc/php-fpm.conf\n"
cp $CUR_DIR/config/php-fpm/php-fpm.conf /usr/local/etc/php-fpm.conf
fi
cp $CUR_DIR/init/php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
mkdir -p /var/run/php-fpm
touch /var/run/php-fpm/php-fpm.pid
chown nginx:nginx /var/run/php-fpm
chown root:root /var/run/php-fpm/php-fpm.pid
mkdir /var/log/php-fpm/
touch /var/log/php-fpm/www-error.log
touch /var/log/php-fpm/www-php.error.log
chmod 0666 /var/log/php-fpm/www-error.log
chmod 0666 /var/log/php-fpm/www-php.error.log
fpmconfdir
#chown -R root:nginx /var/lib/php/session/
chkconfig --levels 235 php-fpm on
#/etc/init.d/php-fpm restart 2>/dev/null
# /etc/init.d/php-fpm force-quit
/etc/init.d/php-fpm start
if [[ `grep exclude /etc/yum.conf` && $MDB_INSTALL = y ]]; then
cecho "exclude line exists... adding nginx* mysql* php* exclusions" $boldgreen
sed -i "s/exclude=\*.i386 \*.i586 \*.i686 mysql\*/exclude=\*.i386 \*.i586 \*.i686 nginx\* mysql\* php\*/" /etc/yum.conf
sed -i "s/exclude=mysql\*/exclude=mysql\* php\*/" /etc/yum.conf
elif [[ `grep exclude /etc/yum.conf` ]]; then
cecho "exclude line exists... adding nginx* php* exclusions" $boldgreen
sed -i "s/exclude=\*.i386 \*.i586 \*.i686/exclude=\*.i386 \*.i586 \*.i686 nginx\* php\*/" /etc/yum.conf
fi
if [[ ! `grep exclude /etc/yum.conf` && $MDB_INSTALL = y ]]; then
cecho "Can't find exclude line in /etc/yum.conf.. adding exclude line for nginx* mysql* php*" $boldgreen
echo "exclude=nginx* mysql* php*">> /etc/yum.conf
elif [[ ! `grep exclude /etc/yum.conf` ]]; then
cecho "Can't find exclude line in /etc/yum.conf... adding exclude line for nginx* php*" $boldgreen
echo "exclude=nginx* php*">> /etc/yum.conf
fi
funct_logphprotate
echo "*************************************************"
cecho "* PHP installed" $boldgreen
echo "*************************************************"
fi
xcacheinstall_ask
#if [ "$xcacheinstallcheck" != 'y' ]; then
#cecho "* If you installed Xcache, DO NOT install APC" $boldgreen
#fi # xcacheinstallcheck
#ASK "Install APC? (By default uses 32MB RAM) [y/n] "
# if ZOPCACHEDFT override enabled = yY then skip APC Cache install
if [[ "$APCINSTALL" = [yY] && "$ZOPCACHEDFT" = [nN] ]]; then
funct_apcsourceinstall
fi
# if ZOPCACHEDFT override enabled = yY and PHP_VERSION is not 5.5
# install Zend OpCache PECL extesnion otherwise if PHP_VERSION = 5.5
# then php_configure.inc routine will pick up PHP_VERSION 5.5 and install
# native Zend OpCache when ZOPCACHEDFT=yY
PHPMVER=$(echo "$PHP_VERSION" | cut -d . -f1,2)
if [[ "$APCINSTALL" = [nN] || "$ZOPCACHEDFT" = [yY] && "$PHPMVER" != '5.5' ]]; then
zopcacheinstall
fi
# if PHP_VERSION = 5.5 will need to setup a zendopcache.ini settings file
if [[ "$APCINSTALL" = [nN] || "$ZOPCACHEDFT" = [yY] && "$PHPMVER" = '5.5' ]]; then
zopcache_initialini
fi
# igbinary still needed for libmemcached PHP extension if ZOPCACHE=yY
if [[ "$APCINSTALL" = [nN] || "$ZOPCACHEDFT" = [yY] ]]; then
funct_igbinaryinstall
fi
if [[ "$SENDMAIL_INSTALL" = [yY] && "$POSTFIX_INSTALL" = [nN] ]]; then
if [[ ! -f /etc/init.d/postfix && ! -f /etc/init.d/sendmail ]]; then
echo "*************************************************"
cecho "* Installing sendmail" $boldgreen
echo "*************************************************"
yum${CACHESKIP} -y -q install sendmail mailx sendmail-cf
chkconfig --levels 235 sendmail on
funct_sendmailmc
echo "*************************************************"
cecho "* sendmail installed" $boldgreen
echo "*************************************************"
elif [[ -f /etc/init.d/postfix ]]; then
if [ ! -f /bin/mail ]; then
yum${CACHESKIP} -y -q install mailx
fi
postfixsetup
echo "*************************************************"
cecho "Postfix already detected, sendmail install aborted" $boldgreen
echo "*************************************************"
elif [[ -f /etc/init.d/sendmail ]]; then
if [ ! -f /bin/mail ]; then
yum${CACHESKIP} -y -q install mailx
fi
chkconfig --levels 235 sendmail on
funct_sendmailmc
echo "*************************************************"
cecho "sendmail already detected, sendmail install aborted" $boldgreen
echo "*************************************************"
fi
fi
if [[ "$SENDMAIL_INSTALL" = [yY] && "$POSTFIX_INSTALL" = [yY] ]]; then
if [[ ! -f /etc/init.d/postfix && ! -f /etc/init.d/sendmail ]]; then
echo "*************************************************"
cecho "* Installing postfix" $boldgreen
echo "*************************************************"
yum${CACHESKIP} -y -q install postfix mailx
postfixsetup
echo "*************************************************"
cecho "* postfix installed" $boldgreen
echo "*************************************************"
elif [[ -f /etc/init.d/postfix ]]; then
if [ ! -f /bin/mail ]; then
yum${CACHESKIP} -y -q install mailx
fi
postfixsetup
echo "*************************************************"
cecho "Postfix already detected, postfix install aborted" $boldgreen
echo "*************************************************"
elif [[ -f /etc/init.d/sendmail ]]; then
yum${CACHESKIP} -y -q remove sendmail sendmail-cf
yum${CACHESKIP} -y -q install postfix mailx
postfixsetup
echo "*************************************************"
cecho "* postfix installed" $boldgreen
echo "*************************************************"
fi
fi
if [[ "$POSTFIX_INSTALL" = [yY] && "$SENDMAIL_INSTALL" = [nN] ]]; then
if [[ ! -f /etc/init.d/postfix && ! -f /etc/init.d/sendmail ]]; then
echo "*************************************************"
cecho "* Installing postfix" $boldgreen
echo "*************************************************"
yum${CACHESKIP} -y -q install postfix mailx
postfixsetup
echo "*************************************************"
cecho "* postfix installed" $boldgreen
echo "*************************************************"
elif [[ -f /etc/init.d/postfix ]]; then
if [ ! -f /bin/mail ]; then
yum${CACHESKIP} -y -q install mailx
fi
postfixsetup
echo "*************************************************"
cecho "Postfix already detected, postfix install aborted" $boldgreen
echo "*************************************************"
elif [[ -f /etc/init.d/sendmail ]]; then
yum${CACHESKIP} -y -q remove sendmail sendmail-cf
yum${CACHESKIP} -y -q install postfix mailx
postfixsetup
echo "*************************************************"
cecho "* postfix installed" $boldgreen
echo "*************************************************"
fi
fi
incmemcachedinstall
csfinstalls
siegeinstall
installpythonfuct
imagickinstall
nsdinstall
if [ -f $CUR_DIR/Extras/nginx-update.sh ];
then
chmod +x $CUR_DIR/Extras/nginx-update.sh
fi
echo " "
shortcutsinstall
echo " "
cecho "**********************************************************************" $boldgreen
cecho "* Starting Services..." $boldgreen
cecho "**********************************************************************" $boldgreen
if [[ "$NSD_INSTALL" = [yY] ]];
then
/etc/init.d/nsd start
fi
if [ -f /etc/init.d/ntpd ];
then
/etc/init.d/ntpd start
fi
if [[ "$NGINX_INSTALL" = [yY] ]];
then
/etc/init.d/nginx start
fi
if [[ "$MDB_INSTALL" = [yY] || "$MDB_YUMREPOINSTALL" = [yY] ]];
then
/etc/init.d/mysql start
fi
if [[ "$MYSQL_INSTALL" = [yY] ]];
then
/etc/init.d/mysqld start
fi
echo " "
echo " "
cd
if [[ "$ENABLE_MENU" != [yY] ]]; then
ASK "Do would you like to run script cleanup (Highly recommended) ? [y/n] "
if [[ "$key" = [yY] ]];
then
rm -rf $DIR_TMP
rm -rf $CUR_DIR/config
rm -rf $CUR_DIR/init
rm -rf $CUR_DIR/sysconfig
echo "Temporary files/folders removed"
fi
ASK "Do you want to delete this script ? [y/n] "
if [[ "$key" = [yY] ]];
then
echo "*************************************************"