From d59de920eb90d916e58d33d4e9703c2f33d369fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=B5=E4=BA=8C?= <66155308+miaoermua@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:39:23 +0800 Subject: [PATCH] Update: Hotupdate --- cattools.sh | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/cattools.sh b/cattools.sh index 5266b63..beadfa9 100644 --- a/cattools.sh +++ b/cattools.sh @@ -23,38 +23,40 @@ fi # Update update_cattools() { echo "Please wait for the script to be updated." - local temp_file=$(mktemp) + local target_file="/usr/bin/cattools" local retries=3 local success=false + local urls=( + "https://raw.githubusercontent.com/miaoermua/cattools/main/cattools.sh" + "https://mirror.ghproxy.com/https://raw.githubusercontent.com/miaoermua/cattools/main/cattools.sh" + "https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/cattools.sh" + ) while [ $retries -gt 0 ]; do - if curl --silent --connect-timeout 3 --max-time 5 -o "$temp_file" https://raw.githubusercontent.com/miaoermua/cattools/main/cattools.sh; then - echo "cattools update downloaded from the first URL." - success=true - break - elif curl --silent --connect-timeout 3 --max-time 5 -o "$temp_file" https://mirror.ghproxy.com/https://raw.githubusercontent.com/miaoermua/cattools/main/cattools.sh; then - echo "cattools update downloaded from the second URL." - success=true - break - elif curl --silent --connect-timeout 3 --max-time 5 -o "$temp_file" https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/cattools.sh; then - echo "cattools update downloaded from the third URL." - success=true - break - else - echo "Attempt $((4 - retries)) failed. Retrying..." - retries=$((retries - 1)) - fi + for url in "${urls[@]}"; do + curl --silent --connect-timeout 3 --max-time 5 -o "$target_file" "$url" + curl_exit_code=$? + + if [ $curl_exit_code -eq 0 ]; then + if [ -s "$target_file" ]; then + success=true + break 2 + fi + fi + done + + echo "Attempt $((4 - retries)) failed. Retrying..." + retries=$((retries - 1)) done if [ "$success" = false ]; then echo "Unable to download the latest version, continue to use the current offline version." echo "" - rm -f "$temp_file" + rm -f "$target_file" return fi - mv "$temp_file" /usr/bin/cattools - chmod +x /usr/bin/cattools + chmod +x "$target_file" echo "cattools updated successfully." echo "" }