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

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

# 设置环境变量
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/git/homebrew/homebrew-core.git"

# 写入 shell 配置文件
if [ -f ~/.zshrc ]; then
    echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/git/homebrew/brew.git"' >> ~/.zshrc
    echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.zshrc
    echo "✓ 已写入 ~/.zshrc"
elif [ -f ~/.bash_profile ]; then
    echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/git/homebrew/brew.git"' >> ~/.bash_profile
    echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.bash_profile
    echo "✓ 已写入 ~/.bash_profile"
fi

# 更新 Homebrew
brew update

echo "\n✅ Homebrew 镜像源已成功配置为 中科大"
echo "重启终端或执行 source ~/.zshrc 以使配置生效"