-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathh5ai.sh
340 lines (321 loc) · 9.79 KB
/
h5ai.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
#!/bin/bash
# ====================================================
# System Request:Debian 8+/Ubuntu 16.04+
# Author: wulabing
# Dscription: LNP-H5AI-onekey (only)
# Version: 2.0
# Blog: https://www.wulabing.com
# ====================================================
#fonts color
Green="\033[32m"
Red="\033[31m"
GreenBG="\033[42;37m"
RedBG="\033[41;37m"
Font="\033[0m"
#notification information
Info="${Green}[Info]${Font}"
OK="${Green}[OK]${Font}"
Error="${Red}[Error]${Font}"
#folder
nginx_conf_dir="/etc/nginx/conf.d"
h5ai_zip="h5ai-0.29.0.zip"
h5ai_download_http="https://raw.githubusercontent.com/yanshibin/h5ai_onekey_install-lnp-/master/${h5ai_zip}"
source /etc/os-release &>/dev/null
# 系统检测、仅支持 Debian8+ 和 Ubuntu16.04+
check_system(){
if [[ "${ID}" == "debian" && ${VERSION_ID} -ge 8 ]];then
echo -e "${OK} ${GreenBG} 当前系统为 Debian ${VERSION_ID} ${Font} "
elif [[ "${ID}" == "ubuntu" && `echo "${VERSION_ID}" | cut -d '.' -f1` -ge 16 ]];then
echo -e "${OK} ${GreenBG} 当前系统为 Ubuntu ${VERSION_ID} ${Font} "
else
echo -e "${Error} ${RedBG} 当前系统为不在支持的系统列表内,安装中断 ${Font} "
exit 1
fi
}
# 判定是否为root用户
is_root(){
if [ `id -u` == 0 ]
then echo -e "${OK} ${GreenBG} 当前用户是root用户,进入安装流程 ${Font} "
sleep 1
else
echo -e "${Error} ${RedBG} 当前用户不是root用户,请切换到root用户后重新执行脚本 ${Font}"
exit 1
fi
}
debian_source(){
# 添加源
echo "deb http://packages.dotdeb.org jessie all" | tee --append /etc/apt/sources.list
echo "deb-src http://packages.dotdeb.org jessie all" | tee --append /etc/apt/sources.list
# 添加key
wget --no-check-certificate https://www.dotdeb.org/dotdeb.gpg
if [[ -f dotdeb.gpg ]];then
apt-key add dotdeb.gpg
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} 导入 GPG 秘钥成功 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} 导入 GPG 秘钥失败 ${Font}"
exit 1
fi
else
echo -e "${Error} ${RedBG} 下载 GPG 秘钥失败 ${Font}"
exit 1
fi
# 源更新
apt-get update
}
basic_dependency(){
apt update
apt install wget unzip net-tools bc curl -y
}
nginx_install(){
# debian_source
apt install nginx -y
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} nginx 安装成功 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} nginx 安装失败 ${Font}"
exit 1
fi
}
php7_install(){
apt install php7.0-cgi php7.0-fpm php7.0-curl php7.0-gd -y
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} php7 安装成功 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} php7 安装失败 ${Font}"
exit 1
fi
}
nginx_conf_add(){
cat > ${nginx_conf_dir}/h5ai.conf <<EOF
server {
listen 80;
server_name ${domain};
root /home/wwwroot/${domain};
index index.html /_h5ai/public/index.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
EOF
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} nginx 配置导入成功 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} nginx 配置导入失败 ${Font}"
exit 1
fi
}
nginx_conf_ssl_add(){
cat > ${nginx_conf_dir}/h5ai.conf <<EOF
server
{
listen 443 ssl http2;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
server_name ${domain};
root /home/wwwroot/${domain};
index index.html /_h5ai/public/index.php;
ssl on;
ssl_certificate /home/wwwroot/ssl/h5ai.crt;
ssl_certificate_key /home/wwwroot/ssl/h5ai.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log off;
}
server
{
listen 80;
server_name ${domain};
rewrite ^(.*) https://${domain}\$1 permanent;
}
EOF
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} nginx SSL 配置导入成功 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} nginx SSL 配置导入失败 ${Font}"
exit 1
fi
}
ssl_install(){
apt install socat netcat -y
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} SSL 证书生成脚本依赖安装成功 ${Font}"
sleep 2
else
echo -e "${Error} ${RedBG} SSL 证书生成脚本依赖安装失败 ${Font}"
exit 6
fi
curl https://get.acme.sh | sh
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} SSL 证书生成脚本安装成功 ${Font}"
sleep 2
else
echo -e "${Error} ${RedBG} SSL 证书生成脚本安装失败,请检查相关依赖是否正常安装 ${Font}"
exit 7
fi
}
acme(){
mkdir -p /home/wwwroot/ssl
~/.acme.sh/acme.sh --issue -d ${domain} --standalone -k ec-256 --force
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} SSL 证书生成成功 ${Font}"
sleep 2
~/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /home/wwwroot/ssl/h5ai.crt --keypath /home/wwwroot/ssl/h5ai.key --ecc
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} 证书配置成功 ${Font}"
sleep 2
else
echo -e "${Error} ${RedBG} 证书配置失败 ${Font}"
fi
else
echo -e "${Error} ${RedBG} SSL 证书生成失败 ${Font}"
exit 1
fi
}
port_exist_check(){
if [[ 0 -eq `netstat -tlpn | grep "$1"| wc -l` ]];then
echo -e "${OK} ${GreenBG} $1 端口未被占用 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} $1 端口被占用,请检查占用进程 结束后重新运行脚本 ${Font}"
netstat -tlpn | grep "$1"
exit 1
fi
}
h5ai_install(){
mkdir -p /home/wwwroot/${domain} && cd /home/wwwroot/${domain}&& wget ${h5ai_download_http} && unzip ${h5ai_zip}
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} h5ai 下载成功 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} h5ai 下载失败 ${Font}"
exit 1
fi
}
h5ai_dependency(){
apt install libav-tools -y
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} 成功添加 Movie thumbs 支持 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} 未添加 Movie thumbs 支持 ${Font}"
fi
apt install aptitude -y
aptitude install imagemagick -y
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} 成功添加 PDF thumbs 支持 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} 未添加 PDF thumbs 支持 ${Font}"
fi
apt install zip -y
if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} 成功添加 zip 支持 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} 未添加 zip 支持 ${Font}"
fi
chmod 666 /home/wwwroot/${domain}/_h5ai/private/cache
echo -e "${OK} ${GreenBG} 成功添加 Public Cache directory 支持 ${Font}"
sleep 1
chmod 666 /home/wwwroot/${domain}/_h5ai/public/cache
echo -e "${OK} ${GreenBG} 成功添加 Private Cache directory 支持 ${Font}"
sleep 1
}
domain_check(){
stty erase '^H' && read -p "请输入你的域名信息(eg:www.wulabing.com):" domain
## ifconfig
## stty erase '^H' && read -p "请输入公网 IP 所在网卡名称(default:eth0):" broadcast
## [[ -z ${broadcast} ]] && broadcast="eth0"
domain_ip=`ping ${domain} -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'`
local_ip=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6 | awk '{print $2}' | tr -d "addr:"`
echo -e "域名dns解析IP:${domain_ip}"
echo -e "本机IP: ${local_ip}"
sleep 2
if [[ $(echo ${local_ip}|tr '.' '+'|bc) -eq $(echo ${domain_ip}|tr '.' '+'|bc) ]];then
echo -e "${OK} ${GreenBG} 域名dns解析IP 与 本机IP 匹配 ${Font}"
sleep 2
else
echo -e "${Error} ${RedBG} 域名dns解析IP 与 本机IP 不匹配 是否继续安装?(y/n)${Font}" && read install
case $install in
[yY][eE][sS]|[yY])
echo -e "${GreenBG} 继续安装 ${Font}"
sleep 2
;;
*)
echo -e "${RedBG} 安装终止 ${Font}"
exit 2
;;
esac
fi
}
standard(){
basic_dependency
domain_check
nginx_install
php7_install
h5ai_install
h5ai_dependency
nginx_conf_add
}
ssl(){
systemctl stop nginx
systemctl stop php7.0-fpm
port_exist_check 80
port_exist_check 443
ssl_install
acme
nginx_conf_ssl_add
systemctl start nginx
systemctl start php7.0-fpm
}
main(){
check_system
is_root
sleep 2
echo -e "${Red} 请选择安装内容 ${Font}"
echo -e "1. h5ai"
echo -e "2. SSL"
echo -e "3. h5ai+SSL"
read -p "input:" number
case ${number} in
1)
standard
echo -e "${OK} ${GreenBG} h5ai 安装成功 ${Font}"
;;
2)
domain_check
ssl
;;
3)
standard
ssl
echo -e "${OK} ${GreenBG} h5ai + SSL 安装成功 ${Font}"
;;
*)
echo -e "${Error} ${RedBG} 请输入正确的序号 ${Font}"
exit 1
;;
esac
}
main