代码拉取完成,页面将自动刷新
同步操作将从 qd-today/qd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/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.02.04"
__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}') -eq 1 ];then
echo -e "Info: 当前版本: $localversion \nInfo: 新版本: $remoteversion \nInfo: 正在更新中,请稍候..."
git fetch --all
git reset --hard origin/master
git checkout master
git pull
[[ -z $(file /bin/busybox | grep -i "musl") ]] && \
pip install -r requirements.txt || {\
if [ $(echo $localversion | awk '$1>20211228 {print 0} $1<=20211228 {print 1}') -eq 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 "如需使用DDDDOCR API,请重新拉取最新容器(ARM32暂不支持此API)"
fi
apk add --update --no-cache openrc redis bash git tzdata nano openssh-client ca-certificates\
file libidn2-dev libgsasl-dev krb5-dev zstd-dev nghttp2-dev zlib-dev brotli-dev \
python3 py3-numpy-dev py3-pip py3-setuptools py3-wheel py3-opencv python3-dev \
py3-pillow py3-markupsafe py3-pycryptodome py3-tornado py3-wrapt py3-packaging
apk add --no-cache --virtual .build_deps cmake make perl autoconf g++ automake \
linux-headers libtool util-linux
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
pip install --no-cache-dir -r requirements.txt
pip install --no-cache-dir --compile pycurl
apk del .build_deps
rm -rf /var/cache/apk/*
rm -rf /usr/share/man/*
}
else
echo "Info: 当前版本: $localversion , 无需更新!"
fi
if [ $AUTO_RELOAD ] && [ "$AUTO_RELOAD" == "False" ];then
echo "Info: 请手动重启容器,或设置环境变量AUTO_RELOAD以开启热更新功能"
fi
}
force_update() {
echo -e "Info: 正在强制更新中,请稍候..."
git fetch --all
git reset --hard origin/master
git checkout master
git pull
[[ -z $(file /bin/busybox | grep -i "musl") ]] && \
pip install -r requirements.txt || {\
if [ $(echo $localversion | awk '$1>20211228 {print 0} $1<=20211228 {print 1}') -eq 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 "如需使用DDDDOCR API,请重新拉取最新容器(ARM32暂不支持此API)"
fi
apk add --update --no-cache openrc redis bash git tzdata nano openssh-client ca-certificates\
file libidn2-dev libgsasl-dev krb5-dev zstd-dev nghttp2-dev zlib-dev brotli-dev \
python3 py3-numpy-dev py3-pip py3-setuptools py3-wheel py3-opencv python3-dev \
py3-pillow py3-markupsafe py3-pycryptodome py3-tornado py3-wrapt py3-packaging
apk add --no-cache --virtual .build_deps cmake make perl autoconf g++ automake \
linux-headers libtool util-linux
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
pip install --no-cache-dir -r requirements.txt
pip install --no-cache-dir --compile pycurl
apk del .build_deps
rm -rf /var/cache/apk/*
rm -rf /usr/share/man/*
}
if [ $AUTO_RELOAD ] && [ "$AUTO_RELOAD" == "False" ];then
echo "Info: 请手动重启容器,或设置环境变量AUTO_RELOAD以开启热更新功能"
fi
}
update_version() {
echo -e "Info: 正在强制切换至指定Tag版本: $1,请稍候..."
git fetch --all
git checkout -f $1
[[ -z $(file /bin/busybox | grep -i "musl") ]] && \
pip install -r requirements.txt || {\
if [ $(echo $localversion | awk '$1>20211228 {print 0} $1<=20211228 {print 1}') -eq 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 "如需使用DDDDOCR API,请重新拉取最新容器(ARM32暂不支持此API)"
fi
apk add --update --no-cache openrc redis bash git tzdata nano openssh-client ca-certificates\
file libidn2-dev libgsasl-dev krb5-dev zstd-dev nghttp2-dev zlib-dev brotli-dev \
python3 py3-numpy-dev py3-pip py3-setuptools py3-wheel py3-opencv python3-dev \
py3-pillow py3-markupsafe py3-pycryptodome py3-tornado py3-wrapt py3-packaging
apk add --no-cache --virtual .build_deps cmake make perl autoconf g++ automake \
linux-headers libtool util-linux
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
pip install --no-cache-dir -r requirements.txt
pip install --no-cache-dir --compile pycurl
apk del .build_deps
rm -rf /var/cache/apk/*
rm -rf /usr/share/man/*
}
if [ $AUTO_RELOAD ] && [ "$AUTO_RELOAD" == "False" ];then
echo "Info: 请手动重启容器,或设置环境变量AUTO_RELOAD以开启热更新功能"
fi
}
if [ $# -eq 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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。