From 37ccdafc230fa8e0db545f92f44c2dfdb1044713 Mon Sep 17 00:00:00 2001 From: eddy Date: Thu, 2 Jul 2026 03:41:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20NewApi=20=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=84=9A=E6=9C=AC=E4=BB=A5=E6=94=AF=E6=8C=81=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加检测已有安装的功能,避免覆盖数据库路径和配置 - 提供用户选择:仅更新或强制重装 - 强制重装时需确认,防止意外数据丢失 --- install/20-NewApi.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/install/20-NewApi.sh b/install/20-NewApi.sh index a60393c..c7c62db 100644 --- a/install/20-NewApi.sh +++ b/install/20-NewApi.sh @@ -22,14 +22,24 @@ done install_dir=/root/data/docker_data/NewApi update_script="$install_dir/auto-update.sh" -# 交互:选择安装或仅执行 Docker 更新 +# 交互:已有安装时默认只更新,避免覆盖数据库路径、账号数据和密钥 +existing_install=0 +if [ -f "$install_dir/docker-compose.yml" ]; then + existing_install=1 +fi + echo "请选择操作:" -echo " 1) 安装 NewApi(默认)" -echo " 2) 不安装,立即执行 Docker 更新" +if [ "$existing_install" -eq 1 ]; then + echo " 1) 已安装,仅执行 Docker 更新(默认,安全,不覆盖配置/数据库)" + echo " 2) 强制重装 NewApi(危险,会重写 docker-compose.yml)" +else + echo " 1) 安装 NewApi(默认)" + echo " 2) 不安装,立即执行 Docker 更新" +fi read -r -p "请输入选项 [1/2](默认 1):" action_choice action_choice="${action_choice:-1}" -if [ "$action_choice" = "2" ]; then +if { [ "$existing_install" -eq 1 ] && [ "$action_choice" = "1" ]; } || { [ "$existing_install" -eq 0 ] && [ "$action_choice" = "2" ]; }; then echo "已选择:立即执行 Docker 更新。" if [ -x "$update_script" ]; then "$update_script" @@ -54,6 +64,16 @@ if [ "$action_choice" = "2" ]; then exit 0 fi +if [ "$existing_install" -eq 1 ] && [ "$action_choice" = "2" ]; then + echo "检测到已有 NewApi 安装:$install_dir/docker-compose.yml" + echo "强制重装会覆盖 docker-compose.yml,可能导致服务连接到新的空数据库。" + read -r -p "如确需重装,请输入 REINSTALL 确认:" reinstall_confirm + if [ "$reinstall_confirm" != "REINSTALL" ]; then + echo "未确认强制重装,已退出。原有配置未修改。" + exit 0 + fi +fi + # 生成 sed 安全的随机密钥(hex) redis_password=$(openssl rand -hex 16) session_secret=$(openssl rand -hex 24)