#!/bin/bash

# 获取版本号输入
read -p "请输入版本号 (例如: 2.2.0)： " version

# 配置下载路径
download_dir="./v${version}"

# 创建下载目录
mkdir -p "$download_dir"

# 设置基础 URL
base_url="https://github.com/clash-verge-rev/clash-verge-rev/releases/download/v${version}"

# 定义需要下载的文件列表
files=(
    "Clash.Verge-${version}-1.aarch64.rpm"
    "Clash.Verge-${version}-1.armhfp.rpm"
    "Clash.Verge-${version}-1.x86_64.rpm"
    "Clash.Verge_${version}_aarch64.dmg"
    "Clash.Verge_${version}_amd64.deb"
    "Clash.Verge_${version}_arm64-setup.exe"
    "Clash.Verge_${version}_arm64.deb"
    "Clash.Verge_${version}_arm64_fixed_webview2-setup.exe"
    "Clash.Verge_${version}_armhf.deb"
    "Clash.Verge_${version}_x64-setup.exe"
    "Clash.Verge_${version}_x64.dmg"
    "Clash.Verge_${version}_x64_fixed_webview2-setup.exe"
    "Clash.Verge_aarch64.app.tar.gz"
    "Clash.Verge_x64.app.tar.gz"
    "Clash.Verge_${version}.zip"
    "Clash.Verge_${version}.tar.gz"
)

# 允许用户选择下载工具（默认 wget）
read -p "请选择下载方式 [1] wget (默认) [2] aria2c 并行下载: " choice
choice=${choice:-1}

echo "开始下载 Clash Verge 版本 ${version}..."

if [[ "$choice" == "2" ]]; then
    # 并行下载（使用 aria2c）
    aria2c -d "$download_dir" -i <(printf "${base_url}/%s\n" "${files[@]}")
else
    # 逐个下载（使用 wget）
    for file in "${files[@]}"; do
        wget -c -O "${download_dir}/${file}" "${base_url}/${file}"
    done
fi

echo "下载完成，所有文件保存在 ${download_dir} 目录中。"
