From 96a0c4ed99ba7d39be006dda92b40019fa21dfa1 Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Mon, 20 Apr 2026 22:57:35 +0800 Subject: [PATCH] update --- bin/create_config.sh | 4 ++-- bin/update_port.sh | 25 ++++++++++++++++++++++++- install.sh | 10 +++++----- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/bin/create_config.sh b/bin/create_config.sh index 60aeb8c..6b2ebcd 100644 --- a/bin/create_config.sh +++ b/bin/create_config.sh @@ -9,7 +9,7 @@ create_acme_tls_config() { cp "$config_dir/template/tls_cert_config.json" "$config_file" # 设置端口 - update_port + update_port $(find_free_port) # 设置密码 update_password @@ -53,7 +53,7 @@ create_self_tls_config() { cp "$script_dir/../config/template/self_cert_config.json" "$script_dir/../config/config.json" # 设置端口 - update_port + update_port $(find_free_port) # 设置密码 update_password diff --git a/bin/update_port.sh b/bin/update_port.sh index 36c4526..de34ce0 100644 --- a/bin/update_port.sh +++ b/bin/update_port.sh @@ -161,9 +161,32 @@ update_port(){ local config_dir="$script_dir/../config" - local port=$(find_free_port) + local port=$1 + # 如果没有提供端口参数,则自动查找一个随机空闲端口 + if [[ -z "$port" ]]; then + port=$(find_free_port) + fi + modify_json_file "$config_dir/config.json" ".inbounds[0].listen_port" "$port" port_manage allow "$port" echo "设置端口成功" } +# 通过交互方式更新端口 +ask_update_port(){ + local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + local config_file="$script_dir/../config/config.json" + + local current_port=$(get_listen_port) + local new_port=$(ask_update "请输入新的端口号" "$current_port") + update_port "$new_port" +} + + +get_listen_port(){ + local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + local config_file="$script_dir/../config/config.json" + + local port=$(jq -r ".inbounds[0].listen_port" "$config_file") + echo $port +} diff --git a/install.sh b/install.sh index 655b75d..c2bc29b 100644 --- a/install.sh +++ b/install.sh @@ -37,10 +37,10 @@ install(){ } -get_listen_port(){ - local port=$(jq -r ".inbounds[0].listen_port" ./config/config.json) - echo $port -} +# get_listen_port(){ +# local port=$(jq -r ".inbounds[0].listen_port" ./config/config.json) +# echo $port +# } main(){ @@ -88,7 +88,7 @@ main(){ 5) # 修改端口 check_config_file - update_port + ask_update_port port_manage allow $(get_listen_port) # 开放端口 restart_docker ;;