From a7aca93355f1d0f79903101caf4a333350fc53b8 Mon Sep 17 00:00:00 2001 From: WanWanYun Date: Thu, 13 Nov 2025 01:46:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ssl=5Ffallback=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E6=8E=92=E9=99=A4=E5=B7=B2=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题描述: - 用户选择方案2失败后,fallback还推荐方案2 - 用户再次选择方案2,还是会失败 - 浪费时间,用户体验差 修复方案: - ssl_fallback函数接收失败的方案编号作为参数 - 动态生成可用选项,排除已失败的方案 - 显示提示:方案X已失败,已从列表中移除 - 如果备选方案再次失败,递归调用fallback并排除 改进内容: 1. ssl_fallback($failed_method) - 接收方案编号 2. 动态显示可用选项(排除失败方案) 3. 输入验证:只接受可用选项 4. 递归调用:如果备选方案也失败,继续排除 方案编号映射: - 1: Certbot - 2: acme.sh + Let's Encrypt - 3: acme.sh + ZeroSSL - 4: acme.sh + Buypass - 5: 阿里云(未实现) - 6: 腾讯云(未实现) - 8: 不配置HTTPS 用户体验改进: - 避免重复尝试失败的方案 - 清晰提示哪个方案已失败 - 自动缩小选择范围 - 节省用户时间 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- install.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 604e600..3eb8e57 100644 --- a/install.sh +++ b/install.sh @@ -1134,22 +1134,22 @@ deploy_ssl() { case $SSL_METHOD in 1) - deploy_certbot || ssl_fallback + deploy_certbot || ssl_fallback "1" ;; 2) - deploy_acme_letsencrypt || ssl_fallback + deploy_acme_letsencrypt || ssl_fallback "2" ;; 3) - deploy_acme_zerossl || ssl_fallback + deploy_acme_zerossl || ssl_fallback "3" ;; 4) - deploy_acme_buypass || ssl_fallback + deploy_acme_buypass || ssl_fallback "4" ;; 5) - deploy_aliyun_ssl || ssl_fallback + deploy_aliyun_ssl || ssl_fallback "5" ;; 6) - deploy_tencent_ssl || ssl_fallback + deploy_tencent_ssl || ssl_fallback "6" ;; 7) deploy_manual_ssl @@ -1162,35 +1162,97 @@ deploy_ssl() { } ssl_fallback() { + local failed_method=$1 # 接收失败的方案编号 + print_error "SSL证书部署失败" echo "" print_warning "建议尝试备选方案:" - echo -e "${GREEN}[2]${NC} acme.sh + Let's Encrypt (推荐)" - echo -e "${GREEN}[3]${NC} acme.sh + ZeroSSL" - echo -e "${GREEN}[4]${NC} acme.sh + Buypass" + echo "" + + # 动态显示可用选项(排除已失败的) + local available_options=() + + # 方案1: Certbot + if [[ "$failed_method" != "1" ]]; then + echo -e "${GREEN}[1]${NC} Certbot (Let's Encrypt官方工具)" + available_options+=("1") + fi + + # 方案2: acme.sh + Let's Encrypt + if [[ "$failed_method" != "2" ]]; then + echo -e "${GREEN}[2]${NC} acme.sh + Let's Encrypt" + available_options+=("2") + fi + + # 方案3: acme.sh + ZeroSSL + if [[ "$failed_method" != "3" ]]; then + echo -e "${GREEN}[3]${NC} acme.sh + ZeroSSL" + available_options+=("3") + fi + + # 方案4: acme.sh + Buypass + if [[ "$failed_method" != "4" ]]; then + echo -e "${GREEN}[4]${NC} acme.sh + Buypass" + available_options+=("4") + fi + + # 方案5: 阿里云(注释掉,未实现) + # if [[ "$failed_method" != "5" ]]; then + # echo -e "${GREEN}[5]${NC} 阿里云免费证书" + # available_options+=("5") + # fi + + # 方案6: 腾讯云(注释掉,未实现) + # if [[ "$failed_method" != "6" ]]; then + # echo -e "${GREEN}[6]${NC} 腾讯云免费证书" + # available_options+=("6") + # fi + + # 方案8: 不配置HTTPS echo -e "${GREEN}[8]${NC} 暂不配置HTTPS" + available_options+=("8") + + echo "" + echo -e "${YELLOW}提示: 方案 $failed_method 已失败,已从列表中移除${NC}" echo "" while true; do - read -p "请选择备选方案 [2-4/8]: " retry_choice < /dev/tty + read -p "请选择备选方案: " retry_choice < /dev/tty + + # 检查输入是否在可用选项中 + if [[ ! " ${available_options[@]} " =~ " ${retry_choice} " ]]; then + print_error "无效选项或该方案已失败" + continue + fi + case $retry_choice in + 1) + deploy_certbot && return 0 + # 如果再次失败,继续调用fallback但排除方案1 + ssl_fallback "1" + return $? + ;; 2) deploy_acme_letsencrypt && return 0 + # 如果再次失败,继续调用fallback但排除方案2 + ssl_fallback "2" + return $? ;; 3) deploy_acme_zerossl && return 0 + ssl_fallback "3" + return $? ;; 4) deploy_acme_buypass && return 0 + ssl_fallback "4" + return $? ;; 8) print_info "跳过HTTPS配置" SSL_METHOD=8 return 0 ;; - *) - print_error "无效选项" - ;; esac done }