@@ -297,18 +297,6 @@ proxy-groups: []
297297rules: []
298298EOF
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 '
313301active: default
314302profiles:
@@ -1974,17 +1962,93 @@ mark_install_port_plan() {
19741962}
19751963
19761964mixin_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+
19802038ensure_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
19842048apply_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() {
19982062apply_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() {
20142078apply_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