clash-meta-proxy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Clash-Meta 配置更新

Update Clash-Meta Configuration

更新服务器的 clash-meta 代理配置。
Update the clash-meta proxy configuration on the server.

环境信息

Environment Information

  • 默认工作目录:
    ./
  • 现配置文件:
    config.yaml
  • 新代理配置:
    .proxies.yaml
  • Default Working Directory:
    ./
  • Current Configuration File:
    config.yaml
  • New Proxy Configuration:
    .proxies.yaml

使用脚本自动化(推荐)

Automated Script Usage (Recommended)

提供 PEP 723 内联元数据脚本,支持
uv run
直接运行,无需手动安装依赖。
A script with PEP 723 inline metadata is provided, supporting direct execution via
uv run
without manual dependency installation.

运行方式

Execution Methods

方式一:直接运行(推荐)
bash
undefined
Method 1: Direct Execution (Recommended)
bash
undefined

In the work_dir

In the work_dir

uv run scripts/update_clash_config.py

**方式二:指定工作目录运行**
```bash
uv run --cwd ./ scripts/update_clash_config.py
脚本自动完成:
  • 文件备份(
    config.yaml.bak
    + 时间戳备份 +
    config.yaml.editing
  • 读取
    .proxies.yaml
    并完整覆盖
    proxies
  • 核验
    proxy-groups
    ,注释失效代理
  • 生成 diff 到控制台和
    .update.diff
uv run scripts/update_clash_config.py

**Method 2: Execute with Specified Working Directory**
```bash
uv run --cwd ./ scripts/update_clash_config.py
The script automatically performs the following:
  • File backup (creates
    config.yaml.bak
    , timestamped backup, and
    config.yaml.editing
    )
  • Reads
    .proxies.yaml
    and fully overwrites the
    proxies
    section
  • Verifies
    proxy-groups
    and comments out invalid proxies
  • Generates a diff output to the console and
    .update.diff
    file

人工确认与生效(关键步骤)

Manual Confirmation and Activation (Critical Step)

脚本不会自动重命名文件,需人工确认后执行:
  1. 检查 diff 输出
bash
cat ./.update.diff
  1. 确认无误后生效
bash
mv ./config.yaml.editing ./config.yaml
The script will not automatically rename files; manual confirmation is required before execution:
  1. Check Diff Output
bash
cat ./.update.diff
  1. Activate After Confirmation
bash
mv ./config.yaml.editing ./config.yaml

手动操作流程

Manual Operation Process

若脚本无法使用,按以下步骤手动操作:
  1. 备份配置
    • 复制
      config.yaml
      config.yaml.bak
    • 复制
      config.yaml
      config.yaml.editing
  2. 更新 proxies 配置
    • 读取
      .proxies.yaml
      获取新代理节点
    • 用新代理列表完整覆盖
      config.yaml.editing
      中的
      proxies
      字段
  3. 核验 proxy-groups
    • 检查
      proxy-groups[*].proxies
      引用的 name 是否存在于
      proxies
      列表
    • 若发现失效代理,注释掉而非删除
  4. diff 确认并重命名
    • 执行
      diff config.yaml.bak config.yaml.editing
      对比
    • 确认无误后,将
      config.yaml.editing
      重命名为
      config.yaml
If the script cannot be used, follow these steps manually:
  1. Backup Configuration
    • Copy
      config.yaml
      to
      config.yaml.bak
    • Copy
      config.yaml
      to
      config.yaml.editing
  2. Update Proxies Configuration
    • Read
      .proxies.yaml
      to obtain new proxy nodes
    • Fully overwrite the
      proxies
      field in
      config.yaml.editing
      with the new proxy list
  3. Verify Proxy-Groups
    • Check if the names referenced in
      proxy-groups[*].proxies
      exist in the
      proxies
      list
    • Comment out invalid proxies instead of deleting them
  4. Diff Confirmation and Rename
    • Execute
      diff config.yaml.bak config.yaml.editing
      to compare changes
    • After confirmation, rename
      config.yaml.editing
      to
      config.yaml

配置示例

Configuration Examples

.proxies.yaml 结构

.proxies.yaml Structure

yaml
proxies:
  - name: hy2.node.proxychain.top
    type: hysteria2
    server: IP
    port: PORT
    password: PASSWORD
    sni: hy2.node.proxychain.top
    skip-cert-verify: false
yaml
proxies:
  - name: hy2.node.proxychain.top
    type: hysteria2
    server: IP
    port: PORT
    password: PASSWORD
    sni: hy2.node.proxychain.top
    skip-cert-verify: false

proxy-groups 结构

Proxy-Groups Structure

yaml
proxy-groups:
  - name: G-SELECT
    type: select
    proxies:
      # - 失效节点名    # 已失效,需注释
      - hy2.node.proxychain.top   # 有效节点
yaml
proxy-groups:
  - name: G-SELECT
    type: select
    proxies:
      # - 失效节点名    # 已失效,需注释
      - hy2.node.proxychain.top   # 有效节点

注意事项

Notes

  • proxy-groups[*].proxies
    引用的 name 必须与
    proxies[*].name
    严格对应
  • 仅注释失效代理名,保留配置结构完整
  • 始终保留
    config.yaml.bak
    以便回滚
  • 最终重命名操作必须由人工确认后执行
  • The names referenced in
    proxy-groups[*].proxies
    must strictly match
    proxies[*].name
  • Only comment out invalid proxy names; keep the configuration structure intact
  • Always retain
    config.yaml.bak
    for rollback purposes
  • The final rename operation must be performed manually after confirmation