修改"设置端口方式"
This commit is contained in:
@@ -16,7 +16,7 @@ create_reality_config(){
|
|||||||
update_key
|
update_key
|
||||||
|
|
||||||
# 设置端口
|
# 设置端口
|
||||||
update_port
|
update_port 443
|
||||||
|
|
||||||
# 设置reality_dest目标域名
|
# 设置reality_dest目标域名
|
||||||
update_reality_dest
|
update_reality_dest
|
||||||
@@ -46,7 +46,7 @@ create_xhttp_reality_config(){
|
|||||||
update_reality_dest
|
update_reality_dest
|
||||||
|
|
||||||
# 设置端口
|
# 设置端口
|
||||||
update_port
|
update_port 443
|
||||||
|
|
||||||
green "成功创建配置"
|
green "成功创建配置"
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -78,7 +78,20 @@ update_port(){
|
|||||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹路径
|
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹路径
|
||||||
local config_file="$script_dir/../conf/config.json"
|
local config_file="$script_dir/../conf/config.json"
|
||||||
|
|
||||||
local port=$(find_free_port)
|
local port=$1
|
||||||
|
# 如果参数为空,则设置为443
|
||||||
|
if [ -z "$port" ]; then
|
||||||
|
port=443
|
||||||
|
fi
|
||||||
modify_json_file "$config_file" ".inbounds[0].port" "$port"
|
modify_json_file "$config_file" ".inbounds[0].port" "$port"
|
||||||
echo "设置端口成功"
|
echo "设置端口成功"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ask_update_port(){
|
||||||
|
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹路径
|
||||||
|
local config_file="$script_dir/../conf/config.json"
|
||||||
|
|
||||||
|
local current_port=$(jq -r '.inbounds[0].port' $config_dir/config.json)
|
||||||
|
local new_port=ask_update "请输入新的端口号" "$current_port"
|
||||||
|
update_port $new_port
|
||||||
|
}
|
||||||
|
|||||||
@@ -135,3 +135,19 @@ restart_docker() {
|
|||||||
docker-compose -f $script_dir/../docker-compose.yml down
|
docker-compose -f $script_dir/../docker-compose.yml down
|
||||||
docker-compose -f $script_dir/../docker-compose.yml up -d
|
docker-compose -f $script_dir/../docker-compose.yml up -d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 通用:展示当前值并询问新值
|
||||||
|
# 用法: ask_update "提示语" "当前值(当前配置文件的值)"
|
||||||
|
# 示例:
|
||||||
|
# new_port=$(ask_update "请输入新的端口号" "$(jq -r '.inbounds[0].port' $config_dir/config.json)")
|
||||||
|
ask_update() {
|
||||||
|
local prompt="$1" # 提示语
|
||||||
|
local current_value="$2"
|
||||||
|
local input
|
||||||
|
|
||||||
|
read -p "${prompt} [当前: ${current_value}]: " input
|
||||||
|
# 用户直接回车则保留当前值,否则使用新输入
|
||||||
|
echo "${input:-$current_value}"
|
||||||
|
}
|
||||||
+1
-1
@@ -101,7 +101,7 @@ main(){
|
|||||||
7)
|
7)
|
||||||
# 修改端口
|
# 修改端口
|
||||||
check_config
|
check_config
|
||||||
update_port
|
ask_update_port
|
||||||
restart_docker
|
restart_docker
|
||||||
;;
|
;;
|
||||||
8)
|
8)
|
||||||
|
|||||||
Reference in New Issue
Block a user