#!/bin/bash
# Maven 镜像配置 - 阿里云
# 由 镜像加速站 自动生成

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

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

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

# 写入新配置
cat > ~/.m2/settings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
          http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <id>阿里云</id>
      <name>阿里云 Maven Mirror</name>
      <url>https://maven.aliyun.com/repository/public</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
</settings>
EOF

echo "✓ Maven 镜像源配置已更新"
echo "\n✅ Maven 镜像源已成功配置为 阿里云"
echo "如需恢复原有配置，执行: mv ~/.m2/settings.xml.backup.* ~/.m2/settings.xml"