From 9d1a13a140043e976cfc6116f3a5450895ebfe63 Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Sun, 11 Jan 2026 11:55:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=20run.sh=20=E4=B8=AD=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=AE=B9=E5=99=A8=E7=8A=B6=E6=80=81=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=9B=E5=9C=A8=20install.sh=20=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=8A=9F=E8=83=BD=E4=BB=A5=E9=AA=8C=E8=AF=81=20JSON?= =?UTF-8?q?=20=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/run.sh | 4 +--- install.sh | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/run.sh b/bin/run.sh index a39107b..1921f8c 100644 --- a/bin/run.sh +++ b/bin/run.sh @@ -24,12 +24,10 @@ run() { bash "$script_dir/create_config.sh" # 创建配置 fi - # 检查容器是否已启动,如果启动则先关闭 + # 如果容器已经启动, 则先停止容器 local compose_file="$script_dir/../docker-compose.yml" if docker-compose -f "$compose_file" ps | grep -q "Up"; then - echo "检测到容器正在运行,正在关闭容器..." docker-compose -f "$compose_file" down - echo "容器已关闭" fi # 启动docker容器 diff --git a/install.sh b/install.sh index 104e299..daf34a9 100644 --- a/install.sh +++ b/install.sh @@ -29,6 +29,25 @@ install(){ fi } + +check_config_file(){ + local script_dir="$(cd "$(dirname "$0")"; pwd)/bin" # 脚本所在目录 + local config_file="$script_dir/../config/config.json" + + # 检查配置文件是否存在 + if [ ! -e "$config_file" ]; then + echo "配置文件不存在, 请先生成配置文件." + exit 1 + fi + + # 检查配置文件是否为有效的JSON格式 + if jq '.' "$config_file" >/dev/null 2>&1; then + echo "有效的JSON文件" + else + echo "无效的JSON文件" + fi +} + main(){ local script_dir="$(cd "$(dirname "$0")"; pwd)/bin" # 脚本所在目录 source "${script_dir}/utils/base.sh" @@ -64,24 +83,26 @@ main(){ ;; 3) # 查看分享链接 + check_config_file bash ./bin/print_share_link.sh ;; 4) # 修改域名 + check_config_file bash ./bin/update_domain.sh ;; 5) # 修改端口 + check_config_file bash ./bin/update_port.sh ;; 6) # 启动容器 - echo "启动容器.." + check_config_file bash ./bin/run.sh ;; 7) # 停止容器 - echo "正在停止容器.." docker-compose -f ./docker-compose.yml down ;; 8)