From 54c63acc2778c4a093461a12d8713a37bc7712cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=B5=E4=BA=8C?= <66155308+miaoermua@users.noreply.github.com> Date: Sat, 31 Aug 2024 20:05:16 +0800 Subject: [PATCH] fix: update fail --- cattools.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cattools.sh b/cattools.sh index fb06571..4e1d0ae 100644 --- a/cattools.sh +++ b/cattools.sh @@ -20,10 +20,11 @@ if ! grep -qi -E "OpenWrt|QWRT" /etc/openwrt_release; then exit 1 fi -# Update +# Update CatTools update_cattools() { echo "Please wait for the cattools to be updated." local target_file="/usr/bin/cattools" + local temp_file="/tmp/cattools/cattools.sh" local retries=3 local success=false local urls=( @@ -32,16 +33,16 @@ update_cattools() { "https://raw.githubusercontent.com/miaoermua/cattools/main/cattools.sh" ) + mkdir -p /tmp/cattools + while [ $retries -gt 0 ]; do for url in "${urls[@]}"; do - curl --silent --connect-timeout 3 --max-time 5 -o "$target_file" "$url" + curl --silent --connect-timeout 3 --max-time 5 -o "$temp_file" "$url" curl_exit_code=$? - if [ $curl_exit_code -eq 0 ]; then - if [ -s "$target_file" ]; then - success=true - break 2 - fi + if [ $curl_exit_code -eq 0 ] && [ -s "$temp_file" ]; then + success=true + break 2 fi done @@ -52,10 +53,11 @@ update_cattools() { if [ "$success" = false ]; then echo "Unable to download the latest version, continue to use the current offline version." echo "" - rm -f "$target_file" + rm -f "$temp_file" return fi + mv "$temp_file" "$target_file" chmod +x "$target_file" echo "cattools updated successfully." echo ""