diff --git a/script/clashctl.sh b/script/clashctl.sh index 6d5f148..c06ad29 100644 --- a/script/clashctl.sh +++ b/script/clashctl.sh @@ -2,7 +2,7 @@ # shellcheck disable=SC2155 function clashon() { - _get_kernel_port + _get_proxy_port sudo systemctl start "$BIN_KERNEL_NAME" && _okcat '已开启代理环境' || _failcat '启动失败: 执行 "clashstatus" 查看日志' || return 1 @@ -56,7 +56,7 @@ function clashstatus() { function clashui() { # 防止tun模式强制走代理获取不到真实公网ip clashoff >&/dev/null - _get_kernel_port + _get_ui_port # 公网ip # ifconfig.me local query_url='api64.ipify.org' diff --git a/script/common.sh b/script/common.sh index 0473758..dea19a4 100644 --- a/script/common.sh +++ b/script/common.sh @@ -119,15 +119,10 @@ _get_random_port() { _get_random_port } -function _get_kernel_port() { +function _get_proxy_port() { local mixed_port=$(sudo "$BIN_YQ" '.mixed-port // ""' $CLASH_CONFIG_RUNTIME) - local ext_addr=$(sudo "$BIN_YQ" '.external-controller // ""' $CLASH_CONFIG_RUNTIME) - local ext_port=${ext_addr##*:} - MIXED_PORT=${mixed_port:-7890} - UI_PORT=${ext_port:-9090} - # 端口占用场景 _is_already_in_use "$MIXED_PORT" "$BIN_KERNEL_NAME" && { local newPort=$(_get_random_port) local msg="端口占用:${MIXED_PORT} 🎲 随机分配:$newPort" @@ -135,6 +130,13 @@ function _get_kernel_port() { MIXED_PORT=$newPort _failcat '🎯' "$msg" } +} + +function _get_ui_port() { + local ext_addr=$(sudo "$BIN_YQ" '.external-controller // ""' $CLASH_CONFIG_RUNTIME) + local ext_port=${ext_addr##*:} + UI_PORT=${ext_port:-9090} + _is_already_in_use "$UI_PORT" "$BIN_KERNEL_NAME" && { local newPort=$(_get_random_port) local msg="端口占用:${UI_PORT} 🎲 随机分配:$newPort"