#!/bin/bash
# Cargo 镜像配置 - 中科大
# 由 镜像加速站 自动生成

echo "正在配置 Cargo 镜像源..."

# 创建配置目录
mkdir -p ~/.cargo

# 备份原有配置
if [ -f ~/.cargo/config ]; then
    cp ~/.cargo/config ~/.cargo/config.backup.$(date +%Y%m%d)
    echo "✓ 原有配置已备份"
fi

# 写入配置
cat > ~/.cargo/config << 'EOF'
[source.crates-io]
replace-with = 'mirror'

[source.mirror]
registry = "https://mirrors.ustc.edu.cn/crates.io-index/"
EOF

echo "✓ Cargo 镜像源配置已更新"
echo "\n✅ Cargo 镜像源已成功配置为 中科大"
echo "验证: cargo search serde"