Skip to content

Commit f258692

Browse files
authored
Merge pull request #222 from wnlen/dev
Dev
2 parents 9a65347 + 7fff13e commit f258692

3 files changed

Lines changed: 86 additions & 21 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ Control 层负责把常用动作收口成可理解的命令和反馈。
235235
- 单 active 主订阅
236236
- active-only 编译链
237237
- 订阅下载 / 转换 / 校验
238-
- `config/mixin.yaml` 运行补丁
238+
- `runtime/mixin.yaml` 运行补丁(兼容读取 `config/mixin.yaml`
239239
- 输出 `runtime/config.yaml`
240240
241241
当前规则很明确:`generate_config` 只处理当前 active 主订阅。
@@ -307,7 +307,7 @@ resources/geo/Country.mmdb
307307
308308
也可以设置 `CLASH_BUNDLED_ASSET_ENABLED=false` 强制跳过内置文件,或用 `CLASH_BUNDLED_ASSET_DIR=/path/to/assets` 指向项目外的资源目录。Mihomo、yq、subconverter 兼容旧路径 `resources/bin/<category>/<version>/<file>`
309309
310-
### `config/mixin.yaml`
310+
### `runtime/mixin.yaml`(兼容 `config/mixin.yaml`
311311
312312
用于对最终运行配置做补丁:
313313
@@ -359,7 +359,7 @@ clashctl mixin raw
359359
clashctl mixin runtime
360360
```
361361
362-
Mixin 是运行配置补丁,不是订阅管理。它通过 `config/mixin.yaml` 对当前 active 订阅生成的运行配置执行:
362+
Mixin 是运行配置补丁,不是订阅管理。它优先通过 `runtime/mixin.yaml`(兼容读取 `config/mixin.yaml`对当前 active 订阅生成的运行配置执行:
363363
364364
- `override`
365365
- `prepend`
@@ -395,7 +395,7 @@ clashctl mixin edit
395395
396396
### 多跳节点
397397
398-
多跳节点会写入 `config/mixin.yaml`,通过 Mihomo/Clash 的 `relay` 策略组串联已有订阅节点。节点名称必须与订阅生成的节点名完全一致,可先通过 Web 控制台确认:
398+
多跳节点会写入 `runtime/mixin.yaml`(兼容读取 `config/mixin.yaml`,通过 Mihomo/Clash 的 `relay` 策略组串联已有订阅节点。节点名称必须与订阅生成的节点名完全一致,可先通过 Web 控制台确认:
399399
400400
```bash
401401
clashon

scripts/core/clashctl.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,7 +3829,8 @@ cmd_profile() {
38293829
}
38303830

38313831
mixin_config_file() {
3832-
echo "$CONFIG_DIR/mixin.yaml"
3832+
ensure_mixin_file
3833+
echo "$(mixin_file)"
38333834
}
38343835

38353836
active_subscription_runtime_raw_file() {
@@ -4284,7 +4285,7 @@ cmd_relay() {
42844285
echo " clashctl relay add 全局多跳 节点A 节点B --match"
42854286
echo
42864287
echo "说明:"
4287-
echo " add 会写入 config/mixin.yaml,并重新生成运行配置"
4288+
echo " add 会写入 runtime/mixin.yaml(兼容读取 config/mixin.yaml,并重新生成运行配置"
42884289
echo " --domain 用于小范围测试,--match 会让所有未提前命中的流量走多跳"
42894290
echo " 节点名称必须与订阅生成的节点名完全一致"
42904291
;;

scripts/core/config.sh

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,6 @@ proxy-groups: []
297297
rules: []
298298
EOF
299299

300-
[ -f "$CONFIG_DIR/mixin.yaml" ] || cat > "$CONFIG_DIR/mixin.yaml" <<'EOF'
301-
override: {}
302-
prepend:
303-
proxies: []
304-
proxy-groups: []
305-
rules: []
306-
append:
307-
proxies: []
308-
proxy-groups: []
309-
rules: []
310-
EOF
311-
312300
[ -f "$CONFIG_DIR/profiles.yaml" ] || cat > "$CONFIG_DIR/profiles.yaml" <<'EOF'
313301
active: default
314302
profiles:
@@ -1974,17 +1962,93 @@ mark_install_port_plan() {
19741962
}
19751963

19761964
mixin_file() {
1965+
echo "$RUNTIME_DIR/mixin.yaml"
1966+
}
1967+
1968+
mixin_legacy_file() {
19771969
echo "$CONFIG_DIR/mixin.yaml"
19781970
}
19791971

1972+
write_default_mixin_template() {
1973+
local file="$1"
1974+
cat > "$file" <<'EOF'
1975+
override: {}
1976+
prepend:
1977+
proxies: []
1978+
proxy-groups: []
1979+
rules: []
1980+
append:
1981+
proxies: []
1982+
proxy-groups: []
1983+
rules: []
1984+
EOF
1985+
}
1986+
1987+
mixin_conflict_notice_file() {
1988+
echo "$RUNTIME_DIR/.mixin-conflict-noticed"
1989+
}
1990+
1991+
warn_mixin_path_conflict_once() {
1992+
local notice_file
1993+
notice_file="$(mixin_conflict_notice_file)"
1994+
if [ -f "$notice_file" ]; then
1995+
return 0
1996+
fi
1997+
1998+
warn "检测到新旧 mixin 配置同时存在且内容不一致。将优先使用 $(mixin_file),旧文件 $(mixin_legacy_file) 仅保留兼容读取。"
1999+
warn "迁移建议:请将 $(mixin_legacy_file) 的自定义内容合并到 $(mixin_file),并停止修改旧路径。"
2000+
2001+
mkdir -p "$RUNTIME_DIR"
2002+
: > "$notice_file"
2003+
}
2004+
2005+
mixin_read_file() {
2006+
local new_file legacy_file
2007+
new_file="$(mixin_file)"
2008+
legacy_file="$(mixin_legacy_file)"
2009+
2010+
if [ -f "$new_file" ]; then
2011+
if [ -f "$legacy_file" ] && ! cmp -s "$new_file" "$legacy_file" 2>/dev/null; then
2012+
warn_mixin_path_conflict_once
2013+
fi
2014+
echo "$new_file"
2015+
return 0
2016+
fi
2017+
2018+
if [ -f "$legacy_file" ]; then
2019+
echo "$legacy_file"
2020+
return 0
2021+
fi
2022+
2023+
echo "$new_file"
2024+
}
2025+
2026+
migrate_legacy_mixin_to_runtime_if_needed() {
2027+
local new_file legacy_file
2028+
new_file="$(mixin_file)"
2029+
legacy_file="$(mixin_legacy_file)"
2030+
2031+
[ -f "$new_file" ] && return 0
2032+
[ -f "$legacy_file" ] || return 0
2033+
2034+
mkdir -p "$RUNTIME_DIR"
2035+
cp -f "$legacy_file" "$new_file" 2>/dev/null || true
2036+
}
2037+
19802038
ensure_mixin_file() {
19812039
ensure_config_files
2040+
migrate_legacy_mixin_to_runtime_if_needed
2041+
2042+
if [ ! -f "$(mixin_file)" ]; then
2043+
mkdir -p "$RUNTIME_DIR"
2044+
write_default_mixin_template "$(mixin_file)"
2045+
fi
19822046
}
19832047

19842048
apply_mixin_override() {
19852049
local runtime_file="$1"
19862050
local mixin_file_path
1987-
mixin_file_path="$(mixin_file)"
2051+
mixin_file_path="$(mixin_read_file)"
19882052

19892053
[ -s "$runtime_file" ] || die "运行配置不存在:$runtime_file"
19902054
[ -f "$mixin_file_path" ] || return 0
@@ -1998,7 +2062,7 @@ apply_mixin_override() {
19982062
apply_mixin_prepend_arrays() {
19992063
local runtime_file="$1"
20002064
local mixin_file_path
2001-
mixin_file_path="$(mixin_file)"
2065+
mixin_file_path="$(mixin_read_file)"
20022066

20032067
[ -s "$runtime_file" ] || die "运行配置不存在:$runtime_file"
20042068
[ -f "$mixin_file_path" ] || return 0
@@ -2014,7 +2078,7 @@ apply_mixin_prepend_arrays() {
20142078
apply_mixin_append_arrays() {
20152079
local runtime_file="$1"
20162080
local mixin_file_path
2017-
mixin_file_path="$(mixin_file)"
2081+
mixin_file_path="$(mixin_read_file)"
20182082

20192083
[ -s "$runtime_file" ] || die "运行配置不存在:$runtime_file"
20202084
[ -f "$mixin_file_path" ] || return 0

0 commit comments

Comments
 (0)