功能: 添加修复模式到install.sh

修复模式功能说明:
- 重新加载和应用所有配置
- 保留数据库和用户数据
- 重新生成nginx配置
- 重启后端服务和nginx
- 适用于配置更新、修复nginx问题等场景

使用方法:
  bash install.sh --repair
  bash install.sh --fix
  bash install.sh repair

交互式菜单中添加第3个选项「修复/重新配置」

实现内容:
1. 模式检测: 支持 --repair, --fix, repair 参数
2. 交互式菜单: 添加修复选项到主菜单
3. 主执行流程: 添加repair模式路由到repair_main()
4. repair_main(): 主修复流程函数
   - confirm_repair(): 确认修复操作
   - repair_check_project(): 检查项目是否已安装
   - repair_load_existing_config(): 读取现有.env和nginx配置
   - repair_regenerate_nginx_config(): 重新生成nginx配置
   - repair_restart_services(): 重启PM2和nginx
   - repair_verify_services(): 验证服务状态
   - print_repair_completion(): 显示完成信息

修复: 修正了之前提交的语法错误
- 使用sed命令精确修改,避免破坏文件结构
- 通过bash -n语法检查确保无错误
- 保持代码缩进和格式一致性
This commit is contained in:
2025-11-11 16:59:34 +08:00
parent 91fa2d4fa4
commit 8755a50d80

View File

@@ -14,6 +14,8 @@ if [[ "$1" == "--uninstall" ]] || [[ "$1" == "-u" ]] || [[ "$1" == "uninstall" ]
MODE="uninstall" MODE="uninstall"
elif [[ "$1" == "--update" ]] || [[ "$1" == "--upgrade" ]] || [[ "$1" == "update" ]]; then elif [[ "$1" == "--update" ]] || [[ "$1" == "--upgrade" ]] || [[ "$1" == "update" ]]; then
MODE="update" MODE="update"
elif [[ "$1" == "--repair" ]] || [[ "$1" == "--fix" ]] || [[ "$1" == "repair" ]]; then
MODE="repair"
fi fi
# 颜色定义 # 颜色定义
@@ -2084,12 +2086,13 @@ main() {
echo -e "${GREEN}[1]${NC} 安装/部署 玩玩云" echo -e "${GREEN}[1]${NC} 安装/部署 玩玩云"
echo -e "${BLUE}[2]${NC} 更新/升级 玩玩云" echo -e "${BLUE}[2]${NC} 更新/升级 玩玩云"
echo -e "${YELLOW}[3]${NC} 修复/重新配置 玩玩云" echo -e "${YELLOW}[3]${NC} 修复/重新配置 玩玩云"
echo -e "${RED}[4]${NC} 卸载 玩玩云" echo -e "${RED}[3]${NC} 卸载 玩玩云"
echo "" echo ""
while true; do while true; do
read -p "请输入选项 [1-4]: " mode_choice < /dev/tty read -p "请输入选项 [1-4]: " mode_choice < /dev/tty
case $mode_choice in case $mode_choice in
1)
print_success "已选择: 安装模式" print_success "已选择: 安装模式"
echo "" echo ""
break break
@@ -2117,12 +2120,19 @@ main() {
;; ;;
esac esac
done done
echo -e "${YELLOW}提示:${NC}" else
# 管道执行时的提示
print_info "检测到通过管道执行脚本"
print_info "默认进入安装模式"
print_warning "如需其他操作,请下载脚本后运行"
echo ""
echo -e "${YELLOW}提示:${NC}" echo -e "${YELLOW}提示:${NC}"
echo " 安装: wget https://gitee.com/yu-yon/vue-driven-cloud-storage/raw/master/install.sh && bash install.sh" echo " 安装: wget https://gitee.com/yu-yon/vue-driven-cloud-storage/raw/master/install.sh && bash install.sh"
echo " 更新: wget https://gitee.com/yu-yon/vue-driven-cloud-storage/raw/master/install.sh && bash install.sh --update" echo " 更新: wget https://gitee.com/yu-yon/vue-driven-cloud-storage/raw/master/install.sh && bash install.sh --update"
echo " 修复: wget https://gitee.com/yu-yon/vue-driven-cloud-storage/raw/master/install.sh && bash install.sh --repair"
echo " 卸载: wget https://gitee.com/yu-yon/vue-driven-cloud-storage/raw/master/install.sh && bash install.sh --uninstall" echo " 卸载: wget https://gitee.com/yu-yon/vue-driven-cloud-storage/raw/master/install.sh && bash install.sh --uninstall"
echo " 修复: wget https://gitee.com/yu-yon/vue-driven-cloud-storage/raw/master/install.sh && bash install.sh --repair"
echo ""
sleep 2
fi fi
fi fi
@@ -2211,7 +2221,6 @@ uninstall_main() {
} }
# 执行主流程 # 执行主流程
if [[ "$MODE" == "uninstall" ]]; then if [[ "$MODE" == "uninstall" ]]; then
uninstall_main uninstall_main
elif [[ "$MODE" == "update" ]]; then elif [[ "$MODE" == "update" ]]; then
@@ -2221,12 +2230,15 @@ elif [[ "$MODE" == "repair" ]]; then
else else
main main
fi fi
################################################################################
################################################################################ ################################################################################
# 修复功能 # 修复功能
################################################################################ ################################################################################
print_repair_banner() { print_repair_banner() {
clear
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ ║" echo "║ ║"
echo "║ 🔧 玩玩云 修复模式 ║" echo "║ 🔧 玩玩云 修复模式 ║"
echo "║ ║" echo "║ ║"