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

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

# 设置环境变量
export PUB_HOSTED_URL="https://mirrors.aliyun.com/dart-pub"
export FLUTTER_STORAGE_BASE_URL="https://mirrors.aliyun.com/flutter"

# 写入 shell 配置文件
SHELL_CONFIG=""
if [ -f ~/.zshrc ]; then
    SHELL_CONFIG=~/.zshrc
elif [ -f ~/.bash_profile ]; then
    SHELL_CONFIG=~/.bash_profile
elif [ -f ~/.bashrc ]; then
    SHELL_CONFIG=~/.bashrc
fi

if [ -n "$SHELL_CONFIG" ]; then
    echo "" >> $SHELL_CONFIG
    echo "# Flutter 镜像源 - 阿里云" >> $SHELL_CONFIG
    echo 'export PUB_HOSTED_URL="https://mirrors.aliyun.com/dart-pub"' >> $SHELL_CONFIG
    echo 'export FLUTTER_STORAGE_BASE_URL="https://mirrors.aliyun.com/flutter"' >> $SHELL_CONFIG
    echo "✓ 已写入 $SHELL_CONFIG"
fi

echo "\n✅ Flutter 镜像源已成功配置为 阿里云"
echo "重启终端或执行 source $SHELL_CONFIG 使配置生效"
echo "验证: flutter doctor"