forked from jinwyp/one_click_script
-
Notifications
You must be signed in to change notification settings - Fork 2
/
linux_install_software.sh
7416 lines (5273 loc) · 239 KB
/
linux_install_software.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
export LC_ALL=C
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
sudoCmd=""
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
sudoCmd="sudo"
fi
# fonts color
red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
yellow(){
echo -e "\033[33m\033[01m$1\033[0m"
}
blue(){
echo -e "\033[34m\033[01m$1\033[0m"
}
bold(){
echo -e "\033[1m\033[01m$1\033[0m"
}
function showHeaderGreen(){
echo
green " =================================================="
for parameter in "$@"
do
if [[ -n "${parameter}" ]]; then
green " ${parameter}"
fi
done
green " =================================================="
echo
}
function showHeaderRed(){
echo
red " =================================================="
for parameter in "$@"
do
if [[ -n "${parameter}" ]]; then
red " ${parameter}"
fi
done
red " =================================================="
echo
}
function showInfoGreen(){
echo
for parameter in "$@"
do
if [[ -n "${parameter}" ]]; then
green " ${parameter}"
fi
done
echo
}
function promptContinueOpeartion(){
read -r -p "是否继续操作? 直接回车默认继续操作, 请输入[Y/n]:" isContinueInput
isContinueInput=${isContinueInput:-Y}
if [[ $isContinueInput == [Yy] ]]; then
echo ""
else
exit 1
fi
}
osCPU=""
osArchitecture="arm"
osInfo=""
osRelease=""
osReleaseVersion=""
osReleaseVersionNo=""
osReleaseVersionNoShort=""
osReleaseVersionCodeName="CodeName"
osSystemPackage=""
osSystemMdPath=""
osSystemShell="bash"
function checkArchitecture(){
# https://stackoverflow.com/questions/48678152/how-to-detect-386-amd64-arm-or-arm64-os-architecture-via-shell-bash
case $(uname -m) in
i386) osArchitecture="386" ;;
i686) osArchitecture="386" ;;
x86_64) osArchitecture="amd64" ;;
arm) dpkg --print-architecture | grep -q "arm64" && osArchitecture="arm64" || osArchitecture="arm" ;;
aarch64) dpkg --print-architecture | grep -q "arm64" && osArchitecture="arm64" || osArchitecture="arm" ;;
* ) osArchitecture="arm" ;;
esac
}
function checkCPU(){
osCPUText=$(cat /proc/cpuinfo | grep vendor_id | uniq)
if [[ $osCPUText =~ "GenuineIntel" ]]; then
osCPU="intel"
elif [[ $osCPUText =~ "AMD" ]]; then
osCPU="amd"
else
echo
fi
# green " Status 状态显示--当前CPU是: $osCPU"
}
# 检测系统版本号
getLinuxOSVersion(){
if [[ -s /etc/redhat-release ]]; then
osReleaseVersion=$(grep -oE '[0-9.]+' /etc/redhat-release)
else
osReleaseVersion=$(grep -oE '[0-9.]+' /etc/issue)
fi
# https://unix.stackexchange.com/questions/6345/how-can-i-get-distribution-name-and-version-number-in-a-simple-shell-script
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
source /etc/os-release
osInfo=$NAME
osReleaseVersionNo=$VERSION_ID
if [ -n "$VERSION_CODENAME" ]; then
osReleaseVersionCodeName=$VERSION_CODENAME
fi
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
osInfo=$(lsb_release -si)
osReleaseVersionNo=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
osInfo=$DISTRIB_ID
osReleaseVersionNo=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
osInfo=Debian
osReleaseVersion=$(cat /etc/debian_version)
osReleaseVersionNo=$(sed 's/\..*//' /etc/debian_version)
elif [ -f /etc/redhat-release ]; then
osReleaseVersion=$(grep -oE '[0-9.]+' /etc/redhat-release)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
osInfo=$(uname -s)
osReleaseVersionNo=$(uname -r)
fi
osReleaseVersionNoShort=$(echo $osReleaseVersionNo | sed 's/\..*//')
}
# 检测系统发行版代号
function getLinuxOSRelease(){
if [[ -f /etc/redhat-release ]]; then
osRelease="centos"
osSystemPackage="yum"
osSystemMdPath="/usr/lib/systemd/system/"
osReleaseVersionCodeName=""
elif cat /etc/issue | grep -Eqi "debian|raspbian"; then
osRelease="debian"
osSystemPackage="apt-get"
osSystemMdPath="/lib/systemd/system/"
osReleaseVersionCodeName="buster"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
osRelease="ubuntu"
osSystemPackage="apt-get"
osSystemMdPath="/lib/systemd/system/"
osReleaseVersionCodeName="bionic"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
osRelease="centos"
osSystemPackage="yum"
osSystemMdPath="/usr/lib/systemd/system/"
osReleaseVersionCodeName=""
elif cat /proc/version | grep -Eqi "debian|raspbian"; then
osRelease="debian"
osSystemPackage="apt-get"
osSystemMdPath="/lib/systemd/system/"
osReleaseVersionCodeName="buster"
elif cat /proc/version | grep -Eqi "ubuntu"; then
osRelease="ubuntu"
osSystemPackage="apt-get"
osSystemMdPath="/lib/systemd/system/"
osReleaseVersionCodeName="bionic"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
osRelease="centos"
osSystemPackage="yum"
osSystemMdPath="/usr/lib/systemd/system/"
osReleaseVersionCodeName=""
fi
getLinuxOSVersion
checkArchitecture
checkCPU
[[ -z $(echo $SHELL|grep zsh) ]] && osSystemShell="bash" || osSystemShell="zsh"
green " OS info: ${osInfo}, ${osRelease}, ${osReleaseVersion}, ${osReleaseVersionNo}, ${osReleaseVersionCodeName}, ${osCPU} CPU ${osArchitecture}, ${osSystemShell}, ${osSystemPackage}, ${osSystemMdPath}"
}
configLocalVPSIp="$(curl https://ipv4.icanhazip.com/)"
function getVPSIPInput (){
echo
read -r -p "请输入VPS的IP地址:" currentVPSIPaddressInput
if [[ -n "${currentVPSIPaddressInput}" ]]; then
configLocalVPSIp="${currentVPSIPaddressInput}"
else
red "输入的IP地址无效 请重新输入. Invalid IP address, pls input again."
getVPSIPInput
fi
}
function getVPSIP(){
configLocalVPSIp="$(curl https://ipv4.icanhazip.com/)"
echo
green "当前VPS的IP为: ${configLocalVPSIp}"
green "The current IP address of the VPS is: ${configLocalVPSIp}"
echo
green "如果本机IPv4 不是 ${configLocalVPSIp}, 请手动输入正确的IP "
green "If VPS IP is not ${configLocalVPSIp}, pls input the IP manually"
echo
read -r -p "是否手动输入IP 默认否, 请输入[y/N]:" isChangeVPSIPInput
if [[ $isChangeVPSIPInput == [yY] ]]; then
getVPSIPInput
fi
echo
}
osPort80=""
osPort443=""
osSELINUXCheck=""
osSELINUXCheckIsRebootInput=""
function testLinuxPortUsage(){
$osSystemPackage -y install net-tools socat
osPort80=$(netstat -tlpn | awk -F '[: ]+' '$1=="tcp"{print $5}' | grep -w 80)
osPort443=$(netstat -tlpn | awk -F '[: ]+' '$1=="tcp"{print $5}' | grep -w 443)
if [ -n "$osPort80" ]; then
process80=$(netstat -tlpn | awk -F '[: ]+' '$5=="80"{print $9}')
red "==========================================================="
red "检测到80端口被占用,占用进程为:${process80} "
red "==========================================================="
promptContinueOpeartion
fi
if [ -n "$osPort443" ]; then
process443=$(netstat -tlpn | awk -F '[: ]+' '$5=="443"{print $9}')
red "============================================================="
red "检测到443端口被占用,占用进程为:${process443} "
red "============================================================="
promptContinueOpeartion
fi
osSELINUXCheck=$(grep SELINUX= /etc/selinux/config | grep -v "#")
if [ "$osSELINUXCheck" == "SELINUX=enforcing" ]; then
red "======================================================================="
red "检测到SELinux为开启强制模式状态, 为防止申请证书失败 将关闭SELinux. 请先重启VPS后,再执行本脚本"
red "======================================================================="
read -p "是否现在重启? 请输入 [Y/n] :" osSELINUXCheckIsRebootInput
[ -z "${osSELINUXCheckIsRebootInput}" ] && osSELINUXCheckIsRebootInput="y"
if [[ $osSELINUXCheckIsRebootInput == [Yy] ]]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo -e "VPS 重启中..."
reboot
fi
exit
fi
if [ "$osSELINUXCheck" == "SELINUX=permissive" ]; then
red "======================================================================="
red "检测到SELinux为宽容模式状态, 为防止申请证书失败, 将关闭SELinux. 请先重启VPS后,再执行本脚本"
red "======================================================================="
read -p "是否现在重启? 请输入 [Y/n] :" osSELINUXCheckIsRebootInput
[ -z "${osSELINUXCheckIsRebootInput}" ] && osSELINUXCheckIsRebootInput="y"
if [[ $osSELINUXCheckIsRebootInput == [Yy] ]]; then
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo -e "VPS 重启中..."
reboot
fi
exit
fi
if [ "$osRelease" == "centos" ]; then
if [[ ${osReleaseVersionNoShort} == "6" || ${osReleaseVersionNoShort} == "5" ]]; then
green " =================================================="
red " 本脚本不支持 Centos 6 或 Centos 6 更早的版本"
green " =================================================="
exit
fi
red " 关闭防火墙 firewalld"
${sudoCmd} systemctl stop firewalld
${sudoCmd} systemctl disable firewalld
elif [ "$osRelease" == "ubuntu" ]; then
if [[ ${osReleaseVersionNoShort} == "14" || ${osReleaseVersionNoShort} == "12" ]]; then
green " =================================================="
red " 本脚本不支持 Ubuntu 14 或 Ubuntu 14 更早的版本"
green " =================================================="
exit
fi
red " 关闭防火墙 ufw"
${sudoCmd} systemctl stop ufw
${sudoCmd} systemctl disable ufw
if ! command -v ufw &> /dev/null; then
echo "ufw command could not be found"
else
ufw disable
fi
elif [ "$osRelease" == "debian" ]; then
$osSystemPackage update -y
fi
}
# 编辑 SSH 公钥 文件用于 免密码登录
function editLinuxLoginWithPublicKey(){
if [ ! -d "${HOME}/ssh" ]; then
mkdir -p ${HOME}/.ssh
fi
vi ${HOME}/.ssh/authorized_keys
}
# 修改SSH 端口号
function changeLinuxSSHPort(){
green " 修改的SSH登陆的端口号, 不要使用常用的端口号. 例如 20|21|23|25|53|69|80|110|443|123!"
read -p "请输入要修改的端口号(必须是纯数字并且在1024~65535之间或22):" osSSHLoginPortInput
osSSHLoginPortInput=${osSSHLoginPortInput:-0}
if [ $osSSHLoginPortInput -eq 22 -o $osSSHLoginPortInput -gt 1024 -a $osSSHLoginPortInput -lt 65535 ]; then
sed -i "s/#\?Port [0-9]*/Port $osSSHLoginPortInput/g" /etc/ssh/sshd_config
if [ "$osRelease" == "centos" ] ; then
if [[ ${osReleaseVersionNoShort} == "7" ]]; then
yum -y install policycoreutils-python
elif [[ ${osReleaseVersionNoShort} == "8" ]]; then
yum -y install policycoreutils-python-utils
fi
# semanage port -l
if command -v semanage &> /dev/null; then
semanage port -a -t ssh_port_t -p tcp ${osSSHLoginPortInput}
fi
if command -v firewall-cmd &> /dev/null; then
firewall-cmd --permanent --zone=public --add-port=$osSSHLoginPortInput/tcp
firewall-cmd --reload
fi
${sudoCmd} systemctl restart sshd.service
fi
if [ "$osRelease" == "ubuntu" ] || [ "$osRelease" == "debian" ] ; then
if ! command -v semanage &> /dev/null; then
echo "semanage command could not be found"
else
semanage port -a -t ssh_port_t -p tcp $osSSHLoginPortInput
fi
if ! command -v ufw &> /dev/null; then
echo "ufw command could not be found"
else
${sudoCmd} ufw allow $osSSHLoginPortInput/tcp
fi
${sudoCmd} service ssh restart
${sudoCmd} systemctl restart ssh
fi
green "设置成功, 请记住设置的端口号 ${osSSHLoginPortInput}!"
green "登陆服务器命令: ssh -p ${osSSHLoginPortInput} [email protected] ip !"
else
red "输入的端口号错误! 范围: 22,1025~65534"
fi
}
# 设置北京时区
function setLinuxDateZone(){
tempCurrentDateZone=$(date +'%z')
echo
if [[ ${tempCurrentDateZone} == "+0800" ]]; then
yellow "当前时区已经为北京时间 $tempCurrentDateZone | $(date -R) "
else
green " =================================================="
yellow " 当前时区为: $tempCurrentDateZone | $(date -R) "
yellow " 是否设置时区为北京时间 +0800区, 以便cron定时重启脚本按照北京时间运行."
green " =================================================="
# read 默认值 https://stackoverflow.com/questions/2642585/read-a-variable-in-bash-with-a-default-value
read -p "是否设置为北京时间 +0800 时区? 请输入[Y/n]:" osTimezoneInput
osTimezoneInput=${osTimezoneInput:-Y}
if [[ $osTimezoneInput == [Yy] ]]; then
if [[ -f /etc/localtime ]] && [[ -f /usr/share/zoneinfo/Asia/Shanghai ]]; then
mv /etc/localtime /etc/localtime.bak
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yellow " 设置成功! 当前时区已设置为 $(date -R)"
green " =================================================="
fi
fi
fi
echo
if [ "$osRelease" == "centos" ]; then
if [[ ${osReleaseVersionNoShort} == "7" ]]; then
systemctl stop chronyd
systemctl disable chronyd
$osSystemPackage -y install ntpdate
$osSystemPackage -y install ntp
ntpdate -q 0.rhel.pool.ntp.org
systemctl enable ntpd
systemctl restart ntpd
ntpdate -u pool.ntp.org
elif [[ ${osReleaseVersionNoShort} == "8" || ${osReleaseVersionNoShort} == "9" ]]; then
$osSystemPackage -y install chrony
systemctl enable chronyd
systemctl restart chronyd
if command -v firewall-cmd &> /dev/null; then
firewall-cmd --permanent --add-service=ntp
firewall-cmd --reload
fi
chronyc sources
echo
fi
else
if [[ "${osReleaseVersionNoShort}" == "12" ]]; then
systemctl restart systemd-timesyncd
timedatectl timesync-status
else
$osSystemPackage install -y ntp
systemctl enable ntp
systemctl restart ntp
fi
fi
}
function DSMEditHosts(){
green " ================================================== "
green " 准备打开VI 编辑/etc/hosts"
green " 请用root 用户登录系统的SSH 运行本命令"
green " ================================================== "
# nameserver 223.5.5.5
# nameserver 8.8.8.8
HostFilePath="/etc/hosts"
if ! grep -q "github" "${HostFilePath}"; then
echo "199.232.69.194 github.global.ssl.fastly.net" >> ${HostFilePath}
echo "185.199.108.153 assets-cdn.github.com" >> ${HostFilePath}
echo "185.199.108.133 raw.githubusercontent.com" >> ${HostFilePath}
echo "140.82.114.3 github.com" >> ${HostFilePath}
echo "104.16.16.35 registry.npmjs.org" >> ${HostFilePath}
fi
vi ${HostFilePath}
}
# 软件安装
function installSoftDownload(){
if [[ "${osRelease}" == "debian" || "${osRelease}" == "ubuntu" ]]; then
if ! dpkg -l | grep -qw wget; then
${osSystemPackage} -y install wget git unzip curl apt-transport-https
# https://stackoverflow.com/questions/11116704/check-if-vt-x-is-activated-without-having-to-reboot-in-linux
${osSystemPackage} -y install cpu-checker
fi
if ! dpkg -l | grep -qw curl; then
${osSystemPackage} -y install curl git unzip wget apt-transport-https
${osSystemPackage} -y install cpu-checker
fi
elif [[ "${osRelease}" == "centos" ]]; then
if [[ ${osReleaseVersion} == "8.1.1911" || ${osReleaseVersion} == "8.2.2004" || ${osReleaseVersion} == "8.0.1905" ]]; then
# https://techglimpse.com/failed-metadata-repo-appstream-centos-8/
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
yum update -y
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
${sudoCmd} dnf install centos-release-stream -y
${sudoCmd} dnf swap centos-{linux,stream}-repos -y
${sudoCmd} dnf distro-sync -y
fi
if ! rpm -qa | grep -qw wget; then
${osSystemPackage} -y install wget curl git unzip
elif ! rpm -qa | grep -qw git; then
${osSystemPackage} -y install wget curl git unzip
fi
fi
}
function installPackage(){
echo
green " =================================================="
yellow " 开始安装软件"
green " =================================================="
echo
# sed -i '1s/^/nameserver 1.1.1.1 \n/' /etc/resolv.conf
if [ "$osRelease" == "centos" ]; then
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rm -f /etc/yum.repos.d/nginx.repo
# cat > "/etc/yum.repos.d/nginx.repo" <<-EOF
# [nginx]
# name=nginx repo
# baseurl=https://nginx.org/packages/centos/$osReleaseVersionNoShort/\$basearch/
# gpgcheck=0
# enabled=1
# sslverify=0
#
# EOF
if ! rpm -qa | grep -qw iperf3; then
${sudoCmd} ${osSystemPackage} install -y epel-release
${osSystemPackage} install -y curl wget git unzip zip tar bind-utils htop net-tools
${osSystemPackage} install -y xz jq redhat-lsb-core
${osSystemPackage} install -y iputils
${osSystemPackage} install -y iperf3
fi
${osSystemPackage} update -y
# https://www.cyberciti.biz/faq/how-to-install-and-use-nginx-on-centos-8/
if [[ ${osReleaseVersionNoShort} == "8" || ${osReleaseVersionNoShort} == "9" ]]; then
${sudoCmd} yum module -y reset nginx
${sudoCmd} yum module -y enable nginx:1.20
${sudoCmd} yum module list nginx
fi
elif [ "$osRelease" == "ubuntu" ]; then
# https://joshtronic.com/2018/12/17/how-to-install-the-latest-nginx-on-debian-and-ubuntu/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/install/
$osSystemPackage install -y gnupg2 curl ca-certificates lsb-release ubuntu-keyring
# wget -O - https://nginx.org/keys/nginx_signing.key | ${sudoCmd} apt-key add -
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
rm -f /etc/apt/sources.list.d/nginx.list
cat > "/etc/apt/sources.list.d/nginx.list" <<-EOF
deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://nginx.org/packages/ubuntu/ $osReleaseVersionCodeName nginx
# deb [arch=amd64] https://nginx.org/packages/ubuntu/ $osReleaseVersionCodeName nginx
# deb-src https://nginx.org/packages/ubuntu/ $osReleaseVersionCodeName nginx
EOF
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99-nginx
if [[ "${osReleaseVersionNoShort}" == "22" || "${osReleaseVersionNoShort}" == "21" ]]; then
echo
fi
${osSystemPackage} update -y
if ! dpkg -l | grep -qw iperf3; then
${sudoCmd} ${osSystemPackage} install -y software-properties-common
${osSystemPackage} install -y curl wget git unzip zip tar htop
${osSystemPackage} install -y xz-utils jq lsb-core lsb-release
${osSystemPackage} install -y iputils-ping
${osSystemPackage} install -y iperf3
fi
elif [ "$osRelease" == "debian" ]; then
# ${sudoCmd} add-apt-repository ppa:nginx/stable -y
${osSystemPackage} update -y
apt install -y gnupg2
apt install -y curl ca-certificates lsb-release
wget https://nginx.org/keys/nginx_signing.key -O- | apt-key add -
rm -f /etc/apt/sources.list.d/nginx.list
if [[ "${osReleaseVersionNoShort}" == "12" ]]; then
echo
else
cat > "/etc/apt/sources.list.d/nginx.list" <<-EOF
deb https://nginx.org/packages/mainline/debian/ $osReleaseVersionCodeName nginx
deb-src https://nginx.org/packages/mainline/debian $osReleaseVersionCodeName nginx
EOF
fi
${osSystemPackage} update -y
if ! dpkg -l | grep -qw iperf3; then
${osSystemPackage} install -y curl wget git unzip zip tar htop
${osSystemPackage} install -y xz-utils jq lsb-core lsb-release
${osSystemPackage} install -y iputils-ping
${osSystemPackage} install -y iperf3
fi
fi
}
function installSoftEditor(){
# 安装 micro 编辑器
if [[ ! -f "${HOME}/bin/micro" ]] ; then
mkdir -p ${HOME}/bin
cd ${HOME}/bin
curl https://getmic.ro | bash
cp ${HOME}/bin/micro /usr/local/bin
green " =================================================="
green " micro 编辑器 安装成功!"
green " =================================================="
fi
if [ "$osRelease" == "centos" ]; then
$osSystemPackage install -y xz vim-minimal vim-enhanced vim-common nano
else
$osSystemPackage install -y vim-gui-common vim-runtime vim nano
fi
# 设置vim 中文乱码
if [[ ! -d "${HOME}/.vimrc" ]] ; then
cat > "${HOME}/.vimrc" <<-EOF
set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
set enc=utf8
set fencs=utf8,gbk,gb2312,gb18030
syntax on
colorscheme elflord
if has('mouse')
se mouse+=a
set number
endif
EOF
fi
}
# 更新本脚本
function upgradeScript(){
wget -Nq --no-check-certificate -O ./linux_install_software.sh "https://raw.githubusercontent.com/jinwyp/one_click_script/master/linux_install_software.sh"
green " Script upgrade successful. 本脚本升级成功! "
chmod +x ./linux_install_software.sh
sleep 2s
exec "./linux_install_software.sh"
}
function installWireguard(){
bash <(wget -qO- https://github.com/jinwyp/one_click_script/raw/master/install_kernel.sh)
# wget -N --no-check-certificate https://github.com/jinwyp/one_click_script/raw/master/install_kernel.sh && chmod +x ./install_kernel.sh && ./install_kernel.sh
}
function toolboxSkybox(){
wget -O skybox.sh https://raw.githubusercontent.com/BlueSkyXN/SKY-BOX/main/box.sh && chmod +x skybox.sh && ./skybox.sh
}
function toolboxJcnf(){
wget -O jcnfbox.sh https://raw.githubusercontent.com/Netflixxp/jcnf-box/main/jcnfbox.sh && chmod +x jcnfbox.sh && ./jcnfbox.sh
}
function installCasaOS(){
wget -O- https://get.casaos.io | bash
}
function removeCasaOS(){
casaos-uninstall
}
configDownloadTempPath="${HOME}/temp"
function downloadAndUnzip(){
if [ -z $1 ]; then
green " ================================================== "
green " 下载文件地址为空!"
green " ================================================== "
exit
fi
if [ -z $2 ]; then
green " ================================================== "
green " 目标路径地址为空!"
green " ================================================== "
exit
fi
if [ -z $3 ]; then
green " ================================================== "
green " 下载文件的文件名为空!"
green " ================================================== "
exit
fi
mkdir -p ${configDownloadTempPath}
if [[ $3 == *"tar.xz"* ]]; then
green "===== 下载并解压tar.xz文件: $3 "
wget -O ${configDownloadTempPath}/$3 $1
tar xf ${configDownloadTempPath}/$3 -C ${configDownloadTempPath}
mv ${configDownloadTempPath}/* $2
rm -rf ${configDownloadTempPath}
elif [[ $3 == *"tar.gz"* ]]; then
green "===== 下载并解压tar.gz文件: $3 "
wget -O ${configDownloadTempPath}/$3 $1
tar zxvf ${configDownloadTempPath}/$3 -C ${configDownloadTempPath}
mv ${configDownloadTempPath}/* $2
rm -rf ${configDownloadTempPath}
else
green "===== 下载并解压zip文件: $3 "
wget -O ${configDownloadTempPath}/$3 $1
unzip -d $2 ${configDownloadTempPath}/$3
rm -rf ${configDownloadTempPath}
fi
}
function getGithubLatestReleaseVersion(){
# https://github.com/p4gefau1t/trojan-go/issues/63
wget --no-check-certificate -qO- https://api.github.com/repos/$1/tags | grep 'name' | cut -d\" -f4 | head -1 | cut -b 2-
}
function getGithubLatestReleaseVersion2(){
# https://github.com/p4gefau1t/trojan-go/issues/63
wget --no-check-certificate -qO- https://api.github.com/repos/$1/tags | grep 'name' | cut -d\" -f4 | sort -r | head -1 | cut -b 1-
}
function installNodejs(){
showHeaderGreen "Prepare to install Nodejs"
if [ "$osRelease" == "centos" ] ; then
if [ "$osReleaseVersion" == "7" ]; then
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
${sudoCmd} yum install -y nodejs
else
${sudoCmd} dnf module list nodejs
${sudoCmd} dnf module switch-to nodejs:16 -y
${sudoCmd} dnf module enable nodejs:16 -y
${sudoCmd} dnf module list nodejs
${sudoCmd} dnf install -y nodejs
fi
else
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
echo 'export NVM_DIR="$HOME/.nvm"' >> ${HOME}/.zshrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ${HOME}/.zshrc
source ${HOME}/.zshrc
command -v nvm
nvm --version
nvm ls-remote
nvm install --lts
fi
echo
green " Nodejs 版本:"
node --version
echo
green " NPM 版本:"
npm --version
showHeaderGreen "准备安装 PM2 进程守护程序"
npm install -g pm2
showHeaderGreen "Nodejs 与 PM2 安装成功 !"
}
configDockerDownloadPath="${HOME}/download"
configDockerComposePath="/usr/local/lib/docker/cli-plugins"
function installDocker(){
showHeaderGreen "准备安装 Docker 与 Docker Compose"
mkdir -p ${configDockerDownloadPath}
cd ${configDockerDownloadPath}
if [[ -s "/usr/bin/docker" ]]; then
showHeaderRed "已安装过 Docker. Docker already installed!"
else
if [[ "${osInfo}" == "AlmaLinux" ]]; then
echo " dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
${sudoCmd} yum module remove container-tools
${sudoCmd} dnf upgrade
# https://linuxconfig.org/install-docker-on-almalinux
${sudoCmd} dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
${sudoCmd} dnf remove -y podman buildah
${sudoCmd} dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
elif [[ "$osRelease" == "debian" ]]; then
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc;
do
${sudoCmd} apt-get remove $pkg;
done
${sudoCmd} apt-get update
${sudoCmd} apt-get install -y ca-certificates curl gnupg
${sudoCmd} install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
${sudoCmd} chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
${osReleaseVersionCodeName} stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
${sudoCmd} apt-get update
${sudoCmd} apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
else
curl -fsSL https://get.docker.com -o ${configDockerDownloadPath}/get-docker.sh
# curl -sSL https://get.daocloud.io/docker -o ${configDockerDownloadPath}/get-docker.sh
chmod +x ${configDockerDownloadPath}/get-docker.sh