perf: improve merge config process to fix #333,fix #303
This commit is contained in:
1 parent
a01f1ab052
commit
44d8f76fc5
2 files changed
+86
-15
No files matched your search
+20
-8
@@ -1,22 +1,34 @@
|
||||
# 系统代理配置
|
||||
system-proxy:
|
||||
enable: true
|
||||
_custom:
|
||||
system-proxy:
|
||||
enable: true
|
||||
|
||||
mixed-port: 7890
|
||||
|
||||
# Web 控制台配置
|
||||
external-controller: "0.0.0.0:9090"
|
||||
external-ui: public
|
||||
secret:
|
||||
|
||||
# 代理服务器配置
|
||||
allow-lan: false # 若开启务必设置用户验证以防暴露公网后被滥用
|
||||
authentication:
|
||||
# - "username:password" # 用户验证(clashon 会自动填充验证信息)
|
||||
# - "username:password" # 用户验证(clashon 会自动填充)
|
||||
|
||||
# 自定义规则
|
||||
# prefix:前置插入
|
||||
# suffix:后置插入
|
||||
# override:根据 name 匹配并替换原项
|
||||
rules:
|
||||
- DOMAIN,api64.ipify.org,DIRECT # 用于 clashui 获取真实公网 IP
|
||||
prefix:
|
||||
- DOMAIN,api64.ipify.org,DIRECT #用于 clashui 获取真实公网 IP
|
||||
suffix:
|
||||
|
||||
proxies:
|
||||
prefix:
|
||||
suffix:
|
||||
override:
|
||||
|
||||
proxy-groups:
|
||||
prefix:
|
||||
suffix:
|
||||
override:
|
||||
|
||||
# tun 配置
|
||||
tun:
|
||||
|
||||
+66
-7
@@ -71,17 +71,17 @@ function clashproxy() {
|
||||
_failcat '代理程序未运行,请执行 clashon 开启代理环境'
|
||||
return 1
|
||||
}
|
||||
sudo "$BIN_YQ" -i '.system-proxy.enable = true' "$CLASH_CONFIG_MIXIN"
|
||||
sudo "$BIN_YQ" -i '._custom.system-proxy.enable = true' "$CLASH_CONFIG_MIXIN"
|
||||
_set_system_proxy
|
||||
_okcat '已开启系统代理'
|
||||
;;
|
||||
off)
|
||||
sudo "$BIN_YQ" -i '.system-proxy.enable = false' "$CLASH_CONFIG_MIXIN"
|
||||
sudo "$BIN_YQ" -i '._custom.system-proxy.enable = false' "$CLASH_CONFIG_MIXIN"
|
||||
_unset_system_proxy
|
||||
_okcat '已关闭系统代理'
|
||||
;;
|
||||
status)
|
||||
local system_proxy_status=$(sudo "$BIN_YQ" '.system-proxy.enable' "$CLASH_CONFIG_MIXIN" 2>/dev/null)
|
||||
local system_proxy_status=$(sudo "$BIN_YQ" '._custom.system-proxy.enable' "$CLASH_CONFIG_MIXIN" 2>/dev/null)
|
||||
[ "$system_proxy_status" = "false" ] && {
|
||||
_failcat "系统代理:关闭"
|
||||
return 1
|
||||
@@ -131,11 +131,70 @@ function clashui() {
|
||||
|
||||
_merge_config_restart() {
|
||||
local backup="/tmp/rt.backup"
|
||||
sudo cat "$CLASH_CONFIG_RUNTIME" 2>/dev/null | sudo tee $backup >&/dev/null
|
||||
sudo "$BIN_YQ" eval-all '. as $item ireduce ({}; . *+ $item) | (.. | select(tag == "!!seq")) |= unique' \
|
||||
"$CLASH_CONFIG_MIXIN" "$CLASH_CONFIG_RAW" "$CLASH_CONFIG_MIXIN" | sudo tee "$CLASH_CONFIG_RUNTIME" >&/dev/null
|
||||
sudo cat "$CLASH_CONFIG_RUNTIME" 2>/dev/null | sudo tee $backup >/dev/null
|
||||
# shellcheck disable=SC2016
|
||||
"$BIN_YQ" eval-all '
|
||||
########################################
|
||||
# Load Files #
|
||||
########################################
|
||||
select(fileIndex==0) as $config |
|
||||
select(fileIndex==1) as $mixin |
|
||||
|
||||
########################################
|
||||
# Deep Merge #
|
||||
########################################
|
||||
$mixin |= del(._custom) |
|
||||
($config * $mixin) as $base |
|
||||
$base |
|
||||
|
||||
########################################
|
||||
# Rules #
|
||||
########################################
|
||||
.rules = (
|
||||
($mixin.rules.prefix // []) +
|
||||
($config.rules // []) +
|
||||
($mixin.rules.suffix // [])
|
||||
) |
|
||||
|
||||
########################################
|
||||
# Proxies #
|
||||
########################################
|
||||
.proxies = (
|
||||
($mixin.proxies.prefix // []) +
|
||||
(
|
||||
($config.proxies // []) as $configList |
|
||||
($mixin.proxies.override // []) as $overrideList |
|
||||
$configList | map(
|
||||
. as $configItem |
|
||||
(
|
||||
$overrideList[] | select(.name == $configItem.name)
|
||||
) // $configItem
|
||||
)
|
||||
) +
|
||||
($mixin.proxies.suffix // [])
|
||||
) |
|
||||
|
||||
########################################
|
||||
# ProxyGroups #
|
||||
########################################
|
||||
.proxy-groups = (
|
||||
($mixin.proxy-groups.prefix // []) +
|
||||
(
|
||||
($config.proxy-groups // []) as $configList |
|
||||
($mixin.proxy-groups.override // []) as $overrideList |
|
||||
$configList | map(
|
||||
. as $configItem |
|
||||
(
|
||||
$overrideList[] | select(.name == $configItem.name)
|
||||
) // $configItem
|
||||
)
|
||||
) +
|
||||
($mixin.proxy-groups.suffix // [])
|
||||
)
|
||||
' "$CLASH_CONFIG_RAW" "$CLASH_CONFIG_MIXIN" |
|
||||
sudo tee "$CLASH_CONFIG_RUNTIME" >/dev/null
|
||||
_valid_config "$CLASH_CONFIG_RUNTIME" || {
|
||||
sudo cat $backup | sudo tee "$CLASH_CONFIG_RUNTIME" >&/dev/null
|
||||
sudo cat $backup | sudo tee "$CLASH_CONFIG_RUNTIME" >/dev/null
|
||||
_error_quit "验证失败:请检查 Mixin 配置"
|
||||
}
|
||||
clashrestart
|
||||
|
||||
Reference in new issue
Block a user