mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-06-28 09:16:55 +00:00
Add auto-select based on ping response
This commit is contained in:
parent
a2db4f06b1
commit
69b9116dd5
18
src/wgd.sh
18
src/wgd.sh
@ -275,17 +275,31 @@ _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))
|
||||||
|
|
||||||
msleep=5
|
msleep=5
|
||||||
printf "\n"
|
printf "\n"
|
||||||
printf " Which mirror you would like to use (Hit enter or wait ${msleep} seconds to use default): "
|
printf " Which mirror you would like to use (Hit enter or wait ${msleep} seconds to use default: ${urls[$min_idx]}): "
|
||||||
read -t ${msleep} -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]}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user