移动函数
This commit is contained in:
+21
-21
@@ -1,5 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ==========================================
|
||||
# 更新 sing-box 配置文件中的监听端口,并开放对应防火墙规则
|
||||
# 参数: 端口号(可选,不传则设置一个5000 到 15000的空闲端口)
|
||||
# --- 使用示例 ---
|
||||
# 指定端口
|
||||
# update_port 8080
|
||||
# ==========================================
|
||||
update_port(){
|
||||
local PORT=$1
|
||||
# 如果没有提供端口参数,则自动查找一个随机空闲端口
|
||||
if [[ -z "$PORT" ]]; then
|
||||
PORT=$(find_free_port 5000 15000)
|
||||
fi
|
||||
|
||||
local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
local CONFIG_DIR="$SCRIPT_DIR/../config"
|
||||
modify_json_file "$CONFIG_DIR/config.json" ".inbounds[0].listen_port" "$PORT"
|
||||
port_manage allow "$PORT"
|
||||
echo "设置端口成功"
|
||||
}
|
||||
|
||||
# 查找随机空闲端口
|
||||
# 用途:
|
||||
# 在指定端口范围内,随机选择一个当前未被监听(TCP/UDP)的端口
|
||||
@@ -164,27 +185,6 @@ port_manage() {
|
||||
echo "[OK] SELinux 端口权限已更新 ($ACTION)"
|
||||
}
|
||||
|
||||
# ==========================================
|
||||
# 更新 sing-box 配置文件中的监听端口,并开放对应防火墙规则
|
||||
# 参数: 端口号(可选,不传则设置一个5000 到 15000的空闲端口)
|
||||
# --- 使用示例 ---
|
||||
# 指定端口
|
||||
# update_port 8080
|
||||
# ==========================================
|
||||
update_port(){
|
||||
local PORT=$1
|
||||
# 如果没有提供端口参数,则自动查找一个随机空闲端口
|
||||
if [[ -z "$PORT" ]]; then
|
||||
PORT=$(find_free_port 5000 15000)
|
||||
fi
|
||||
|
||||
local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
local CONFIG_DIR="$SCRIPT_DIR/../config"
|
||||
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)"
|
||||
|
||||
Reference in New Issue
Block a user