-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·2177 lines (2100 loc) · 76.5 KB
/
build.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/bash
# Auto Install services on CentOS - Ubuntu
# Version: 1.0
# Author: mbrother
# Set variables
SCRIPT_NAME=$0
ALL_OPTIONS="$@"
GO_VERSION="go1.12.5.linux-amd64"
RANDOM_STRING=`date +%s | sha256sum | base64 | head -c 12`
BUILD_TMP="/root/buildeverything_${RANDOM_STRING}"
DIR=`pwd`
GITHUB_LINK="https://raw.githubusercontent.com/mbrother2/buildeverything/master"
MARIADB_MIRROR="http://sgp1.mirrors.digitalocean.com"
LOG_FILE="/var/log/buildeverything.log"
DEFAULT_DIR_WEB="/var/www/html"
REMI_DIR="/etc/opt/remi"
LSWS_DIR="/usr/local/lsws"
VHOST_DIR="/etc/nginx/conf.d"
SHOW_SERVICE=$(echo "Service Version Installed Running"
echo "------- ------- --------- -------")
# List exclude mirrors
List_CentOS_epel=(mirror.xeonbd.com ftp.iij.ad.jp ftp.jaist.ac.jp)
# List support
List_OS=(CentOS Ubuntu)
List_CentOS=(6 7 8)
List_Ubuntu=(16.04 18.04 20.04)
List_MARIADB=(5.5 10.0 10.1 10.2 10.3 10.4 10.5)
List_NODEJS=(8.x 9.x 10.x 11.x 12.x 14.x)
List_BACKUP=(all gdrive rclone restic)
List_CACHE=(all memcached redis)
List_FTP=(proftpd pure-ftpd vsftpd)
List_WEB=(httpd openlitespeed nginx)
List_EXTRA=(all phpmyadmin vnstat)
List_SECURITY=(all acme_sh certbot clamav csf imunify)
List_STACK=(lamp lemp lomp)
List_SKIP_ACTION=(all no-update no-preinstall no-start)
# Default services & version
PMD_VERSION_MAX="5.0.2"
PMD_VERSION_COMMON="4.9.5"
RESTIC_VERSION="0.9.6"
DEFAULT_BACKUP_SERVICE="rclone"
DEFAULT_FTP_SERVER="pure-ftpd"
DEFAULT_PHP_VERSION="7.4"
DEFAULT_SQL_SERVER="10.4"
DEFAULT_WEB_SERVER="nginx"
DEFAULT_NODEJS="12.x"
DEFAULT_VNSTAT_VERSION="2.6"
DEFAULT_EXTRA_SERVICE="phpmyadmin"
DEFAULT_SECURITY_SERVICE="csf"
# Set colors
REMOVE='\e[0m'
RED='\e[31m'
GREEN='\e[32m'
YELLOW='\e[33m'
WHITE='\e[39m'
# Check OS
_check_os(){
OS_ARCH=`uname -m`
if [ -f /etc/redhat-release ]
then
OS_NAME=`cat /etc/redhat-release | awk '{print $1}'`
PKG_MANAGER="RPM"
INSTALL_CM="yum"
OS_VERSION=`rpm -E %centos`
if [ "${OS_VERSION}" == "8" ]
then
List_PHP=(all 5.6 7.0 7.1 7.2 7.3 7.4)
else
List_PHP=(all 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4)
fi
elif [ -f /usr/bin/lsb_release ]
then
OS_NAME=`lsb_release -is`
OS_NAME_LOWER=`echo "${OS_NAME}" | awk '{print tolower($0)}'`
OS_CODENAME=`lsb_release -cs | awk '{print tolower($0)}'`
PKG_MANAGER="DEB"
INSTALL_CM="apt"
OS_VERSION=`lsb_release -rs`
OS_VERSION_MIN=`echo "${OS_VERSION}" | sed 's/\.//'`
if [ "${OS_NAME}" == "Ubuntu" ]
then
List_PHP=(all 5.6 7.0 7.1 7.2 7.3 7.4)
fi
fi
_check_value_in_list "OS" "${OS_NAME}" "${List_OS[*]}"
if [ -f /etc/redhat-release ]
then
_check_value_in_list "CentOS" "${OS_VERSION}" "${List_CentOS[*]}"
elif [ -f /usr/bin/lsb_release ]
then
_check_value_in_list "Ubuntu" "${OS_VERSION}" "${List_Ubuntu[*]}"
fi
}
# Trap press Ctrl + C
trap ctrl_c INT
ctrl_c(){
echo ""
_show_log -d -y " [WARN]" -w " You press Ctrl + C. Exit!"
_exit_build 0
}
_exit_build(){
rm -rf ${BUILD_TMP}
exit $1
}
# Check user root
_check_user_root(){
if [ $EUID -ne 0 ]
then
echo -e "`date "+[ %d/%m/%Y %H:%M:%S ]"` ${RED}[FAIL]${REMOVE} You must be ${GREEN}root${REMOVE} to run build.sh, please switch to root user then run again!"
exit 1
fi
}
# Print log
_print_log(){
if [ ${SUM_ARG} -eq ${OPTIND} ]
then
printf "$1${OPTARG}${REMOVE}""\n" | tee -a ${LOG_FILE}
else
printf "$1${OPTARG}${REMOVE}" | tee -a ${LOG_FILE}
fi
}
# Show log
_show_log(){
OPTIND=1
SUM_ARG=$(($#+1))
while getopts 'r:g:y:w:d' OPTION
do
case ${OPTION} in
d) _print_log "`date "+[ %d/%m/%Y %H:%M:%S ]"`" ;;
r) _print_log "${RED}" ;;
g) _print_log "${GREEN}" ;;
y) _print_log "${YELLOW}" ;;
w) _print_log "${WHITE}" ;;
esac
done
}
# Check network
_check_network(){
_show_log -d -g " [INFO]" -w " Cheking network..."
curl -sI raw.githubusercontent.com >/dev/null
if [ $? -eq 0 ]
then
_show_log -d -g " [INFO]" -w " Connect Github successful!"
else
_show_log -d -r " [FAIL]" -w " Can not connect to Github file, please check your network. Exit!"
_exit_build 1
fi
}
# Start time
_start_install(){
TIME_BEGIN=`date +%s`
echo "---" >> ${LOG_FILE}
echo -e "$(date "+[ %d/%m/%Y %H:%M:%S ]") ${GREEN}[INFO]${REMOVE} Run command: ${RED}${SCRIPT_NAME} ${ALL_OPTIONS}${REMOVE}" >> ${LOG_FILE}
}
# End time
_end_install(){
TIME_END=`date +%s`
TIME_RUN=`date -d@$(( ${TIME_END} - ${TIME_BEGIN} )) -u +%Hh%Mm%Ss`
_show_log -d -g " [INFO]" -w " Run time: ${TIME_RUN}"
if [ ! -z "${SHOW_INFO}" ]
then
echo "${SHOW_INFO}"
fi
echo ""
echo "---"
echo "Ensure all services are installed and running."
echo ""
echo "${SHOW_SERVICE}" | column -t
_exit_build 0
}
# Create necessary directory
_create_dir(){
for i in ${DEFAULT_DIR_WEB} ${BUILD_TMP}
do
if [ ! -d $i ]
then
mkdir -p $i
fi
done
}
# Check if cPanel, DirectAdmin, Plesk has installed before
_check_control_panel(){
_show_log -d -g " [INFO]" -w " Checking if cPanel, DirectAdmin, Plesk has installed before..."
if [ -f /usr/local/cpanel/cpanel ]
then
_show_log -d -r " [FAIL]" -w " Detected cPanel is installed on this server. Please use minimal OS without any control panel to use buildmce !"
_exit_build 1
elif [ -f /usr/local/directadmin/custombuild/build ]
then
_show_log -d -r " [FAIL]" -w " Detected DirectAdmin is installed on this server. Please use minimal OS without any control panel to use buildmce !"
_exit_build 1
elif [ -f /usr/local/psa/version ]
then
_show_log -d -r " [FAIL]" -w " Detected Plesk is installed on this server. Please use minimal OS without any control panel to use buildmce !"
_exit_build 1
else
_show_log -d -g " [INFO]" -w " No control panel detected. Continue..."
fi
}
# Check option in a list
_check_value_in_list(){
NAME=$1
VALUE=$2
List_VALUE=($3)
false
for i_CHECK_VALUE in ${List_VALUE[*]}
do
if [ "${i_CHECK_VALUE}" == "${VALUE}" ]
then
true
break
else
false
fi
done
if [ $? -ne 0 ]
then
_show_log -d -r " [FAIL]" -w " Not support $1:" -r " $2" -w ". Only support: $(echo ${List_VALUE[*]} | sed 's/ /|/g')"
_exit_build 1
fi
}
# Check exclude service
_check_exclude(){
VAR=$1
if [ ! -z "${EXCLUDE_SERVICE}" ]
then
CHECK_EXCLUDE=`echo "${EXCLUDE_SERVICE[@]}" | tr ' ' '\n' | grep -c "^$4$3$"`
if [ ${CHECK_EXCLUDE} -ne 0 ]
then
eval "$VAR"=\( "${2/$3/}" \)
fi
fi
}
# Get options
_get_option(){
if [ -z $4 ]
then
_show_log -d -r " [FAIL]" -w " Missing argument for option ${RED}$2${REMOVE}. Exit!"
_exit_build 1
else
if [ "$1" == "single" ]
then
eval "$3"="$4"
elif [ "$1" == "multi" ]
then
eval "$3"+=\( $4 \)
fi
fi
}
# Check installed service
_check_installed_service(){
CHECK_SERVICE=`command -v $1`
if [ "$2" == "new" ]
then
if [ -z ${CHECK_SERVICE} ]
then
_show_log -d -r " [FAIL]" -w " Can not install $1. Exit"
_exit_build 1
else
_show_log -d -g " [INFO]" -w " Install $1 sucessful!"
fi
else
if [ -z ${CHECK_SERVICE} ]
then
_show_log -d -r " [FAIL]" -w " $1 is not installed!"
return 1
else
_show_log -d -g " [INFO]" -w " $1 is installed!"
return 0
fi
fi
}
# Show Yes or No
_yes_no(){
if [ ${1} -eq 2 ]
then
echo ""
elif [ ${1} -eq 1 ]
then
echo "Yes"
else
echo "No"
fi
}
# Detect web server
_detect_web_server(){
if [ -z "${WEB_SERVER}" ]
then
_show_log -d -g " [INFO]" -w " Detecting web server..."
if [ -z "${GET_WEB_SERVER}" ]
then
CHECK_HTTPD_RUNNING=`_check_service -r httpd`
CHECK_NGINX_RUNNING=`_check_service -r nginx`
CHECK_OLS_RUNNING=`_check_service -r litespeed`
if [ ${CHECK_HTTPD_RUNNING} -eq 1 ]
then
_show_log -d -g " [INFO]" -w " Detected httpd running."
WEB_SERVER="httpd"
elif [ ${CHECK_NGINX_RUNNING} -eq 1 ]
then
_show_log -d -g " [INFO]" -w " Detected nginx running."
WEB_SERVER="nginx"
elif [ ${CHECK_OLS_RUNNING} -eq 1 ]
then
_show_log -d -g " [INFO]" -w " Detected openlitespeed running."
WEB_SERVER="openlitespeed"
else
_show_log -d -g " [INFO]" -w " Can not detect web server is running!"
echo ""
echo "Do you want to install $1 for httpd or nginx or openlitespeed?"
echo "1. httpd"
echo "2. nginx"
echo "3. openlitespeed"
read -p "Your choice: " WEB_SERVER_CHOICE
until [[ "${WEB_SERVER_CHOICE}" == 1 ]] || [[ "${WEB_SERVER_CHOICE}" == 2 ]] || [[ "${WEB_SERVER_CHOICE}" == 3 ]]
do
echo "Please choose 1 or 2 or 3!"
read -p "Your choice: " WEB_SERVER_CHOICE
done
if [ ${WEB_SERVER_CHOICE} -eq 1 ]
then
WEB_SERVER="httpd"
elif [ ${WEB_SERVER_CHOICE} -eq 2 ]
then
WEB_SERVER="nginx"
else
WEB_SERVER="openlitespeed"
fi
_show_log -d -g " [INFO]" -w " You choose web server" -r " ${WEB_SERVER}"
fi
else
WEB_SERVER=${GET_WEB_SERVER}
_show_log -d -g " [INFO]" -w " Web server is ${GET_WEB_SERVER}."
fi
fi
}
# Detect service running at port
_detect_port_used(){
_show_log -d -g " [INFO]" -w " Detecting service is running at port $2..."
CHECK_PORT=`netstat -lntp | grep -e " 0.0.0.0:$2 " -e " 127.0.0.1:$2 " -e " :::$2 " | awk '{print $7}' | cut -d"/" -f2 | sed 's/://' | sed 's/.conf//' | uniq`
if [ -z ${CHECK_PORT} ]
then
_show_log -d -g " [INFO]" -w " No service is running at port $2."
else
_show_log -d -g " [INFO]" -w " Detected ${CHECK_PORT} is running at port $2!"
if [ "${CHECK_PORT}" != "$1" ]
then
_show_log -d -g " [INFO]" -w " Trying stop ${CHECK_PORT}..."
if [ -f /bin/systemctl ]
then
systemctl stop ${CHECK_PORT}
else
service ${CHECK_PORT} stop
fi
CHECK_PORT_AGAIN=`netstat -lntp | grep -e " 0.0.0.0:$2 " -e " 127.0.0.1:$2 " -e " :::$2 " | awk '{print $7}' | cut -d"/" -f2 | sed 's/://' | sed 's/.conf//' | uniq`
if [ ! -z ${CHECK_PORT_AGAIN} ]
then
_show_log -d -y " [WARN]" -w " Can not stop ${CHECK_PORT}!"
CANNOT_STOP_PORT="CANNOT_STOP_PORT_$2"
eval "$CANNOT_STOP_PORT"=1
else
_show_log -d -g " [INFO]" -w " Stop ${CHECK_PORT} sucessful!"
fi
fi
fi
}
#######################
# Check input options #
#######################
# Check informations
_check_info(){
_show_log -d -g " [INFO]" -w " Checking input options..."
if [ "${INSTALL_COMMON}" == "1" ]
then
GET_FTP_SERVER=${GET_FTP_SERVER:-$DEFAULT_FTP_SERVER}
GET_PHP_VERSION=${GET_PHP_VERSION:-$DEFAULT_PHP_VERSION}
GET_MARIADB=${GET_MARIADB:-$DEFAULT_SQL_SERVER}
GET_NODEJS=${GET_NODEJS:-$DEFAULT_NODEJS}
GET_WEB_SERVER=${GET_WEB_SERVER:-$DEFAULT_WEB_SERVER}
EXTRA_SERVICE=( "${List_EXTRA[@]:1}" )
SECURITY_SERVICE=( "${List_SECURITY[@]:1}" )
elif [ ! -z "${GET_STACK}" ]
then
GET_FTP_SERVER=${GET_FTP_SERVER:-$DEFAULT_FTP_SERVER}
GET_PHP_VERSION=${GET_PHP_VERSION:-$DEFAULT_PHP_VERSION}
GET_MARIADB=${GET_MARIADB:-$DEFAULT_SQL_SERVER}
if [ "${GET_STACK}" == "lamp" ]
then
GET_WEB_SERVER="httpd"
elif [ "${GET_STACK}" == "lemp" ]
then
GET_WEB_SERVER="nginx"
elif [ "${GET_STACK}" == "lomp" ]
then
GET_WEB_SERVER="openlitespeed"
fi
EXTRA_SERVICE=${EXTRA_SERVICE:-$DEFAULT_EXTRA_SERVICE}
SECURITY_SERVICE=${SECURITY_SERVICE:-$DEFAULT_SECURITY_SERVICE}
fi
if [ ! -z "${SKIP_ACTION}" ]
then
if [ "${SKIP_ACTION}" == "all" ]
then
SKIP_ACTION=( "${List_SKIP_ACTION[@]:1}" )
NO_UPDATE=1
NO_PRE_INSTALL=1
NO_START=1
else
for i_SKIP_ACTION in ${SKIP_ACTION[*]}
do
if [ "${i_SKIP_ACTION}" == "no-update" ]
then
NO_UPDATE=1
elif [ "${i_SKIP_ACTION}" == "no-preinstall" ]
then
NO_PRE_INSTALL=1
elif [ "${i_SKIP_ACTION}" == "no-start" ]
then
NO_START=1
fi
done
fi
SHOW_OPTIONS=$(echo "Skip action : ${SKIP_ACTION[*]}")
fi
if [ ! -z "${GET_BACKUP_SERVICE}" ]
then
if [ "${GET_BACKUP_SERVICE}" == "all" ]
then
GET_BACKUP_SERVICE=( "${List_BACKUP[@]:1}" )
fi
for i_GET_BACKUP_SERVICE in ${GET_BACKUP_SERVICE[*]}
do
_check_exclude GET_BACKUP_SERVICE "${GET_BACKUP_SERVICE[*]}" "${i_GET_BACKUP_SERVICE}"
done
if [ ! -z "${GET_BACKUP_SERVICE}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "Backup : ${GET_BACKUP_SERVICE[*]}")
INSTALL_SERVICE+=("${GET_BACKUP_SERVICE[*]}")
fi
fi
if [ ! -z "${GET_CACHE_SERVICE}" ]
then
if [ "${GET_CACHE_SERVICE}" == "all" ]
then
GET_CACHE_SERVICE=( "${List_CACHE[@]:1}" )
fi
for i_CACHE_SERVICE in ${GET_CACHE_SERVICE[*]}
do
_check_exclude GET_CACHE_SERVICE "${GET_CACHE_SERVICE[*]}" "${i_CACHE_SERVICE}"
done
if [ ! -z "${GET_CACHE_SERVICE}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "Cache : ${GET_CACHE_SERVICE[*]}")
INSTALL_SERVICE+=("${GET_CACHE_SERVICE[*]}")
fi
fi
if [ ! -z "${GET_FTP_SERVER}" ]
then
_check_exclude GET_FTP_SERVER "${GET_FTP_SERVER[*]}" "${GET_FTP_SERVER}"
if [ ! -z "${GET_FTP_SERVER}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "FTP server : ${GET_FTP_SERVER}")
INSTALL_SERVICE+=("${GET_FTP_SERVER}")
fi
fi
if [ ! -z "${GET_PHP_VERSION}" ]
then
if [ "${GET_PHP_VERSION}" == "all" ]
then
GET_PHP_VERSION=( "${List_PHP[@]:1}" )
fi
for i_GET_PHP_VERSION in ${GET_PHP_VERSION[*]}
do
_check_exclude GET_PHP_VERSION "${GET_PHP_VERSION[*]}" "${i_GET_PHP_VERSION}" "php"
done
if [ ! -z "${GET_PHP_VERSION}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "PHP version : ${GET_PHP_VERSION[*]}")
GET_PHP_VERSION_PREFIX=( "${GET_PHP_VERSION[@]/#/php}" )
INSTALL_SERVICE+=("${GET_PHP_VERSION_PREFIX[*]}")
fi
fi
if [ ! -z "${GET_NODEJS}" ]
then
_check_exclude GET_NODEJS "${GET_NODEJS[*]}" "${GET_NODEJS}" "nodejs"
if [ ! -z "${GET_NODEJS}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "Nodejs version : ${GET_NODEJS}")
INSTALL_SERVICE+=("node")
fi
fi
if [ ! -z "${GET_MARIADB}" ]
then
_check_exclude GET_MARIADB "${GET_MARIADB[*]}" "${GET_MARIADB}" "mariadb"
if [ ! -z "${GET_MARIADB}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "MariaDB version: ${GET_MARIADB}")
INSTALL_SERVICE+=("mariadb")
fi
fi
if [ ! -z "${GET_WEB_SERVER}" ]
then
_check_exclude GET_WEB_SERVER "${GET_WEB_SERVER[*]}" "${GET_WEB_SERVER}"
if [ ! -z "${GET_WEB_SERVER}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "Web server : ${GET_WEB_SERVER}")
INSTALL_SERVICE+=("${GET_WEB_SERVER}")
fi
fi
if [ ! -z "${EXTRA_SERVICE}" ]
then
if [ "${EXTRA_SERVICE}" == "all" ]
then
EXTRA_SERVICE=( "${List_EXTRA[@]:1}" )
fi
for i_EXTRA_SERVICE in ${EXTRA_SERVICE[*]}
do
_check_exclude EXTRA_SERVICE "${EXTRA_SERVICE[*]}" "${i_EXTRA_SERVICE}"
done
if [ ! -z "${EXTRA_SERVICE}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "Extra service : ${EXTRA_SERVICE[*]}")
INSTALL_SERVICE+=("${EXTRA_SERVICE[*]}")
fi
fi
if [ ! -z "${SECURITY_SERVICE}" ]
then
if [ "${SECURITY_SERVICE}" == "all" ]
then
SECURITY_SERVICE=( "${List_SECURITY[@]:1}" )
fi
for i_SECURITY_SERVICE in ${SECURITY_SERVICE[*]}
do
_check_exclude SECURITY_SERVICE "${SECURITY_SERVICE[*]}" "${i_SECURITY_SERVICE}"
done
if [ ! -z "${SECURITY_SERVICE}" ]
then
SHOW_OPTIONS=$(echo "${SHOW_OPTIONS}"
echo "Security : ${SECURITY_SERVICE[*]}")
INSTALL_SERVICE+=("${SECURITY_SERVICE[*]}")
fi
fi
_show_log -d -g " [INFO]" -w " Check input options sucessful!"
echo ""
if [ -z "${INSTALL_SERVICE}" ]
then
_show_log -d -y " [WARN]" -w " Nothing to install. Exit!"
_exit_build 0
fi
echo "We will install following services:"
echo "---"
echo "${SHOW_OPTIONS}"
if [ "${GET_BACKUP_SERVICE}" == "gdrive" ]
then
echo ""
echo -e "${YELLOW}[WARNING]${REMOVE} gdrive project have not been updated in a long time. Recommend to use ${GREEN}rclone${REMOVE} to backup your data to Google Drive!"
fi
echo ""
echo -e "If that is exactly what you need, please type ${GREEN}Yes${REMOVE} with caption ${GREEN}Y${REMOVE} to install or press ${RED}Ctrl + C${REMOVE} to cancel!"
CHOICE_INSTALL="No"
read -p "Your choice: " CHOICE_INSTALL
while [ "${CHOICE_INSTALL}" != "Yes" ]
do
echo -e "Please type ${GREEN}Yes${REMOVE} with caption ${GREEN}Y${REMOVE} to install or press ${RED}Ctrl + C${REMOVE} to cancel!"
read -p "Your choice: " CHOICE_INSTALL
done
}
# Pre-install
_pre_install(){
if [ "${NO_PRE_INSTALL}" != "1" ]
then
echo ""
_show_log -d -g " [INFO]" -w " Installing require packages..."
sleep 1
if [ "${PKG_MANAGER}" == "RPM" ]
then
# Disable SELINUX, stop iptables( CentOS 6) or firewalld( CentOS 7) & disable on boot
if [ -f /bin/systemctl ]
then
systemctl stop firewalld
systemctl disable firewalld
else
service iptables stop
chkconfig iptables off
fi
CHECK_SELINUX=`cat /etc/selinux/config | grep -c "^SELINUX=disabled"`
if [ ${CHECK_SELINUX} -eq 0 ]
then
mv /etc/selinux/config /etc/selinux/config.orig
cat /etc/selinux/config.orig | sed 's/^SELINUX/#SELINUX/g' > /etc/selinux/config
echo "SELINUX=disabled" >> /etc/selinux/config
echo "SELINUXTYPE=targeted" >> /etc/selinux/config
fi
# Install some require packages
yum -y install epel-release
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-${OS_VERSION}.rpm
sed -i "/^gpgkey=.*/a exclude = $(echo ${List_CentOS_epel[*]} | sed 's/ /, /g')" /etc/yum.repos.d/epel.repo
yum -y install wget unzip net-tools pv socat bind-utils
elif [ "${PKG_MANAGER}" == "DEB" ]
then
# Install some require packages
apt-get -y install software-properties-common debconf-utils libwww-perl unzip net-tools
if [ ${OS_VERSION_MIN} -lt 1804 ]
then
apt-get -y install gnupg-curl
fi
fi
echo ""
if [ $? -eq 0 ]
then
_show_log -d -g " [INFO]" -w " Install require packages sucessful!"
else
_show_log -d -g " [FAIL]" -w " Can not install require packages! Exit."
_exit_build 1
fi
fi
}
# Update system
_update_sys(){
if [ "${NO_UPDATE}" != "1" ]
then
echo ""
_show_log -d -g " [INFO]" -w " Updating system..."
sleep 1
if [ "${PKG_MANAGER}" == "RPM" ]
then
yum -y update
elif [ "${PKG_MANAGER}" == "DEB" ]
then
apt-get update -y
apt-get upgrade -y
apt-get dist-upgrade -y
fi
echo ""
_show_log -d -g " [INFO]" -w " Update system sucessful!"
fi
}
####################
# Install services #
####################
# Install PHP
_install_php(){
if [ ! -z "${GET_PHP_VERSION}" ]
then
echo ""
_show_log -d -g " [INFO]" -w " Installing PHP..."
sleep 1
_detect_web_server php
if [ "${PKG_MANAGER}" == "RPM" ]
then
if [ "${OS_VERSION}" == "8" ]
then
dnf config-manager --set-enabled PowerTools
else
yum -y install centos-release-scl-rh
yum -y --enablerepo=centos-sclo-rh-testing install devtoolset-6-gcc-c++
fi
if [ "${WEB_SERVER}" == "openlitespeed" ]
then
PHP_PREFIX="lsphp"
PHP_SUFFIX=""
rpm -ivh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el${OS_VERSION}.noarch.rpm
else
PHP_PREFIX="php"
PHP_SUFFIX="-php"
fi
for i_INSTALL_PHP in ${GET_PHP_VERSION[*]}
do
PHP_VERSION_MIN=`echo ${i_INSTALL_PHP} | sed 's/\.//'`
echo ""
_show_log -d -g " [INFO]" -w " Installing php${PHP_VERSION_MIN}..."
if [ "${WEB_SERVER}" == "openlitespeed" ]
then
PHP_ENABLE_REPO=""
else
if [ "${OS_VERSION}" == "8" ]
then
PHP_ENABLE_REPO="--enablerepo=remi"
else
PHP_ENABLE_REPO="--enablerepo=remi-php${PHP_VERSION_MIN}"
fi
fi
yum -y ${PHP_ENABLE_REPO} install \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX} \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-curl \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-devel \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-exif \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-fileinfo \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-filter \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-gd \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-hash \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-imap \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-intl \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-json \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-mbstring \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-mcrypt \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-mysqlnd \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-session \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-soap \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-simplexml \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-xml \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-xmlrpc \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-xsl \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-zip \
${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-zlib
if [ "${WEB_SERVER}" == "openlitespeed" ]
then
if [ -f /usr/local/lsws/lsphp${PHP_VERSION_MIN}/bin/lsphp ]
then
echo ""
_show_log -d -g " [INFO]" -w " Install php${PHP_VERSION_MIN} sucessful!"
else
_show_log -d -r " [FAIL]" -w " Can not install php${PHP_VERSION_MIN}. Exit"
_exit_build 1
fi
else
yum -y ${PHP_ENABLE_REPO} install ${PHP_PREFIX}${PHP_VERSION_MIN}${PHP_SUFFIX}-fpm
if [[ "${PHP_VERSION_MIN}" == "54" ]] || [[ "${PHP_VERSION_MIN}" == "55" ]]
then
REMI_DIR="/etc/opt/remi"
if [ ! -d ${REMI_DIR} ]
then
mkdir ${REMI_DIR}
fi
ln -sf /opt/remi/php${PHP_VERSION_MIN}/root/etc ${REMI_DIR}/php${PHP_VERSION_MIN}
fi
echo ""
_check_installed_service "php${PHP_VERSION_MIN}" "new"
sed -i "s/^listen =.*/listen = \/var\/run\/php${PHP_VERSION_MIN}.sock/" ${REMI_DIR}/php${PHP_VERSION_MIN}/php-fpm.d/www.conf
rm -f /var/run/php${PHP_VERSION_MIN}.sock
if [ "${NO_START}" != "1" ]
then
_restart_services php${PHP_VERSION_MIN}-php-fpm
fi
_start_on_boot php${PHP_VERSION_MIN}-php-fpm
CHECK_INSTALLED=`command -v php${PHP_VERSION_MIN} | wc -l`
if [ ${CHECK_INSTALLED} -ne 0 ]
then
CHECK_VERSION="${i_INSTALL_PHP}"
else
CHECK_VERSION="_"
fi
CHECK_RUNNING=`systemctl status php${PHP_VERSION_MIN}-php-fpm | grep -c "running"`
SHOW_SERVICE=$( echo "${SHOW_SERVICE}"
echo "php${PHP_VERSION_MIN}-php-fpm ${CHECK_VERSION} $(_yes_no ${CHECK_INSTALLED}) $(_yes_no ${CHECK_RUNNING})")
fi
done
elif [ "${PKG_MANAGER}" == "DEB" ]
then
if [ "${OS_NAME}" == "Ubuntu" ]
then
add-apt-repository -y ppa:ondrej/php
apt-get update
for i_INSTALL_PHP in ${GET_PHP_VERSION[*]}
do
apt-get -y install php${i_INSTALL_PHP} \
php${i_INSTALL_PHP}-curl \
php${i_INSTALL_PHP}-exif \
php${i_INSTALL_PHP}-fileinfo \
php${i_INSTALL_PHP}-gd \
php${i_INSTALL_PHP}-imap \
php${i_INSTALL_PHP}-intl \
php${i_INSTALL_PHP}-json \
php${i_INSTALL_PHP}-mbstring \
php${i_INSTALL_PHP}-mysqlnd \
php${i_INSTALL_PHP}-soap \
php${i_INSTALL_PHP}-simplexml \
php${i_INSTALL_PHP}-xml \
php${i_INSTALL_PHP}-xmlrpc \
php${i_INSTALL_PHP}-xsl \
php${i_INSTALL_PHP}-zip
done
fi
fi
fi
}
# Install webserver
_install_web(){
if [ ! -z "${GET_WEB_SERVER}" ]
then
echo ""
_show_log -d -g " [INFO]" -w " Installing ${GET_WEB_SERVER}..."
sleep 1
_install_${GET_WEB_SERVER}
echo ""
_detect_port_used ${GET_WEB_SERVER} 80
if [ -z "${CANNOT_STOP_PORT_80}" ]
then
if [ "${GET_WEB_SERVER}" == "openlitespeed" ]
then
sed -i 's/:8088$/:80/' ${LSWS_DIR}/conf/httpd_config.conf
fi
if [ "${NO_START}" != "1" ]
then
_restart_services ${GET_WEB_SERVER}
fi
fi
_check_installed_service "${GET_WEB_SERVER}" "new"
CHECK_INSTALLED=`command -v ${GET_WEB_SERVER} | wc -l`
if [ ${CHECK_INSTALLED} -ne 0 ]
then
if [ "${GET_WEB_SERVER}" == "httpd" ]
then
CHECK_VERSION=`httpd -v | grep version | awk '{print $3}' | cut -d'/' -f2`
elif [ "${GET_WEB_SERVER}" == "nginx" ]
then
CHECK_VERSION=`nginx -v 2>&1 | awk '{print $3}' | cut -d"/" -f2`
elif [ "${GET_WEB_SERVER}" == "openlitespeed" ]
then
CHECK_VERSION=`/usr/local/lsws/bin/lshttpd -v | head -1 | awk '{print $1}' | cut -d'/' -f2`
fi
else
CHECK_VERSION="_"
fi
CHECK_RUNNING=`systemctl status ${GET_WEB_SERVER} | grep -c "running"`
SHOW_SERVICE=$( echo "${SHOW_SERVICE}"
echo "${GET_WEB_SERVER} ${CHECK_VERSION} $(_yes_no ${CHECK_INSTALLED}) $(_yes_no ${CHECK_RUNNING})")
fi
}
# Install httpd
_install_httpd(){
if [ "${PKG_MANAGER}" == "RPM" ]
then
yum -y install httpd
elif [ "${PKG_MANAGER}" == "DEB" ]
then
apt-get install apache2
fi
}
# Install nginx
_install_nginx(){
if [ "${PKG_MANAGER}" == "RPM" ]
then
cat > "/etc/yum.repos.d/nginx.repo" <<EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0
enabled=1
module_hotfixes=true
EOF
yum -y install nginx
elif [ "${PKG_MANAGER}" == "DEB" ]
then
cd ${BUILD_TMP}
wget https://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
cat >> "/etc/apt/sources.list" <<EOF
deb https://nginx.org/packages/${OS_NAME_LOWER}/ ${OS_CODENAME} nginx
deb-src https://nginx.org/packages/${OS_NAME_LOWER}/ ${OS_CODENAME} nginx
EOF
apt-get update
apt-get -y install nginx
fi
}
# Install OpenLiteSpeed
_install_openlitespeed(){
if [ "${PKG_MANAGER}" == "RPM" ]
then
rpm -ivh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el${OS_VERSION}.noarch.rpm
yum -y install openlitespeed lsphp73-intl lsphp73-json lsphp73-devel lsphp73-soap lsphp73-xmlrpc lsphp73-zip
elif [ "${PKG_MANAGER}" == "DEB" ]
then
cd ${BUILD_TMP}
wget -O - http://rpms.litespeedtech.com/debian/enable_lst_debain_repo.sh | bash
apt-get -y install openlitespeed lsphp73-intl
fi
ln -sf /usr/local/lsws/bin/openlitespeed /usr/local/bin/openlitespeed
}
# Install MariaDB
_install_mariadb(){
if [ ! -z "${GET_MARIADB}" ]
then
CHECK_SQL_SERVER=`_check_service -i "mysql"`
if [ ${CHECK_SQL_SERVER} -ne 0 ]
then
echo ""
_show_log -d -y " [WARN]" -w " MariaDB installed. Do not install new!"
else
echo ""
_show_log -d -g " [INFO]" -w " Installing MariaDB..."
sleep 1
if [ "${PKG_MANAGER}" == "RPM" ]
then
# Check yum.mariadb.org
HOST="yum.mariadb.org"
if ping -c 1 -w 1 ${HOST} > /dev/null
then
if [ "${OS_ARCH}" == "x86_64" ]
then
OS_ARCH1="amd64"
elif [ "${OS_ARCH}" == "i686" ]
then
OS_ARCH1="x86"
fi
cat > "/etc/yum.repos.d/MariaDB.repo" <<EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/${GET_MARIADB}/centos${OS_VERSION}-${OS_ARCH1}
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
if [ "${OS_VERSION}" == "8" ]
then
yum -y install boost-program-options
yum -y install MariaDB-server MariaDB-client --disablerepo=AppStream
else
yum -y install MariaDB-server MariaDB-client
fi
else
_show_log -d -r " [FAIL]" -w " Can not connect to yum.mariadb.org! Exit"
_exit_build 1
fi
elif [ "${PKG_MANAGER}" == "DEB" ]
then
MARIADB_VERSION_MIN=`echo ${GET_MARIADB} | sed 's/\.//'`
if [ ${MARIADB_VERSION_MIN} -lt 104 ]
then
SQLPASS=`date +%s | sha256sum | base64 | head -c 12`
echo "maria-db-${GET_MARIADB} mysql-server/root_password password ${SQLPASS}" | debconf-set-selections
echo "maria-db-${GET_MARIADB} mysql-server/root_password_again password ${SQLPASS}" | debconf-set-selections
fi
apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
add-apt-repository "deb [arch=amd64,arm64,i386,ppc64el] ${MARIADB_MIRROR}/mariadb/repo/${GET_MARIADB}/${OS_NAME_LOWER} ${OS_CODENAME} main"
apt-get -y update
apt-get -y install mariadb-server
fi
echo ""
_check_installed_service "mysql" "new"
CHECK_MARIADB=`mysql -V | grep MariaDB | wc -l`
if [ ${CHECK_MARIADB} = 1 ]
then
if [ "${GET_MARIADB}" == "10.4" ]
then
MYSQL="mariadb"
else
MYSQL="mysql"
fi
else
MYSQL="mysqld"
fi
if [ "${NO_START}" != "1" ]
then
_restart_services ${MYSQL}
fi
_start_on_boot ${MYSQL}
fi
CHECK_INSTALLED=`command -v mysql | wc -l`
if [ ${CHECK_INSTALLED} -ne 0 ]
then
CHECK_VERSION=`mysql -V | awk '{print $5}' | cut -d"-" -f 1 | sed 's/,//'`
SHOW_INFO=$( echo "${SHOW_INFO}"
echo "---"
echo -e "${RED}[IMPORTANT]${REMOVE} You should run command ${GREEN}mysql_secure_installation${REMOVE} to set Mariadb root's password and secure your sql server!" )