fix: update fail

This commit is contained in:
喵二
2024-08-31 20:05:16 +08:00
committed by GitHub
parent f544e42629
commit 54c63acc27

View File

@@ -20,10 +20,11 @@ if ! grep -qi -E "OpenWrt|QWRT" /etc/openwrt_release; then
exit 1 exit 1
fi fi
# Update # Update CatTools
update_cattools() { update_cattools() {
echo "Please wait for the cattools to be updated." echo "Please wait for the cattools to be updated."
local target_file="/usr/bin/cattools" local target_file="/usr/bin/cattools"
local temp_file="/tmp/cattools/cattools.sh"
local retries=3 local retries=3
local success=false local success=false
local urls=( local urls=(
@@ -32,17 +33,17 @@ update_cattools() {
"https://raw.githubusercontent.com/miaoermua/cattools/main/cattools.sh" "https://raw.githubusercontent.com/miaoermua/cattools/main/cattools.sh"
) )
mkdir -p /tmp/cattools
while [ $retries -gt 0 ]; do while [ $retries -gt 0 ]; do
for url in "${urls[@]}"; 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=$? curl_exit_code=$?
if [ $curl_exit_code -eq 0 ]; then if [ $curl_exit_code -eq 0 ] && [ -s "$temp_file" ]; then
if [ -s "$target_file" ]; then
success=true success=true
break 2 break 2
fi fi
fi
done done
echo "Attempt $((4 - retries)) failed. Retrying..." echo "Attempt $((4 - retries)) failed. Retrying..."
@@ -52,10 +53,11 @@ update_cattools() {
if [ "$success" = false ]; then if [ "$success" = false ]; then
echo "Unable to download the latest version, continue to use the current offline version." echo "Unable to download the latest version, continue to use the current offline version."
echo "" echo ""
rm -f "$target_file" rm -f "$temp_file"
return return
fi fi
mv "$temp_file" "$target_file"
chmod +x "$target_file" chmod +x "$target_file"
echo "cattools updated successfully." echo "cattools updated successfully."
echo "" echo ""