Update: Hotupdate
This commit is contained in:
36
cattools.sh
36
cattools.sh
@@ -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"
|
||||||
|
curl_exit_code=$?
|
||||||
|
|
||||||
|
if [ $curl_exit_code -eq 0 ]; then
|
||||||
|
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://mirror.ghproxy.com/https://raw.githubusercontent.com/miaoermua/cattools/main/cattools.sh; then
|
fi
|
||||||
echo "cattools update downloaded from the second URL."
|
fi
|
||||||
success=true
|
done
|
||||||
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..."
|
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 ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user