fix: refresh stale cellular source IP and resolve cpxy symlink BASE

WWAN re-dial often keeps iface name (wwan0) but changes private IP.
Stale inet4_bind_address then makes SOCKS rep=0x01 while the panel still
looks healthy. generate/cpxy now re-read live source IP on each regenerate.

Also fix /usr/local/bin/cpxy symlink: dirname($0) became /usr/local and
broke rebind/generate (missing lib.sh).
This commit is contained in:
Hermes Agent
2026-07-23 08:53:37 +00:00
parent b2a7332f86
commit 062a3eee90
3 changed files with 54 additions and 8 deletions
+18 -2
View File
@@ -201,7 +201,16 @@ info "配置已确认 bind_interface=$cell"
install -m 0755 /dev/stdin "$INSTALL_DIR/bin/cpxy" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
BASE="$(cd "$(dirname "$0")/.." && pwd)"
# 经 /usr/local/bin/cpxy 符号链接调用时,$0 仍是链接路径;必须 resolve 真实路径
_self="${BASH_SOURCE[0]:-$0}"
if command -v readlink >/dev/null 2>&1; then
_resolved="$(readlink -f "$_self" 2>/dev/null || true)"
[[ -n "$_resolved" ]] && _self="$_resolved"
fi
BASE="$(cd "$(dirname "$_self")/.." && pwd)"
if [[ ! -d "$BASE/scripts" && -d /opt/cellular-proxy/scripts ]]; then
BASE="/opt/cellular-proxy"
fi
export CONFIG_FILE="${CONFIG_FILE:-$BASE/etc/settings.conf}"
cmd="${1:-help}"
shift || true
@@ -217,6 +226,13 @@ case "$cmd" in
src="$(detect_source_ip "$cell" || true)"
persist_cellular_to_settings "$CONFIG_FILE" "$cell" "$src"
CELLULAR_IFACE="$cell"
CELLULAR_SOURCE_IP="${src:-}"
fi
elif [[ -n "${CELLULAR_IFACE:-}" ]]; then
src="$(detect_source_ip "$CELLULAR_IFACE" || true)"
if [[ -n "$src" && "${CELLULAR_SOURCE_IP:-}" != "$src" ]]; then
persist_cellular_to_settings "$CONFIG_FILE" "$CELLULAR_IFACE" "$src"
CELLULAR_SOURCE_IP="$src"
fi
fi
"$BASE/scripts/generate.sh" "$BASE/generated"
@@ -235,7 +251,7 @@ case "$cmd" in
[[ -n "$cell" ]] || die "未能探测数据网卡"
src="$(detect_source_ip "$cell" || true)"
persist_cellular_to_settings "$CONFIG_FILE" "$cell" "$src"
info "已重新绑定 $cell"
info "已重新绑定 $cell src=${src:-}"
exec "$0" generate
;;
upgrade)