带v不带v

This commit is contained in:
2025-12-03 21:35:38 +08:00
parent e5fa9429ae
commit 904bc54248

View File

@@ -700,14 +700,6 @@ download_binary_from_releases() {
echo -e "${BLUE} 发布日期: ${latest_created_at}${NC}" echo -e "${BLUE} 发布日期: ${latest_created_at}${NC}"
fi fi
# 构建文件名(根据系统类型)
local file_name="agent-${OS_TYPE}-${ARCH}-${latest_tag}"
local file_ext="tar.gz"
if [ "$OS_TYPE" = "windows" ]; then
file_ext="zip"
fi
local full_file_name="${file_name}.${file_ext}"
# 获取 release 的详细信息(包含 commit hash # 获取 release 的详细信息(包含 commit hash
local release_detail=$(curl -s -X GET "${repo_api}/releases/${latest_release_id}" 2>/dev/null) local release_detail=$(curl -s -X GET "${repo_api}/releases/${latest_release_id}" 2>/dev/null)
@@ -728,14 +720,56 @@ download_binary_from_releases() {
fi fi
fi fi
# 如果还是无法获取 commit hash使用 assets_response 继续(不强制要求 commit # 构建文件名(根据系统类型
local assets_response="$release_detail" # 处理 tag 可能带 v 前缀的情况(如 v1.0.0
local version_in_filename="${latest_tag}"
# 查找匹配的二进制文件 # 如果 tag 以 v 开头,同时尝试带 v 和不带 v 的文件
local download_url=$(echo "$assets_response" | grep -o "\"browser_download_url\":\"[^\"]*${full_file_name}[^\"]*\"" | head -1 | cut -d'"' -f4) local file_ext="tar.gz"
if [ "$OS_TYPE" = "windows" ]; then
file_ext="zip"
fi
if [ -z "$download_url" ]; then # 先尝试使用 tag 的原始格式(可能带 v
echo -e "${YELLOW}⚠ 未找到匹配的二进制文件: ${full_file_name}${NC}" local file_name_with_v="agent-${OS_TYPE}-${ARCH}-${latest_tag}"
local full_file_name_with_v="${file_name_with_v}.${file_ext}"
# 如果 tag 以 v 开头,也尝试不带 v 的版本
local file_name_without_v=""
local full_file_name_without_v=""
if [ "${latest_tag#v}" != "${latest_tag}" ]; then
# tag 以 v 开头,去掉 v 前缀
version_in_filename="${latest_tag#v}"
file_name_without_v="agent-${OS_TYPE}-${ARCH}-${version_in_filename}"
full_file_name_without_v="${file_name_without_v}.${file_ext}"
fi
# 查找匹配的二进制文件(优先尝试带 v 的,如果找不到再尝试不带 v 的)
local download_url=""
local full_file_name=""
# 先尝试带 v 的文件名
download_url=$(echo "$release_detail" | grep -o "\"browser_download_url\":\"[^\"]*${full_file_name_with_v}[^\"]*\"" | head -1 | cut -d'"' -f4)
if [ -n "$download_url" ]; then
full_file_name="$full_file_name_with_v"
echo -e "${BLUE}找到文件: ${full_file_name}${NC}"
elif [ -n "$full_file_name_without_v" ]; then
# 如果带 v 的找不到,尝试不带 v 的
download_url=$(echo "$release_detail" | grep -o "\"browser_download_url\":\"[^\"]*${full_file_name_without_v}[^\"]*\"" | head -1 | cut -d'"' -f4)
if [ -n "$download_url" ]; then
full_file_name="$full_file_name_without_v"
echo -e "${BLUE}找到文件: ${full_file_name} (tag: ${latest_tag})${NC}"
fi
fi
if [ -z "$download_url" ] || [ -z "$full_file_name" ]; then
echo -e "${YELLOW}⚠ 未找到匹配的二进制文件${NC}"
echo -e "${YELLOW} 尝试的文件名:${NC}"
echo -e "${YELLOW} - ${full_file_name_with_v}${NC}"
if [ -n "$full_file_name_without_v" ]; then
echo -e "${YELLOW} - ${full_file_name_without_v}${NC}"
fi
echo -e "${YELLOW} 将使用源码编译${NC}" echo -e "${YELLOW} 将使用源码编译${NC}"
return 1 return 1
fi fi