Skip to content

Commit 575a3c4

Browse files
authored
fix
1 parent f6778fe commit 575a3c4

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

webvirtcompute/scripts/update.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,33 @@ if [[ -z $DISTRO_NAME ]]; then
2323
exit 1
2424
fi
2525

26+
check_cdn() {
27+
local o_url=$1
28+
local shuffled_cdn_urls=($(shuf -e "${cdn_urls[@]}")) # 打乱数组顺序
29+
for cdn_url in "${shuffled_cdn_urls[@]}"; do
30+
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" >/dev/null 2>&1; then
31+
export cdn_success_url="$cdn_url"
32+
return
33+
fi
34+
sleep 0.5
35+
done
36+
export cdn_success_url=""
37+
}
38+
39+
check_cdn_file() {
40+
check_cdn "https://raw.githubusercontent.com/spiritLHLS/ecs/main/back/test"
41+
if [ -n "$cdn_success_url" ]; then
42+
echo "CDN available, using CDN"
43+
else
44+
echo "No CDN available, no use CDN"
45+
fi
46+
}
47+
2648
# Update webvirtcompute
2749
echo -e "\nUpdating webvirtcompute..."
28-
wget -O /tmp/webvirtcompute-$DISTRO_NAME$DISTRO_VERSION-amd64.tar.gz https://github.com/oneclickvirt/webvirtcloud/releases/download/webvirtcloud_dep/webvirtcompute-$DISTRO_NAME$DISTRO_VERSION-amd64.tar.gz
50+
cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/" "http://cdn3.spiritlhl.net/" "http://cdn4.spiritlhl.net/")
51+
check_cdn_file
52+
wget -O /tmp/webvirtcompute-$DISTRO_NAME$DISTRO_VERSION-amd64.tar.gz "${cdn_success_url}https://github.com/oneclickvirt/webvirtcloud/releases/download/webvirtcloud_dep/webvirtcompute-$DISTRO_NAME$DISTRO_VERSION-amd64.tar.gz"
2953
tar -xvf /tmp/webvirtcompute-$DISTRO_NAME$DISTRO_VERSION-amd64.tar.gz -C /tmp
3054
systemctl stop webvirtcompute
3155
cp /tmp/webvirtcompute/webvirtcompute /usr/local/bin/webvirtcompute

0 commit comments

Comments
 (0)