forked from loyess/Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx_install.sh
107 lines (89 loc) · 3.68 KB
/
nginx_install.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
check_sys_and_add_source(){
local PKG_FLAG=$1
local version="$(get_version)"
if check_sys sysRelease centos; then
# 安装依赖
sudo yum install -y yum-utils
# 添加 Nginx 源
touch /etc/yum.repos.d/nginx.repo
cat > /etc/yum.repos.d/nginx.repo<<-EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
if [[ ${PKG_FLAG} = "1" ]]; then
# 安装nginx 稳定版
sudo yum-config-manager --disable nginx-mainline
sudo yum install -y nginx
elif [[ ${PKG_FLAG} = "2" ]]; then
# 安装nginx 主线版
sudo yum-config-manager --enable nginx-mainline
sudo yum install -y nginx
fi
if [ $? -eq 0 ]; then
echo -e "${Info} nginx安装成功."
fi
elif check_sys sysRelease debian; then
# 安装依赖
sudo apt install -y curl gnupg2 ca-certificates lsb-release
if [[ ${PKG_FLAG} = "1" ]]; then
# 添加 Nginx稳定版 源
echo "deb http://nginx.org/packages/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
elif [[ ${PKG_FLAG} = "2" ]]; then
# 添加 Nginx主线版 源
echo "deb http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
fi
# 导入官方的nginx签名密钥
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
# 验证key是否正确
# 打印如下:
# pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
# 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
# uid [ unknown] nginx signing key <[email protected]>
sudo apt-key fingerprint ABF5BD827BD9BF62
# 安装nginx
sudo apt update
sudo apt install -y nginx
if [ $? -eq 0 ]; then
echo -e "${Info} nginx安装成功."
fi
elif check_sys sysRelease ubuntu && version_ge ${version} 16.04; then
# 安装依赖
sudo apt install -y curl gnupg2 ca-certificates lsb-release
if [[ ${PKG_FLAG} = "1" ]]; then
# 添加 Nginx稳定版 源
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
elif [[ ${PKG_FLAG} = "2" ]]; then
# 添加 Nginx主线版 源
echo "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
fi
# 导入官方的nginx签名密钥
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
# 验证key是否正确
# 打印如下:
# pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
# 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
# uid [ unknown] nginx signing key <[email protected]>
sudo apt-key fingerprint ABF5BD827BD9BF62
# 安装nginx
sudo apt update
sudo apt install -y nginx
if [ $? -eq 0 ]; then
echo -e "${Info} nginx安装成功."
fi
fi
}
install_nginx(){
check_sys_and_add_source ${pkg_flag}
}