From a2db4f06b161d12a40ffcc1ec01eece140ca691c Mon Sep 17 00:00:00 2001 From: Leif Date: Sun, 16 Feb 2025 11:43:47 -0900 Subject: [PATCH 1/3] Update wgd.sh install pypi mirror auto select add timeout value so that the install/update can run fully scripted without normal user intervention if desired --- src/wgd.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wgd.sh b/src/wgd.sh index e230900..2971ebc 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -281,9 +281,10 @@ _determinePypiMirror(){ index=$((index+1)) done + msleep=5 printf "\n" - printf " Which mirror you would like to use (Hit enter to use default): " - read -r choice + printf " Which mirror you would like to use (Hit enter or wait ${msleep} seconds to use default): " + read -t ${msleep} -r choice if [[ "$choice" =~ ^[0-9]+$ ]] && (( choice >= 1 && choice <= ${#urls[@]} )); then From 69b9116dd54284b5a251292f76be8964d6afab09 Mon Sep 17 00:00:00 2001 From: Leif Sawyer Date: Sun, 16 Feb 2025 14:53:03 -0900 Subject: [PATCH 2/3] Add auto-select based on ping response --- src/wgd.sh | 56 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/wgd.sh b/src/wgd.sh index 2971ebc..98e4bac 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -256,16 +256,16 @@ _determinePypiMirror(){ printf "[WGDashboard] %s Pinging list of recommended Python Package Index mirror\n" "$install" urls=( "https://pypi.org/simple/" - "https://pypi.tuna.tsinghua.edu.cn/simple/" - "https://pypi.mirrors.ustc.edu.cn/simple/" - "https://mirrors.aliyun.com/pypi/simple/" - "https://pypi.douban.com/simple/" - ) - - # Function to extract hostname and ping it - index=1 - printf " ---------------------------------------------------------\n" - for url in "${urls[@]}"; do + "https://pypi.tuna.tsinghua.edu.cn/simple/" + "https://pypi.mirrors.ustc.edu.cn/simple/" + "https://mirrors.aliyun.com/pypi/simple/" + "https://pypi.douban.com/simple/" + ) + + # Function to extract hostname and ping it + index=1 + printf " ---------------------------------------------------------\n" + for url in "${urls[@]}"; do # Extract the hostname from the URL hostname=$(echo "$url" | awk -F/ '{print $3}') # Ping the hostname once and extract the RTT @@ -275,25 +275,39 @@ _determinePypiMirror(){ rtt="9999" printf " [%i] [FAILED] %s\n" "$index" "$url" else + rtt=${rtt//.*/} printf " [%i] %sms %s\n" "$index" "$rtt" "$url" fi - + rtthost[$index]=$rtt index=$((index+1)) 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 printf "\n" - printf " Which mirror you would like to use (Hit enter or wait ${msleep} seconds to use default): " - read -t ${msleep} -r choice - - + 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 + printf "\n" + + if [[ -z "$choice" ]]; then + choice=${min_dix} + fi + if [[ "$choice" =~ ^[0-9]+$ ]] && (( choice >= 1 && choice <= ${#urls[@]} )); then - selected_url="${urls[choice-1]}" - printf "[WGDashboard] %s Will download Python packages from %s\n" "$heavy_checkmark" "$selected_url" - else - selected_url="${urls[0]}" - printf "[WGDashboard] %s Will download Python packages from %s\n" "$heavy_checkmark" "${urls[0]}" - fi + selected_url="${urls[choice-1]}" + printf "[WGDashboard] %s Will download Python packages from %s\n" "$heavy_checkmark" "$selected_url" + else + selected_url="${urls[0]}" + printf "[WGDashboard] %s Will download Python packages from %s\n" "$heavy_checkmark" "${urls[0]}" + fi } install_wgd(){ From 7c8410ab86ffa9f81419664dcfa01f573772ba0e Mon Sep 17 00:00:00 2001 From: Leif Date: Mon, 17 Feb 2025 09:41:11 -0900 Subject: [PATCH 3/3] Update wgd.sh update msleep for longer timeout, and move that var to the top to make it more obvious --- src/wgd.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wgd.sh b/src/wgd.sh index 98e4bac..45891eb 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -15,6 +15,8 @@ heavy_checkmark=$(printf "\xE2\x9C\x85") heavy_crossmark=$(printf "\xE2\x9D\x8C") install=$(printf "\xF0\x9F\x92\xBF") +msleep=15 + PID_FILE=./gunicorn.pid environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi) if [[ $CONFIGURATION_PATH ]]; then @@ -291,7 +293,6 @@ _determinePypiMirror(){ done min_idx=$((min_idx - 1)) - msleep=5 printf "\n" 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