forked from qd-today/qd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
310 lines (283 loc) · 15.1 KB
/
update.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
#!/bin/bash
#
# FILE: update.sh
#
# DESCRIPTION: Update QianDao for Python3
#
# NOTES: This requires GNU getopt.
# I do not issue any guarantee that this will work for you!
#
# COPYRIGHT: (c) 2021-2022 by a76yyyy
#
# LICENSE: MIT
#
# ORGANIZATION: qiandao-today (https://github.com/qiandao-today)
#
# CREATED: 2021-10-28 20:00:00
#
#=======================================================================
_file=$(readlink -f $0)
_dir=$(dirname $_file)
cd $_dir
AUTO_RELOAD=$AUTO_RELOAD
# Treat unset variables as an error
set -o nounset
__ScriptVersion="2022.12.24"
__ScriptName="update.sh"
#-----------------------------------------------------------------------
# FUNCTION: usage
# DESCRIPTION: Display usage information.
#-----------------------------------------------------------------------
usage() {
cat << EOT
Usage : ${__ScriptName} [OPTION] ...
Update QianDao for Python3 from given options.
Options:
-h, --help Display help message
-s, --script-version Display script version
-u, --update Default update method
-v, --version=TAG_VERSION Forced Update to the specified tag version
-f, --force Forced version update
-l, --local Display Local version
-r, --remote Display Remote version
Exit status:
0 if OK,
!=0 if serious problems.
Example:
1) Use short options:
$ sh $__ScriptName -v=$(python -c 'import sys, json; print(json.load(open("version.json"))["version"])')
2) Use long options:
$ sh $__ScriptName --update
Report issues to https://github.com/qiandao-today/qiandao
EOT
} # ---------- end of function usage ----------
update() {
localversion=$(python -c 'import sys, json; print(json.load(open("version.json"))["version"])')
remoteversion=$(git ls-remote --tags origin | grep -o 'refs/tags/[0-9]*' | sort -r | head -n 1 | grep -o '[^\/]*$')
if [ $(echo $localversion $remoteversion | awk '$1>=$2 {print 0} $1<$2 {print 1}') == 1 ];then
echo -e "Info: 当前版本: $localversion \nInfo: 新版本: $remoteversion \nInfo: 正在更新中, 请稍候..."
wget https://gitee.com/a76yyyy/qiandao/raw/$remoteversion/requirements.txt -O /usr/src/app/requirements.txt && \
[[ -z "$(cat /etc/issue | grep -E "Alpine|alpine")" ]] && { \
pip install -r requirements.txt && \
echo "如需使用 DdddOCR API, 请确认安装 ddddocr Python模组 (如未安装, 请成功执行以下命令后重启qiandao); " && \
echo "pip3 install ddddocr" && \
echo "如需使用 PyCurl 功能, 请确认安装 pycurl Python模组 (如未安装, 请成功执行以下命令后重启qiandao); " && \
echo "pip3 install pycurl" ;\
} || { \
if [ $(echo $localversion | awk '$1>20211228 {print 0} $1<=20211228 {print 1}') == 1 ];then
echo "https://mirrors.ustc.edu.cn/alpine/edge/main" > /etc/apk/repositories
echo "https://mirrors.ustc.edu.cn/alpine/edge/community" >> /etc/apk/repositories
apk del .python-rundeps
echo "Info: 如需使用DDDDOCR API, 请重新拉取最新容器 (32位系统暂不支持此API). "
fi
apk add --update --no-cache openssh-client python3 py3-six py3-markupsafe py3-pycryptodome py3-tornado py3-wrapt py3-packaging py3-greenlet py3-urllib3 py3-cryptography py3-aiosignal py3-async-timeout py3-attrs py3-frozenlist py3-multidict py3-charset-normalizer py3-aiohttp py3-typing-extensions py3-yarl && \
if [ $(printenv QIANDAO_LITE) ] && [ "$QIANDAO_LITE" = "True" ];then
echo "Info: Qiandao-Lite will not install ddddocr related components. "
else
[[ $(getconf LONG_BIT) = "32" ]] && \
echo "Info: 32-bit systems do not support ddddocr, so there is no need to install numpy and opencv-python. " || \
apk add --update --no-cache py3-opencv py3-pillow
fi && \
apk add --no-cache --virtual .build_deps cmake make perl autoconf g++ automake \
linux-headers libtool util-linux py3-pip py3-setuptools py3-wheel python3-dev py3-numpy-dev
if [ -n $(ls /usr/bin | grep -w "python3$") ];then
ls /usr/bin | grep -w "python3$"
ln -sf /usr/bin/python3 /usr/bin/python
ln -sf /usr/bin/python3 /usr/local/bin/python
sed -i '/ddddocr/d' requirements.txt
sed -i '/packaging/d' requirements.txt
sed -i '/wrapt/d' requirements.txt
sed -i '/pycryptodome/d' requirements.txt
sed -i '/tornado/d' requirements.txt
sed -i '/MarkupSafe/d' requirements.txt
sed -i '/pillow/d' requirements.txt
sed -i '/opencv/d' requirements.txt
sed -i '/numpy/d' requirements.txt
sed -i '/greenlet/d' requirements.txt
sed -i '/urllib3/d' requirements.txt
sed -i '/cryptography/d' requirements.txt
sed -i '/aiosignal/d' requirements.txt
sed -i '/async-timeout/d' requirements.txt
sed -i '/attrs/d' requirements.txt
sed -i '/frozenlist/d' requirements.txt
sed -i '/multidict/d' requirements.txt
sed -i '/charset-normalizer/d' requirements.txt
sed -i '/aiohttp/d' requirements.txt
sed -i '/typing-extensions/d' requirements.txt
sed -i '/yarl/d' requirements.txt
fi
pip install --no-cache-dir -r requirements.txt
pip install --no-cache-dir --compile --upgrade pycurl
apk del .build_deps
rm -rf /var/cache/apk/*
rm -rf /usr/share/man/*
} && \
git fetch --all && \
git reset --hard origin/master && \
git checkout master && \
git pull
else
echo "Info: 当前版本: $localversion , 无需更新!"
fi
if [ $(printenv AUTO_RELOAD) ] && [ "$AUTO_RELOAD" == "False" ];then
echo "Info: 请手动重启容器, 或设置环境变量AUTO_RELOAD以开启热更新功能"
fi
}
force_update() {
localversion=$(python -c 'import sys, json; print(json.load(open("version.json"))["version"])')
remoteversion=$(git ls-remote --tags origin | grep -o 'refs/tags/[0-9]*' | sort -r | head -n 1 | grep -o '[^\/]*$')
echo -e "Info: 正在强制更新中, 请稍候..."
wget https://gitee.com/a76yyyy/qiandao/raw/master/requirements.txt -O /usr/src/app/requirements.txt && \
[[ -z "$(cat /etc/issue | grep -E "Alpine|alpine")" ]] && { \
pip install -r requirements.txt && \
echo "如需使用 DdddOCR API, 请确认安装 ddddocr Python模组 (如未安装, 请成功执行以下命令后重启qiandao); " && \
echo "pip3 install ddddocr" && \
echo "如需使用 PyCurl 功能, 请确认安装 pycurl Python模组 (如未安装, 请成功执行以下命令后重启qiandao); " && \
echo "pip3 install pycurl" ;\
} || { \
if [ $(echo $localversion | awk '$1>20211228 {print 0} $1<=20211228 {print 1}') == 1 ];then
echo "https://mirrors.ustc.edu.cn/alpine/edge/main" > /etc/apk/repositories
echo "https://mirrors.ustc.edu.cn/alpine/edge/community" >> /etc/apk/repositories
apk del .python-rundeps
echo "Info: 如需使用DDDDOCR API, 请重新拉取最新容器 (32位系统暂不支持此API). "
fi
apk add --update --no-cache openssh-client python3 py3-six py3-markupsafe py3-pycryptodome py3-tornado py3-wrapt py3-packaging py3-greenlet py3-urllib3 py3-cryptography py3-aiosignal py3-async-timeout py3-attrs py3-frozenlist py3-multidict py3-charset-normalizer py3-aiohttp py3-typing-extensions py3-yarl && \
if [ $(printenv QIANDAO_LITE) ] && [ "$QIANDAO_LITE" = "True" ];then
echo "Info: Qiandao-Lite will not install ddddocr related components. "
else
[[ $(getconf LONG_BIT) = "32" ]] && \
echo "Info: 32-bit systems do not support ddddocr, so there is no need to install numpy and opencv-python. " || \
apk add --update --no-cache py3-opencv py3-pillow
fi && \
apk add --no-cache --virtual .build_deps cmake make perl autoconf g++ automake \
linux-headers libtool util-linux py3-pip py3-setuptools py3-wheel python3-dev py3-numpy-dev
if [ -n $(ls /usr/bin | grep -w "python3$") ];then
ls /usr/bin | grep -w "python3$"
ln -sf /usr/bin/python3 /usr/bin/python
ln -sf /usr/bin/python3 /usr/local/bin/python
sed -i '/ddddocr/d' requirements.txt
sed -i '/packaging/d' requirements.txt
sed -i '/wrapt/d' requirements.txt
sed -i '/pycryptodome/d' requirements.txt
sed -i '/tornado/d' requirements.txt
sed -i '/MarkupSafe/d' requirements.txt
sed -i '/pillow/d' requirements.txt
sed -i '/opencv/d' requirements.txt
sed -i '/numpy/d' requirements.txt
sed -i '/greenlet/d' requirements.txt
sed -i '/urllib3/d' requirements.txt
sed -i '/cryptography/d' requirements.txt
sed -i '/aiosignal/d' requirements.txt
sed -i '/async-timeout/d' requirements.txt
sed -i '/attrs/d' requirements.txt
sed -i '/frozenlist/d' requirements.txt
sed -i '/multidict/d' requirements.txt
sed -i '/charset-normalizer/d' requirements.txt
sed -i '/aiohttp/d' requirements.txt
sed -i '/typing-extensions/d' requirements.txt
sed -i '/yarl/d' requirements.txt
fi
pip install --no-cache-dir -r requirements.txt
pip install --no-cache-dir --compile --upgrade pycurl
apk del .build_deps
rm -rf /var/cache/apk/*
rm -rf /usr/share/man/*
} && \
git fetch --all && \
git reset --hard origin/master && \
git checkout master && \
git pull
if [ $(printenv AUTO_RELOAD) ] && [ "$AUTO_RELOAD" == "False" ];then
echo "Info: 请手动重启容器, 或设置环境变量AUTO_RELOAD以开启热更新功能"
fi
}
update_version() {
echo -e "Info: 正在强制切换至指定Tag版本: $1, 请稍候..."
wget https://gitee.com/a76yyyy/qiandao/raw/$1/requirements.txt -O /usr/src/app/requirements.txt && \
[[ -z "$(cat /etc/issue | grep -E "Alpine|alpine")" ]] && { \
pip install -r requirements.txt && \
echo "如需使用 DdddOCR API, 请确认安装 ddddocr Python模组 (如未安装, 请成功执行以下命令后重启qiandao); " && \
echo "pip3 install ddddocr" && \
echo "如需使用 PyCurl 功能, 请确认安装 pycurl Python模组 (如未安装, 请成功执行以下命令后重启qiandao); " && \
echo "pip3 install pycurl" ;\
} || { \
if [ $(echo $localversion | awk '$1>20211228 {print 0} $1<=20211228 {print 1}') == 1 ];then
echo "https://mirrors.ustc.edu.cn/alpine/edge/main" > /etc/apk/repositories
echo "https://mirrors.ustc.edu.cn/alpine/edge/community" >> /etc/apk/repositories
apk del .python-rundeps
echo "Info: 如需使用DDDDOCR API, 请重新拉取最新容器 (32位系统暂不支持此API). "
fi
apk add --update --no-cache openssh-client python3 py3-six py3-markupsafe py3-pycryptodome py3-tornado py3-wrapt py3-packaging py3-greenlet py3-urllib3 py3-cryptography py3-aiosignal py3-async-timeout py3-attrs py3-frozenlist py3-multidict py3-charset-normalizer py3-aiohttp py3-typing-extensions py3-yarl && \
if [ $(printenv QIANDAO_LITE) ] && [ "$QIANDAO_LITE" = "True" ];then
echo "Info: Qiandao-Lite will not install ddddocr related components. "
else
[[ $(getconf LONG_BIT) = "32" ]] && \
echo "Info: 32-bit systems do not support ddddocr, so there is no need to install numpy and opencv-python. " || \
apk add --update --no-cache py3-opencv py3-pillow
fi && \
apk add --no-cache --virtual .build_deps cmake make perl autoconf g++ automake \
linux-headers libtool util-linux py3-pip py3-setuptools py3-wheel python3-dev py3-numpy-dev
if [ -n $(ls /usr/bin | grep -w "python3$") ];then
ls /usr/bin | grep -w "python3$"
ln -sf /usr/bin/python3 /usr/bin/python
ln -sf /usr/bin/python3 /usr/local/bin/python
sed -i '/ddddocr/d' requirements.txt
sed -i '/packaging/d' requirements.txt
sed -i '/wrapt/d' requirements.txt
sed -i '/pycryptodome/d' requirements.txt
sed -i '/tornado/d' requirements.txt
sed -i '/MarkupSafe/d' requirements.txt
sed -i '/pillow/d' requirements.txt
sed -i '/opencv/d' requirements.txt
sed -i '/numpy/d' requirements.txt
sed -i '/greenlet/d' requirements.txt
sed -i '/urllib3/d' requirements.txt
sed -i '/cryptography/d' requirements.txt
sed -i '/aiosignal/d' requirements.txt
sed -i '/async-timeout/d' requirements.txt
sed -i '/attrs/d' requirements.txt
sed -i '/frozenlist/d' requirements.txt
sed -i '/multidict/d' requirements.txt
sed -i '/charset-normalizer/d' requirements.txt
sed -i '/aiohttp/d' requirements.txt
sed -i '/typing-extensions/d' requirements.txt
sed -i '/yarl/d' requirements.txt
fi
pip install --no-cache-dir -r requirements.txt
pip install --no-cache-dir --compile --upgrade pycurl
apk del .build_deps
rm -rf /var/cache/apk/*
rm -rf /usr/share/man/*
} && \
git fetch --all && \
git checkout -f $1
if [ $(printenv AUTO_RELOAD) ] && [ "$AUTO_RELOAD" == "False" ];then
echo "Info: 请手动重启容器, 或设置环境变量AUTO_RELOAD以开启热更新功能"
fi
}
if [ $# == 0 ]; then update; exit 0; fi
# parse options:
RET=`getopt -o hsuv:flr \
--long help,script-version,update,version:,force,local,remote \
-n ' * ERROR' -- "$@"`
if [ $? != 0 ] ; then echo "Error: $__ScriptName exited with doing nothing." >&2 ; exit 1 ; fi
# Note the quotes around $RET: they are essential!
eval set -- "$RET"
# set option values
while true; do
case "$1" in
-h | --help ) usage; exit 1 ;;
-s | --script-version ) echo "$(basename $0) -- version $__ScriptVersion"; exit 1 ;;
-u | --update ) update; exit 0 ;;
-v | --version ) echo "$2" | grep [^0-9] >/dev/null && echo "'$2' is not correct type of tag" || update_version $2; exit 0 ;;
-f | --force ) force_update; exit 0 ;;
-l | --local ) echo "当前版本: $(python -c 'import sys, json; print(json.load(open("version.json"))["version"])')"; shift ;;
-r | --remote ) echo "远程版本: $(git ls-remote --tags origin | grep -o 'refs/tags/[0-9]*' | sort -r | head -n 1 | grep -o '[^\/]*$')"; shift ;;
-- ) shift; break ;;
* ) echo "Error: internal error!" ; exit 1 ;;
esac
done
# # remaining argument
# for arg do
# # method
# done