mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-06-28 09:16:55 +00:00
Merge pull request #619 from akhepcat/v4.2-dev
Update wgd.sh - install pypi mirror can auto select by rtt after delay
This commit is contained in:
commit
8e5cf14ebc
58
src/wgd.sh
58
src/wgd.sh
@ -15,6 +15,8 @@ heavy_checkmark=$(printf "\xE2\x9C\x85")
|
|||||||
heavy_crossmark=$(printf "\xE2\x9D\x8C")
|
heavy_crossmark=$(printf "\xE2\x9D\x8C")
|
||||||
install=$(printf "\xF0\x9F\x92\xBF")
|
install=$(printf "\xF0\x9F\x92\xBF")
|
||||||
|
|
||||||
|
msleep=15
|
||||||
|
|
||||||
PID_FILE=./gunicorn.pid
|
PID_FILE=./gunicorn.pid
|
||||||
environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi)
|
environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi)
|
||||||
if [[ $CONFIGURATION_PATH ]]; then
|
if [[ $CONFIGURATION_PATH ]]; then
|
||||||
@ -256,16 +258,16 @@ _determinePypiMirror(){
|
|||||||
printf "[WGDashboard] %s Pinging list of recommended Python Package Index mirror\n" "$install"
|
printf "[WGDashboard] %s Pinging list of recommended Python Package Index mirror\n" "$install"
|
||||||
urls=(
|
urls=(
|
||||||
"https://pypi.org/simple/"
|
"https://pypi.org/simple/"
|
||||||
"https://pypi.tuna.tsinghua.edu.cn/simple/"
|
"https://pypi.tuna.tsinghua.edu.cn/simple/"
|
||||||
"https://pypi.mirrors.ustc.edu.cn/simple/"
|
"https://pypi.mirrors.ustc.edu.cn/simple/"
|
||||||
"https://mirrors.aliyun.com/pypi/simple/"
|
"https://mirrors.aliyun.com/pypi/simple/"
|
||||||
"https://pypi.douban.com/simple/"
|
"https://pypi.douban.com/simple/"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Function to extract hostname and ping it
|
# Function to extract hostname and ping it
|
||||||
index=1
|
index=1
|
||||||
printf " ---------------------------------------------------------\n"
|
printf " ---------------------------------------------------------\n"
|
||||||
for url in "${urls[@]}"; do
|
for url in "${urls[@]}"; do
|
||||||
# Extract the hostname from the URL
|
# Extract the hostname from the URL
|
||||||
hostname=$(echo "$url" | awk -F/ '{print $3}')
|
hostname=$(echo "$url" | awk -F/ '{print $3}')
|
||||||
# Ping the hostname once and extract the RTT
|
# Ping the hostname once and extract the RTT
|
||||||
@ -275,24 +277,38 @@ _determinePypiMirror(){
|
|||||||
rtt="9999"
|
rtt="9999"
|
||||||
printf " [%i] [FAILED] %s\n" "$index" "$url"
|
printf " [%i] [FAILED] %s\n" "$index" "$url"
|
||||||
else
|
else
|
||||||
|
rtt=${rtt//.*/}
|
||||||
printf " [%i] %sms %s\n" "$index" "$rtt" "$url"
|
printf " [%i] %sms %s\n" "$index" "$rtt" "$url"
|
||||||
fi
|
fi
|
||||||
|
rtthost[$index]=$rtt
|
||||||
index=$((index+1))
|
index=$((index+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
for i in "${!rtthost[@]}"; do
|
||||||
|
[[ -z ${rtthost[i]} ]] && continue # Skip unset or empty values
|
||||||
|
if [[ -z $min_val || ${rtthost[i]} -lt $min_val ]]; then
|
||||||
|
min_val=${rtthost[i]}
|
||||||
|
min_idx=$i
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
min_idx=$((min_idx - 1))
|
||||||
|
|
||||||
printf "\n"
|
printf "\n"
|
||||||
printf " Which mirror you would like to use (Hit enter to use default): "
|
printf " Which mirror you would like to use (Hit enter or wait ${msleep} seconds to use default: ${urls[$min_idx]}): "
|
||||||
read -r choice
|
read -t ${msleep} -r choice
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
|
if [[ -z "$choice" ]]; then
|
||||||
|
choice=${min_dix}
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$choice" =~ ^[0-9]+$ ]] && (( choice >= 1 && choice <= ${#urls[@]} )); then
|
if [[ "$choice" =~ ^[0-9]+$ ]] && (( choice >= 1 && choice <= ${#urls[@]} )); then
|
||||||
selected_url="${urls[choice-1]}"
|
selected_url="${urls[choice-1]}"
|
||||||
printf "[WGDashboard] %s Will download Python packages from %s\n" "$heavy_checkmark" "$selected_url"
|
printf "[WGDashboard] %s Will download Python packages from %s\n" "$heavy_checkmark" "$selected_url"
|
||||||
else
|
else
|
||||||
selected_url="${urls[0]}"
|
selected_url="${urls[0]}"
|
||||||
printf "[WGDashboard] %s Will download Python packages from %s\n" "$heavy_checkmark" "${urls[0]}"
|
printf "[WGDashboard] %s Will download Python packages from %s\n" "$heavy_checkmark" "${urls[0]}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_wgd(){
|
install_wgd(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user