mirror of
https://github.com/Websoft9/websoft9.git
synced 2024-11-25 09:00:26 +00:00
Create pipinstall.sh
This commit is contained in:
parent
81e86a5de7
commit
4a3f5e7b6d
1 changed files with 46 additions and 0 deletions
46
scripts/pipinstall.sh
Normal file
46
scripts/pipinstall.sh
Normal file
|
@ -0,0 +1,46 @@
|
|||
function pipInstall() {
|
||||
requirementsFile=$1
|
||||
declare -a mirrors=(
|
||||
https://pypi.org
|
||||
https://pypi.tuna.tsinghua.edu.cn/simple/
|
||||
https://pypi.mirrors.ustc.edu.cn/simple/
|
||||
https://mirrors.aliyun.com/pypi/simple/
|
||||
https://pypi.hustunique.com/
|
||||
https://pypi.sdutlinux.org/
|
||||
https://pypi.douban.com/simple/
|
||||
https://repo.huaweicloud.com/repository/pypi/simple/
|
||||
)
|
||||
time=-1
|
||||
fastMirror=""
|
||||
for url in "${mirrors[@]}"; do
|
||||
SPEED_DOWNLOAD=$(curl --location --range 0-102400 --max-time 8 --silent --write-out %{speed_download} --output /dev/null "${url}")
|
||||
tempReult=$(echo "${SPEED_DOWNLOAD} ${time}" | awk '{if ($1 > $2) print 1; else print 0}')
|
||||
if [ "${tempReult}" -ne 0 ]; then
|
||||
time=${SPEED_DOWNLOAD}
|
||||
fastMirror=${url}
|
||||
fi
|
||||
done
|
||||
echo "choose the url: ${fastMirror}"
|
||||
pip install -r ${requirementsFile} -i ${fastMirror}
|
||||
}
|
||||
|
||||
function retry() {
|
||||
local retries=$1
|
||||
shift
|
||||
|
||||
local count=0
|
||||
until "$@"; do
|
||||
exit=$?
|
||||
wait=$((2 ** $count))
|
||||
count=$(($count + 1))
|
||||
if [ $count -lt $retries ]; then
|
||||
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
|
||||
sleep $wait
|
||||
else
|
||||
echo "Retry $count/$retries exited $exit, no more retries left."
|
||||
return $exit
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
retry 3 pipInstall requirement.txt
|
Loading…
Reference in a new issue