From 9a3e20082c5deb36f9077977b3aac15f38343811 Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Sun, 23 Nov 2025 14:15:50 +0800 Subject: [PATCH] refactor: reorganize menu options and add config validation checks - Extracted common config file validation into a new `check_config` function - Renumbered menu options for logical order, with exit as the last option - Added config checks before viewing share links, updating port, and changing Reality destination - Removed trailing backslash and added final newline for proper formatting This update improves code reusability, prevents errors from missing configs, and enhances menu usability. --- install.sh | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/install.sh b/install.sh index f4ad387..45a77c7 100644 --- a/install.sh +++ b/install.sh @@ -7,13 +7,18 @@ restart_docker(){ } -change_reality_dest(){ - local config_dir="./conf" - +check_config(){ if [ ! -e "$config_dir/config.json" ] || [ ! -s "$config_dir/config.json" ];then echo "请先'创建配置'" exit 0 fi +} + + +change_reality_dest(){ + local config_dir="./conf" + + check_config source ./bin/utils/jq_util.sh @@ -34,54 +39,57 @@ change_reality_dest(){ main(){ # 显示菜单 echo "请选择一个操作:" - echo "0. 创建配置 / 重置配置" - echo "1. 启动容器" - echo "2. 查看分享链接" - echo "3. 停止容器" - echo "4. 更新镜像" - echo "5. 修改端口" - echo "6. 修改Reality目标域名" - echo "0. 退出" + echo "1. 创建配置 / 重置配置" + echo "2. 启动容器" + echo "3. 查看分享链接" + echo "4. 停止容器" + echo "5. 更新镜像" + echo "6. 修改端口" + echo "7. 修改Reality目标域名" + echo "8. 退出" # 读取用户选择 read -p "输入您的选择: " choice # 根据用户选择执行相应的操作 case $choice in - 0) + 1) # 创建配置 / 重置配置 bash ./bin/create_config.sh ;; - 1) + 2) # 启动容器 echo "启动容器.." bash ./bin/run.sh ;; - 2) + 3) # 查看分享链接 echo "查看分享链接.." + check_config bash ./bin/print_share_link.sh ;; - 3) + 4) # 停止容器 echo "正在停止容器.." docker-compose -f ./docker-compose.yml down ;; - 4) + 5) # 更新镜像 bash ./bin/update_docker_images.sh ;; - 5) + 6) # 修改端口 + check_config bash ./bin/update_port.sh restart_docker ;; - 6) + 7) # 修改Reality目标域名 + check_config change_reality_dest restart_docker ;; - 0) + 8) # 退出 echo "退出程序." ;; @@ -91,4 +99,4 @@ main(){ esac } -main \ No newline at end of file +main