diff --git a/install.sh b/install.sh index 58f05e8..b00149c 100755 --- a/install.sh +++ b/install.sh @@ -59,8 +59,61 @@ install_xcode_tools() { else print_message "📥 安装 Xcode Command Line Tools..." "$YELLOW" xcode-select --install - print_message "⏳ 请在弹出的窗口中完成安装,然后重新运行此脚本" "$YELLOW" - exit 0 + + # 检测是否为交互式执行 + if [[ -t 0 ]]; then + # 交互式执行 - 等待用户确认 + print_message "⏳ Xcode Command Line Tools 安装进行中..." "$YELLOW" + print_message " 1. 请在弹出的对话框中点击 '安装'" "$YELLOW" + print_message " 2. 等待安装完成(通常需要几分钟)" "$YELLOW" + print_message " 3. 安装完成后按回车键继续..." "$YELLOW" + echo "" + + # 等待用户确认安装完成 + read -p "⚡ 安装完成后请按回车键继续..." -r + echo "" + else + # 非交互式执行 - 自动等待 + print_message "⏳ 等待 Xcode Command Line Tools 安装完成..." "$YELLOW" + print_message " 正在自动检测安装状态..." "$YELLOW" + + # 自动等待安装完成(最多等待10分钟) + local wait_count=0 + while [[ $wait_count -lt 120 ]]; do + if xcode-select -p &>/dev/null; then + print_message "✅ Xcode Command Line Tools 安装完成!" "$GREEN" + return 0 + fi + sleep 5 + ((wait_count++)) + if [[ $((wait_count % 12)) -eq 0 ]]; then + print_message " 仍在等待安装完成... ($((wait_count * 5 / 60))分钟)" "$YELLOW" + fi + done + + print_message "❌ Xcode Command Line Tools 安装超时" "$RED" + print_message " 请手动完成安装后重新运行脚本" "$RED" + exit 1 + fi + + # 再次验证安装是否成功 + local retry_count=0 + while [[ $retry_count -lt 3 ]]; do + if xcode-select -p &>/dev/null; then + print_message "✅ Xcode Command Line Tools 安装成功!" "$GREEN" + return 0 + else + print_message "⚠️ 检测到 Xcode Command Line Tools 尚未安装完成" "$YELLOW" + read -p " 请等待安装完成后按回车键重试... " -r + echo "" + ((retry_count++)) + fi + done + + # 如果多次重试仍未成功,提示用户 + print_message "❌ Xcode Command Line Tools 安装验证失败" "$RED" + print_message " 请确保安装已完成,或手动验证:xcode-select -p" "$RED" + exit 1 fi }