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)