#!/bin/bash # 获取脚本所在目录的绝对路径 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 切换到脚本目录 cd "$SCRIPT_DIR" || exit echo "==========================================" echo "开始下载 GeoData 文件到:" echo "$SCRIPT_DIR" echo "==========================================" # 直接定义完整的 URL,避免解析出错 GEOIP_URL="https://cdn.jsdmirror.com/gh/MetaCubeX/meta-rules-dat@release/geoip.dat" GEOSITE_URL="https://cdn.jsdmirror.com/gh/MetaCubeX/meta-rules-dat@release/geosite.dat" METADB_URL="https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb" # 下载函数 download_file() { local url="$1" local output="$2" local name="$3" # 检查文件是否已存在 if [ -f "$output" ]; then echo "" echo "⏭️ $name 已存在,跳过下载" return 0 fi echo "" echo "正在下载: $name" echo "来源: $url" if curl -L -f -# -o "$output" "$url"; then if command -v du &>/dev/null; then SIZE=$(du -h "$output" | cut -f1) echo "✅ 下载成功: $name (大小: $SIZE)" else echo "✅ 下载成功: $name" fi return 0 else echo "❌ 下载失败: $name" return 1 fi } # 依次下载三个文件 download_file "$GEOIP_URL" "$SCRIPT_DIR/geoip.dat" "geoip.dat" if [ $? -ne 0 ]; then exit 1; fi download_file "$GEOSITE_URL" "$SCRIPT_DIR/geosite.dat" "geosite.dat" if [ $? -ne 0 ]; then exit 1; fi download_file "$METADB_URL" "$SCRIPT_DIR/geoip.metadb" "geoip.metadb" if [ $? -ne 0 ]; then exit 1; fi echo "" echo "==========================================" echo "✅ 所有文件下载完成!" echo "" echo "📁 文件位置: $SCRIPT_DIR" echo "" echo "📝 后续操作:" echo " 请在 config.yaml 中注释掉所有 geox-url 配置" echo "=========================================="