-
Notifications
You must be signed in to change notification settings - Fork 66
/
qbee_p.sh
145 lines (129 loc) · 7.94 KB
/
qbee_p.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
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# --------------------------------------------------------------
# 系统: ALL
# 项目: qBittorrent Enhanced Edition 便携版制作 脚本
# 版本: 1.0.6
# 作者: XIU2
# 官网: https://shell.xiu2.xyz
# 项目: https://github.com/XIU2/Shell
# --------------------------------------------------------------
# 首次使用脚本前,请先配置好 FOLDER_ID、TOKEN、FOLDER、LZY_PATH 四个变量。
FOLDER_ID="12345" # 蓝奏云网盘要上传文件的文件夹 ID, https://shell.xiu2.xyz/#/md/lanzou_up?id=%e8%8e%b7%e5%8f%96%e6%96%87%e4%bb%b6%e5%a4%b9id
TOKEN="XXX" # 微信推送链接 Token,可选
FOLDER="/root/qBittorrentEE" # 脚本工作目录(下载、解压、压缩、上传等操作都在这个文件夹内),脚本会自动创建文件夹
LZY_PATH="/root/lanzou_up.sh" # 蓝奏云上传文件脚本位置, https://shell.xiu2.xyz/#/md/lanzou_up
FILE_FORMAT="zip" # 最后打包的压缩包格式,推荐 zip 或 7z
UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
FOLDER_DOWNLOAD="${FOLDER}/Download" # 存放下载文件的文件夹
FOLDER_DOWNLOAD_UNZIP="${FOLDER_DOWNLOAD}/qBittorrentEE" # 解压下载文件的文件夹
FOLDER_OTHER="${FOLDER}/Other" # 存放配置等文件文件夹
FOLDER_UPLOAD="${FOLDER}/Upload" # 存放压缩后文件 并 上传的文件夹
FILE_OLD_VER="${FOLDER}/old_ver.txt" # 存放旧版本号的文件(每次执行脚本都会检查最新版本)
INFO="[信息]" && ERROR="[错误]" && TIP="[注意]"
# 检查最新版本,可以通过 _CHECK_VER "x.x.x" 来指定版本
_CHECK_VER(){
NEW_VER=$1 # 此处是手动指定版本号时的代码
[[ -z ${NEW_VER} ]] && NEW_VER=$(wget -qO- https://api.github.com/repos/c0re100/qBittorrent-Enhanced-Edition/releases| grep "tag_name"| head -n 1| awk -F ":" '{print $2}'| sed 's/\"//g;s/,//g;s/ //g;s/release-//')
[[ -z ${NEW_VER} ]] && _NOTICE_MAIL "ERROR" "qBittorrentEE最新版本获取失败!"
[[ ! -e ${FOLDER} ]] && mkdir "${FOLDER}" # 如果主文件夹不存在,就新建
[[ ! -e ${FILE_OLD_VER} ]] && echo -n ${NEW_VER} > ${FILE_OLD_VER} # 如果旧版本文件不存在,说明是首次运行,则把当前版本号写入该文件
[[ $(cat ${FILE_OLD_VER}) == ${NEW_VER} ]] && echo -e "${INFO} 已经是最新版本!${NEW_VER} [$(date '+%Y/%m/%d %H:%M')]" && exit 1
}
# 下载
_DOWNLOAD(){
[[ ! -e ${FOLDER_DOWNLOAD} ]] && mkdir "${FOLDER_DOWNLOAD}" # 如果下载文件夹不存在,就新建
cd ${FOLDER_DOWNLOAD}
if ! wget --no-check-certificate -q -t2 -T5 -4 -U "${UA}" -O "qbittorrentEE_x32.exe" "https://github.com/c0re100/qBittorrent-Enhanced-Edition/releases/download/release-${NEW_VER}/qbittorrent_enhanced_${NEW_VER}_setup.exe"; then
rm -f qbittorrentEE_x32.exe
_NOTICE_MAIL "ERROR" "qBittorrentEE_x32_v${NEW_VER}下载失败!"
fi
if ! wget --no-check-certificate -q -t2 -T5 -4 -U "${UA}" -O "qbittorrentEE_x64.exe" "https://github.com/c0re100/qBittorrent-Enhanced-Edition/releases/download/release-${NEW_VER}/qbittorrent_enhanced_${NEW_VER}_x64_setup.exe"; then
rm -f qbittorrentEE_x64.exe
_NOTICE_MAIL "ERROR" "qBittorrentEE_x64_v${NEW_VER}下载失败!"
fi
}
_DOWNLOAD_qt6(){
[[ ! -e ${FOLDER_DOWNLOAD} ]] && mkdir "${FOLDER_DOWNLOAD}" # 如果下载文件夹不存在,就新建
cd ${FOLDER_DOWNLOAD}
if ! wget --no-check-certificate -q -t2 -T5 -4 -U "${UA}" -O "qbittorrentEE_qt6_x64.exe" "https://github.com/c0re100/qBittorrent-Enhanced-Edition/releases/download/release-${NEW_VER}/qbittorrent_enhanced_${NEW_VER}_qt6_x64_setup.exe"; then
rm -f qbittorrentEE_qt6_x64.exe
_NOTICE_MAIL "ERROR" "qBittorrentEE_qt6_x64_v${NEW_VER} 下载失败!"
fi
}
# 解压
_UNZIP(){
[[ -e ${FOLDER_DOWNLOAD_UNZIP} ]] && rm -rf "${FOLDER_DOWNLOAD_UNZIP}" # 如果解压文件夹存在,就删除并重建
mkdir "${FOLDER_DOWNLOAD_UNZIP}"
7z x -bb0 -x'!qbittorrent.pdb' -x'!$PLUGINSDIR' -o"${FOLDER_DOWNLOAD_UNZIP}" qbittorrentEE_x64.exe > /dev/null # 解压64位文件
[[ ! -e "${FOLDER_DOWNLOAD_UNZIP}/qbittorrent.exe" ]] && _NOTICE_MAIL "ERROR" "qBittorrentEE_x64_v${NEW_VER} 解压失败!"
mv "${FOLDER_DOWNLOAD_UNZIP}/qbittorrent.exe" "${FOLDER_DOWNLOAD_UNZIP}/qbittorrent_x64.exe" # 将 qbittorrent.exe 重命名位 qbittorrent_x64.exe
7z e -bb0 -o"${FOLDER_DOWNLOAD_UNZIP}" qbittorrentEE_x32.exe qbittorrent.exe > /dev/null # 解压32位文件,仅 qbittorrent.exe
[[ ! -e "${FOLDER_DOWNLOAD_UNZIP}/qbittorrent.exe" ]] && _NOTICE_MAIL "ERROR" "qBittorrentEE_x32_v${NEW_VER} 解压失败!"
rm -rf qbittorrentEE_x64.exe
rm -rf qbittorrentEE_x32.exe
cd "${FOLDER_DOWNLOAD_UNZIP}/translations"
rm -f $(ls|egrep -v 'zh_') # 删除非中文语言文件,如果需要全语言,则注释这一行及上一行(行首加井号)
}
_UNZIP_qt6(){
[[ -e ${FOLDER_DOWNLOAD_UNZIP} ]] && rm -rf "${FOLDER_DOWNLOAD_UNZIP}" # 如果解压文件夹存在,就删除并重建
mkdir "${FOLDER_DOWNLOAD_UNZIP}"
7z x -bb0 -x'!qbittorrent.pdb' -x'!$PLUGINSDIR' -o"${FOLDER_DOWNLOAD_UNZIP}" qbittorrentEE_qt6_x64.exe > /dev/null # 解压64位文件
[[ ! -e "${FOLDER_DOWNLOAD_UNZIP}/qbittorrent.exe" ]] && _NOTICE_MAIL "ERROR" "qBittorrentEE_qt6_x64_v${NEW_VER} 解压失败!"
rm -rf qbittorrentEE_qt6_x64.exe
cd "${FOLDER_DOWNLOAD_UNZIP}/translations"
rm -f $(ls|egrep -v 'zh_') # 删除非中文语言文件,如果需要全语言,则注释这一行及上一行(行首加井号)
}
# 压缩
_ZIP(){
cd ${FOLDER_DOWNLOAD}
# 复制配置等文件到文件夹内
cp -r "${FOLDER_OTHER}"/* "${FOLDER_DOWNLOAD_UNZIP}"
7z a -bb0 "qBittorrentEE_v${NEW_VER}_便携版.${FILE_FORMAT}" "qBittorrentEE" "" > /dev/null # 压缩
rm -rf "${FOLDER_DOWNLOAD_UNZIP}" # 删除前面解压,已经无用文件夹
[[ ! -e "qBittorrentEE_v${NEW_VER}_便携版.${FILE_FORMAT}" ]] && _NOTICE_MAIL "ERROR" "qBittorrentEE_v${NEW_VER} 压缩失败!"
[[ ! -e ${FOLDER_UPLOAD} ]] && mkdir "${FOLDER_UPLOAD}" # 如果上传文件夹不存在,就新建
mv "qBittorrentEE_v${NEW_VER}_便携版.${FILE_FORMAT}" "${FOLDER_UPLOAD}" # 移动到上传文件夹
}
_ZIP_qt6(){
cd ${FOLDER_DOWNLOAD}
# 复制配置等文件到文件夹内
cp -r "${FOLDER_OTHER}"/* "${FOLDER_DOWNLOAD_UNZIP}"
7z a -bb0 "qBittorrentEE_v${NEW_VER}_qt6_x64_便携版.${FILE_FORMAT}" "qBittorrentEE" "" > /dev/null # 压缩
rm -rf "${FOLDER_DOWNLOAD_UNZIP}" # 删除前面解压,已经无用文件夹
[[ ! -e "qBittorrentEE_v${NEW_VER}_qt6_x64_便携版.${FILE_FORMAT}" ]] && _NOTICE_MAIL "ERROR" "qBittorrentEE_v${NEW_VER}_qt6_x64 压缩失败!"
[[ ! -e ${FOLDER_UPLOAD} ]] && mkdir "${FOLDER_UPLOAD}" # 如果上传文件夹不存在,就新建
mv "qBittorrentEE_v${NEW_VER}_qt6_x64_便携版.${FILE_FORMAT}" "${FOLDER_UPLOAD}" # 移动到上传文件夹
}
#上传
_UPLOAD(){
bash ${LZY_PATH} "qBittorrentEE_v${NEW_VER}_便携版.${FILE_FORMAT}" "${FOLDER_UPLOAD}/qBittorrentEE_v${NEW_VER}_便携版.${FILE_FORMAT}" "${FOLDER_ID}"
#_NOTICE "INFO" "qBittorrentEE_v${NEW_VER}" # 你可以取消井号注释,这样每次更新也会推送消息至微信
}
# 通知
_NOTICE() {
PARAMETER_1="$1"
PARAMETER_2="$2"
if [[ "${TOKEN}" != "" && "${TOKEN}" != "XXX" ]]; then
# 微信推送 Server酱 https://sc.ftqq.com/3.version
#wget --no-check-certificate -t2 -T5 -4 -U "${UA}" -qO- "https://sc.ftqq.com/${TOKEN}.send?text=${PARAMETER_1}${PARAMETER_2}"
# 微信推送 pushplus http://pushplus.hxtrip.com/
wget --no-check-certificate -t2 -T5 -4 -U "${UA}" -qO- "http://pushplus.hxtrip.com/customer/push/send?token=${TOKEN}&title=${PARAMETER_1}&content=${PARAMETER_2}"
fi
if [[ ${PARAMETER_1} == "INFO" ]]; then
echo -e "${INFO} ${PARAMETER_2}"
else
echo -e "${ERROR} ${PARAMETER_2}"
fi
exit 1
}
_CHECK_VER "$1" # 运行脚本的时候传递参数可以指定版本号,例:bash qbee_p.sh "4.2.5.11"
_DOWNLOAD
_UNZIP
_ZIP
_DOWNLOAD_qt6
_UNZIP_qt6
_ZIP_qt6
echo -n ${NEW_VER} > ${FILE_OLD_VER}
#_UPLOAD # 如果不想上传到蓝奏云,可以把这行注释掉(行首加井号)