forked from user1121114685/baidupcsweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BDW.sh
334 lines (309 loc) · 11.1 KB
/
BDW.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
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
sh_ver="1.0.2"
file="/root/BaiduPCSWeb"
Folder="/usr/local/BaiduPCSWeb"
BaiduPCS_Go="/usr/bin/BaiduPCS-Go"
red='\e[91m'
green='\e[92m'
yellow='\e[93m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'
BaiduPCS_port=$(cat ${Folder}/port)
#MMP这里的cat居然是这样的
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[信息]${Font_color_suffix}"
Error="${Red_font_prefix}[错误]${Font_color_suffix}"
Tip="${Green_font_prefix}[注意]${Font_color_suffix}"
check_root(){
[[ $EUID != 0 ]] && echo -e "${Error} 当前非ROOT账号(或没有ROOT权限),无法继续操作,请更换ROOT账号或使用 ${Green_background_prefix}sudo su${Font_color_suffix} 命令获取临时ROOT权限(执行后可能会提示输入当前账号的密码)。" && exit 1
}
#检查系统
check_sys(){
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
bit=`uname -m`
}
check_installed_status(){
[[ ! -e ${Folder} ]] && echo -e "${Error} BaiduPCS-Web 没有安装,请检查 !" && exit 1
}
check_pid(){
PID=`ps -ef| grep "BaiduPCS-Go"| grep -v grep| grep -v "BDW.sh"| grep -v "init.d"| grep -v "service"| awk '{print $2}'`
}
Set_BaiduPCS_port(){
echo
while :; do
echo -e "请输入 "$yellow"BaiduPCS"$BaiduPCS" 端口 ["$magenta"1-65535"$none"]"
echo -e "官方默认端口["$magenta"5299"$none"]"
read -e -p "$(echo -e "(当前端口: ${cyan}${BaiduPCS_port}$none):")" BaiduPCS_port_opt
case "$BaiduPCS_port_opt" in
$BaiduPCS_port)
echo
echo " 哎呀...跟当前端口一毛一样呀...修改个鸡鸡哦"
break
;;
[1-9] | [1-9][0-9] | [1-9][0-9][0-9] | [1-9][0-9][0-9][0-9] | [1-5][0-9][0-9][0-9][0-9] | 6[0-4][0-9][0-9][0-9] | 65[0-4][0-9][0-9] | 655[0-3][0-5])
echo "$BaiduPCS_port_opt" > ${Folder}/port
ReStart_BaiduPCS_Web
##卧槽TM,一个break让我找半天,没有这个,根本跳转不出来!;;是摆设吗?MMP!
break
;;
*)
echo "输入错误请重新输入"
;;
esac
done
}
check_new_ver(){
echo -e "${Info} 请输入 BaiduPCS-Web 版本号,格式如:[ 3.5.9 ],获取地址:[ https://github.com/liuzhuoling2011/baidupcs-web/releases ]"
read -e -p "默认回车自动获取最新版本号:" BaiduPCS_Web_new_ver
if [[ -z ${BaiduPCS_Web_new_ver} ]]; then
BaiduPCS_Web_new_ver="$(curl -H 'Cache-Control: no-cache' -s "https://api.github.com/repos/liuzhuoling2011/BaiduPCS-Web/releases/latest" | grep 'tag_name' | cut -d\" -f4)"
if [[ -z ${BaiduPCS_Web_new_ver} ]]; then
echo -e "${Error} BaiduPCS-Web 最新版本获取失败,请手动获取最新版本号[ https://github.com/liuzhuoling2011/baidupcs-web/releases ]"
read -e -p "请输入版本号 [ 格式如 3.5.9 ] :" BaiduPCS_Web_new_ver
[[ -z "${BaiduPCS_Web_new_ver}" ]] && echo "取消..." && exit 1
else
echo -e "${Info} 检测到 BaiduPCS-Web 最新版本为 [ ${BaiduPCS_Web_new_ver} ]"
fi
else
echo -e "${Info} 即将准备下载 BaiduPCS-Web 版本为 [ ${BaiduPCS_Web_new_ver} ]"
fi
}
check_ver_comparison(){
BaiduPCS_Web_now_ver=$(${Folder}/BaiduPCS-Go -v|head -n 1|awk '{print $3}')
[[ -z ${BaiduPCS_Web_now_ver} ]] && echo -e "${Error} BaiduPCS_Web 当前版本获取失败 !" && exit 1
if [[ "${BaiduPCS_Web_now_ver}" != "${BaiduPCS_Web_new_ver}" ]]; then
echo -e "${Info} 发现 BaiduPCS-Web 已有新版本 [ ${BaiduPCS_Web_new_ver} ](当前版本:${BaiduPCS_Web_now_ver})"
read -e -p "是否更新(会中断当前下载任务,请注意) ? [Y/n] :" yn
[[ -z "${yn}" ]] && yn="y"
if [[ $yn == [Yy] ]]; then
check_pid
[[ ! -z $PID ]] && kill -9 ${PID}
Download_BaiduPCS_Web "update"
Start_BaiduPCS_Web
fi
else
echo -e "${Info} 当前 BaiduPCS-Web 已是最新版本 [ ${BaiduPCS_Web_new_ver} ]" && exit 1
fi
}
Download_BaiduPCS_Web(){
update_dl=$1
cd "/usr/local"
#echo -e "${bit}"
if [[ ${bit} == "x86_64" ]]; then
bit="amd64"
elif [[ ${bit} == "i386" || ${bit} == "i686" ]]; then
bit="86"
else
bit="arm64"
fi
wget -N --no-check-certificate "http://qiniu.zoranjojo.top/BaiduPCS-Go-${BaiduPCS_Web_new_ver}-linux-${bit}.zip"
BaiduPCS_Web_Name="BaiduPCS-Go-${BaiduPCS_Web_new_ver}-linux-${bit}"
[[ ! -s ${BaiduPCS_Web_Name}.zip ]] && echo -e "${Error} BaiduPCS-Web 压缩包下载失败 !" && exit 1
unzip ${BaiduPCS_Web_Name}.zip
[[ ! -e "/usr/local/${BaiduPCS_Web_Name}" ]] && echo -e "${Error} BaiduPCS-Web 解压失败 !" && rm -rf ${BaiduPCS_Web_Name}.zip && exit 1
[[ ${update_dl} = "update" ]] && rm -rf "${Folder}"
mv "/usr/local/${BaiduPCS_Web_Name}" "${Folder}"
[[ ! -e "${Folder}" ]] && echo -e "${Error} BaiduPCS-Web 文件夹重命名失败 !" && rm -rf ${BaiduPCS_Web_Name}.zip && rm -rf "/usr/local/${BaiduPCS_Web_Name}" && exit 1
rm -rf ${BaiduPCS_Web_Name}.zip
cd "${Folder}"
chmod a+x BaiduPCS-Go
echo -e "${Info} BaiduPCS-Web 主程序安装完毕!..."
}
## 以后再修改
Service_BaiduPCS_Web(){
if [[ ${release} = "centos" ]]; then
if ! wget --no-check-certificate https://raw.githubusercontent.com/user1121114685/baidupcsweb/master/BaiduPCSWeb_centos -O /etc/init.d/BaiduPCSWeb; then
echo -e "${Error} BaiduPCS-Web服务 管理脚本下载失败 !" && exit 1
fi
Download_BaiduPCS_port
chmod +x /etc/init.d/BaiduPCSWeb
chkconfig --add BaiduPCSWeb
chkconfig BaiduPCSWeb on
else
if ! wget --no-check-certificate https://raw.githubusercontent.com/user1121114685/baidupcsweb/master/BaiduPCSWeb_debian -O /etc/init.d/BaiduPCSWeb; then
echo -e "${Error} BaiduPCS-Web服务 管理脚本下载失败 !" && exit 1
fi
Download_BaiduPCS_port
chmod +x /etc/init.d/BaiduPCSWeb
update-rc.d -f BaiduPCSWeb defaults
fi
echo -e "${Info} BaiduPCS-Web服务 管理脚本下载完成 !"
}
Download_BaiduPCS_port(){
if ! wget --no-check-certificate https://raw.githubusercontent.com/user1121114685/baidupcsweb/master/port -O ${Folder}/port; then
echo -e "${Error} BaiduPCS-Web服务 prot下载失败 !" && exit 1
fi
echo -e "成功下载port文件..."
chmod 777 ${Folder}/port
}
Installation_dependency(){
if [[ ${release} = "centos" ]]; then
yum update
yum install -y git zip unzip curl wget
else
apt-get update
apt-get install -y git zip unzip curl wget
fi
}
Install_BaiduPCS_Web(){
check_root
[[ -e ${BaiduPCS_Go} ]] && echo -e "${Error} BaiduPCS-Web 已安装,请检查 !" && exit 1
check_sys
echo -e "${Info} 开始安装/配置 依赖..."
Installation_dependency
echo -e "${Info} 开始下载/安装 主程序..."
check_new_ver
Download_BaiduPCS_Web
echo -e "${Info} 开始下载/安装 服务脚本(init)..."
Service_BaiduPCS_Web
echo -e "${Info} 设置端口..."
Set_BaiduPCS_port
echo -e "${Info} 所有步骤 安装完毕,开始启动..."
Start_BaiduPCS_Web
}
Start_BaiduPCS_Web(){
check_installed_status
check_pid
[[ ! -z ${PID} ]] && echo -e "${Error} BaiduPCS-Web 正在运行,请检查 !" && exit 1
/etc/init.d/BaiduPCSWeb start
}
Stop_BaiduPCS_Web(){
check_installed_status
check_pid
[[ -z ${PID} ]] && echo -e "${Error} BaiduPCS-Web 没有运行,请检查 !" && exit 1
/etc/init.d/BaiduPCSWeb stop
}
ReStart_BaiduPCS_Web(){
check_installed_status
check_pid
[[ ! -z ${PID} ]] && /etc/init.d/BaiduPCSWeb stop
/etc/init.d/BaiduPCSWeb start
}
Update_BaiduPCS_Web(){
check_installed_status
check_new_ver
check_ver_comparison
}
UnInstall_BaiduPCS_Web(){
check_installed_status "un"
echo "确定要卸载 BaiduPCS-Web ? (y/N)"
echo
read -e -p "(默认: n):" unyn
[[ -z ${unyn} ]] && unyn="n"
if [[ ${unyn} == [Yy] ]]; then
check_pid
[[ ! -z $PID ]] && kill -9 ${PID}
rm -rf "${BaiduPCS_Go}"
rm -rf "${Folder}"
rm -rf "${file}"
rm -rf "${Folder}/port"
if [[ ${release} = "centos" ]]; then
chkconfig --del BaiduPCSWeb
else
update-rc.d -f BaiduPCSWeb remove
fi
rm -rf "/etc/init.d/BaiduPCSWeb"
echo && echo "BaiduPCS-Web 卸载完成 !" && echo
else
echo && echo "卸载已取消..." && echo
fi
}
Update_Shell(){
local latest_version=$(curl -H 'Cache-Control: no-cache' -s -L "https://raw.githubusercontent.com/user1121114685/baidupcsweb/master/BDW.sh" | grep 'sh_ver' -m1 | cut -d\" -f2)
if [[ ! $latest_version ]]; then
echo
echo -e " $red获取 BaiduPCS_Web 最新版本失败!!!$none"
echo
echo -e " 请检查网络配置!"
echo
echo " 然后再继续...."
echo
exit 1
fi
if [[ $latest_version == $sh_ver ]]; then
echo
echo -e "$green 木有发现新版本 $none"
echo
else
echo
echo -e " $green 咦...发现新版本耶....正在拼命更新.......$none"
echo
wget -N --no-check-certificate "https://raw.githubusercontent.com/user1121114685/baidupcsweb/master/BDW.sh" && chmod +x BDW.sh
echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !(注意:因为更新方式为直接覆盖当前运行的脚本,所以可能下面会提示一些报错,无视即可)" && exit 0
fi
}
echo && echo -e " BaiduPCS-Web 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
by 联盟少侠
管理地址:http://你的IP:${BaiduPCS_port}(支持外网访问)
BaiduPCS-Web项目地址:https://github.com/liuzhuoling2011/baidupcs-web
本脚本的项目地址:https://github.com/user1121114685/baidupcsweb
${Green_font_prefix} 0.${Font_color_suffix} 升级脚本
————————————
${Green_font_prefix} 1.${Font_color_suffix} 安装 BaiduPCS-Web
${Green_font_prefix} 2.${Font_color_suffix} 更新 BaiduPCS-Web
${Green_font_prefix} 3.${Font_color_suffix} 卸载 BaiduPCS-Web
————————————
${Green_font_prefix} 4.${Font_color_suffix} 启动 BaiduPCS-Web
${Green_font_prefix} 5.${Font_color_suffix} 停止 BaiduPCS-Web
${Green_font_prefix} 6.${Font_color_suffix} 重启 BaiduPCS-Web
————————————
${Green_font_prefix} 7.${Font_color_suffix} 修改 BaiduPCS-Web 端口
————————————" && echo
if [[ -e ${Folder} ]]; then
check_pid
if [[ ! -z "${PID}" ]]; then
echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}"
else
echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}"
fi
else
echo -e " 当前状态: ${Red_font_prefix}未安装${Font_color_suffix}"
fi
echo
read -e -p " 请输入数字 [0-7]:" num
case "$num" in
0)
Update_Shell
;;
1)
Install_BaiduPCS_Web
;;
2)
Update_BaiduPCS_Web
;;
3)
UnInstall_BaiduPCS_Web
;;
4)
Start_BaiduPCS_Web
;;
5)
Stop_BaiduPCS_Web
;;
6)
ReStart_BaiduPCS_Web
;;
7)
Set_BaiduPCS_port
;;
*)
echo "请输入正确数字 [0-7]"
;;
esac