Update: Hotupdate

This commit is contained in:
喵二
2024-07-31 11:39:23 +08:00
committed by GitHub
parent 8d0ee8a200
commit d59de920eb

View File

@@ -23,38 +23,40 @@ fi
# Update # Update
update_cattools() { update_cattools() {
echo "Please wait for the script to be updated." echo "Please wait for the script to be updated."
local temp_file=$(mktemp) local target_file="/usr/bin/cattools"
local retries=3 local retries=3
local success=false 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 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 for url in "${urls[@]}"; do
echo "cattools update downloaded from the first URL." curl --silent --connect-timeout 3 --max-time 5 -o "$target_file" "$url"
success=true curl_exit_code=$?
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 if [ $curl_exit_code -eq 0 ]; then
echo "cattools update downloaded from the second URL." if [ -s "$target_file" ]; then
success=true success=true
break break 2
elif curl --silent --connect-timeout 3 --max-time 5 -o "$temp_file" https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/cattools.sh; then fi
echo "cattools update downloaded from the third URL." fi
success=true done
break
else echo "Attempt $((4 - retries)) failed. Retrying..."
echo "Attempt $((4 - retries)) failed. Retrying..." retries=$((retries - 1))
retries=$((retries - 1))
fi
done done
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 "$temp_file" rm -f "$target_file"
return return
fi fi
mv "$temp_file" /usr/bin/cattools chmod +x "$target_file"
chmod +x /usr/bin/cattools
echo "cattools updated successfully." echo "cattools updated successfully."
echo "" echo ""
} }