更新 OpenWrt/upload.sh
Signed-off-by: zhao <zhao@noreply.localhost>
This commit is contained in:
parent
9540a78779
commit
f5e57d9def
@ -7,43 +7,65 @@ REPO="oppen321/ZeroWrt-Action"
|
|||||||
# 1. 下载GitHub Release文件
|
# 1. 下载GitHub Release文件
|
||||||
echo "➜ 下载GitHub Release文件..."
|
echo "➜ 下载GitHub Release文件..."
|
||||||
|
|
||||||
|
# 检查model参数是否有效
|
||||||
|
if [ "$model" != "x86_64" ] && [ "$model" != "rockchip" ]; then
|
||||||
|
echo "❌ 未指定有效的model参数 (x86_64 或 rockchip)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# 根据架构选择对应的tag
|
# 根据架构选择对应的tag
|
||||||
if [ "$model" = "x86_64" ]; then
|
if [ "$model" = "x86_64" ]; then
|
||||||
TAG="OpenWrt-X86_64-24.10"
|
TAG="OpenWrt-X86_64-24.10"
|
||||||
elif [ "$model" = "rockchip" ]; then
|
|
||||||
TAG="OpenWrt-Rockchip-24.10"
|
|
||||||
else
|
else
|
||||||
echo "❌ 未指定有效的model参数 (x86_64 或 rockchip)"
|
TAG="OpenWrt-Rockchip-24.10"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 获取release的assets
|
# 获取release的assets
|
||||||
RELEASE_URL="https://api.github.com/repos/${REPO}/releases/tags/${TAG}"
|
RELEASE_URL="https://api.github.com/repos/${REPO}/releases/tags/${TAG}"
|
||||||
|
|
||||||
# 添加GitHub API认证(如果是私有仓库或避免限流)
|
# 添加GitHub API认证头(推荐使用)
|
||||||
# TOKEN="your_github_token"
|
HEADERS=(
|
||||||
# HEADERS=(-H "Authorization: token ${TOKEN}")
|
-H "Accept: application/vnd.github.v3+json"
|
||||||
|
-H "Authorization: token ${GITHUB_TOKEN:-}" # 使用环境变量中的token
|
||||||
|
)
|
||||||
|
|
||||||
# 获取assets下载链接
|
# 获取assets下载链接
|
||||||
ASSETS=$(curl -sSL "${HEADERS[@]}" "$RELEASE_URL" | jq -r '.assets[]?.browser_download_url')
|
echo "正在获取发布资源..."
|
||||||
|
ASSETS=$(curl -sSL "${HEADERS[@]}" "$RELEASE_URL" | jq -r '.assets[]?.browser_download_url' 2>/dev/null)
|
||||||
|
|
||||||
if [ -z "$ASSETS" ]; then
|
if [ -z "$ASSETS" ]; then
|
||||||
echo "❌ 未找到对应release的assets文件,可能原因:"
|
echo "❌ 未找到对应release的assets文件,可能原因:"
|
||||||
echo " - tag名称不正确: ${TAG}"
|
echo " - tag名称不正确: ${TAG}"
|
||||||
echo " - 仓库中没有该tag的release"
|
echo " - 仓库中没有该tag的release"
|
||||||
echo " - API请求被限制(尝试添加GitHub token)"
|
echo " - API请求被限制(尝试添加GitHub token)"
|
||||||
|
echo " - jq解析失败,请确保已安装jq"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p ./downloads
|
# 创建下载目录
|
||||||
cd ./downloads || exit 1
|
DOWNLOAD_DIR="./downloads"
|
||||||
|
mkdir -p "$DOWNLOAD_DIR"
|
||||||
|
cd "$DOWNLOAD_DIR" || exit 1
|
||||||
|
|
||||||
|
# 下载所有assets
|
||||||
|
echo "开始下载文件..."
|
||||||
for url in $ASSETS; do
|
for url in $ASSETS; do
|
||||||
echo "正在下载: $(basename "$url")"
|
filename=$(basename "$url")
|
||||||
wget -q --show-progress "$url"
|
echo "正在下载: $filename"
|
||||||
|
if ! wget -q --show-progress "$url"; then
|
||||||
|
echo "⚠️ 下载失败: $filename"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# 重命名文件
|
# 重命名文件(更安全的实现)
|
||||||
rename 's/^openwrt/zerowrt-plus-$date/' openwrt*
|
echo "重命名文件..."
|
||||||
|
for file in openwrt*; do
|
||||||
|
if [ -e "$file" ]; then
|
||||||
|
newname="zerowrt-plus-${DATE}${file#openwrt}"
|
||||||
|
echo "重命名: $file → $newname"
|
||||||
|
mv -- "$file" "$newname"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo "✅ 下载和重命名完成"
|
echo "✅ 下载和重命名完成"
|
Loading…
Reference in New Issue
Block a user