@@ -21,27 +21,8 @@ readonly KILL_TIMEOUT=5
2121
2222export PATH=" $MODDIR /bin:$PATH "
2323
24-
2524readonly BUSYBOX=" $( detect_busybox) "
2625
27- # ######################################
28- # 环境与配置校验
29- # ######################################
30- verify_environment () {
31- [ -x " $SING_BOX_BIN " ] || die " sing-box 二进制不存在或不可执行: $SING_BOX_BIN "
32- [ -f " $MODULE_CONF " ] || die " 模块配置文件不存在: $MODULE_CONF "
33- [ -f " $TPROXY_CONF_DIR /tproxy.conf" ] || die " 透明代理配置文件不存在: $TPROXY_CONF_DIR /tproxy.conf"
34-
35- . " $MODULE_CONF "
36- . " $TPROXY_CONF_DIR /tproxy.conf"
37-
38- local outbound_config
39- outbound_config=" $( strip_quotes " ${CURRENT_CONFIG:- } " ) "
40- [ -n " $outbound_config " ] || die " CURRENT_CONFIG 未定义,请先选择节点"
41- [ -f " $outbound_config " ] || die " 指定的节点配置文件不存在: $outbound_config "
42-
43- echo " $outbound_config "
44- }
4526
4627# ######################################
4728# 启动服务
@@ -57,37 +38,21 @@ do_start() {
5738 return 0
5839 fi
5940
60- # 准备节点与运行时出站配置
61- local outbound_config outbound_dir outbound_mode selector_mode runtime_outbounds
62- outbound_config=" $( verify_environment) " || exit 1
63- . " $MODULE_CONF "
64- outbound_mode=" ${OUTBOUND_MODE:- rule} "
65- selector_mode=" ${SELECTOR_MODE:- urltest} "
66- outbound_dir=" $( get_current_outbounds_dir " $outbound_config " ) " || exit 1
67- runtime_outbounds=" $( write_runtime_outbounds " $outbound_config " " $selector_mode " ) " || exit 1
41+ # 准备启动环境与配置
42+ initialize_runtime_context || exit 1
43+ write_runtime_outbounds || exit 1
44+ local runtime_outbounds=" $RUNTIME_DIR /outbounds.json"
6845
69- log " INFO" " 路由模式: $outbound_mode "
46+ log " INFO" " 路由模式: $CUR_OUTBOUND_MODE "
47+ log " INFO" " 节点目录: $CUR_OUTBOUND_DIR "
7048
71- # 构造启动参数
72- local f tag node_count=0 skipped_count=0
49+ # 构造最终启动参数
7350 set -- run -C " $CONFDIR "
74-
75- for f in " $outbound_dir " /* .json; do
76- is_node_config_file " $f " || continue
77- tag=" $( detect_outbound_tag " $f " ) "
78- if [ -z " $tag " ]; then
79- skipped_count=$(( skipped_count + 1 ))
80- continue
81- fi
82-
83- set -- " $@ " -c " $f "
84- node_count=$(( node_count + 1 ))
85- done
86-
87- [ " $node_count " -gt 0 ] || die " 当前节点目录没有可加载的节点配置: $outbound_dir "
88- log " INFO" " 节点目录: $outbound_dir "
89- log " INFO" " 已加载节点: $node_count ,跳过无效节点: $skipped_count "
9051 [ -n " $runtime_outbounds " ] && set -- " $@ " -c " $runtime_outbounds "
52+ eval " set -- \"\$ @\" $SCAN_NODE_ARGS "
53+
54+ [ " $SCAN_NODE_COUNT " -gt 0 ] || die " 当前节点目录没有可加载的节点配置: $CUR_OUTBOUND_DIR "
55+ log " INFO" " 已加载节点: $SCAN_NODE_COUNT ,跳过节点: $SCAN_SKIPPED_COUNT "
9156
9257 # 启动 sing-box 进程
9358 log " INFO" " 正在启动 sing-box 进程..."
@@ -105,7 +70,7 @@ do_start() {
10570 fi
10671
10772 # 同步运行模式并载入透明代理规则
108- sh " $MODDIR /scripts/core/switch.sh" mode " $outbound_mode " >> " $LOG_FILE " 2>&1 || log " WARN" " 控制接口失败"
73+ sh " $MODDIR /scripts/core/switch.sh" mode " $CUR_OUTBOUND_MODE " >> " $LOG_FILE " 2>&1 || log " WARN" " 控制接口失败"
10974 log " INFO" " 载入透明代理规则..."
11075 " $MODDIR /scripts/network/tproxy.sh" start -d " $TPROXY_CONF_DIR " >> " $LOG_FILE " 2>&1
11176
0 commit comments