|
|
1 vecka sedan | |
|---|---|---|
| scripts | 1 vecka sedan | |
| substore | 1 vecka sedan | |
| .gitignore | 1 vecka sedan | |
| CLAUDE.md | 1 vecka sedan | |
| README.md | 1 vecka sedan | |
| config.router.json | 1 vecka sedan | |
| config.server.json | 1 vecka sedan | |
| router_local.conf | 1 vecka sedan | |
| workflow.md | 1 vecka sedan |
一个用于选择优选目标并写出运行时文件的工具集,当前支持两套独立模式:
runtime/,可自动提交到 runtime-statecfst,选择优选 IP,写入 cfip_runtime/;HTTP 暴露推荐使用项目目录下的完整 BusyBox httpd这两套模式已经彻底拆开:
config.server.jsoncfst 模式使用 config.router.jsonrouter_local.conf旧的 config.json / config.example.json 已废弃,不再使用。
核心脚本:
scripts/domain_updater.py
统一的 Python 主入口,支持 api 和 cfst_local 两种 source.typescripts/run_update_and_commit.sh
服务器模式入口,执行 updater 并按配置同步运行时文件到 runtime-statescripts/install_debian.sh
Debian/Ubuntu 一键安装 systemd service + timerscripts/uninstall_debian.sh
卸载 systemd service + timerscripts/router_local_update.sh
BusyBox sh 路由器入口,执行 cfst 并写出 cfip_runtimescripts/router_local_http.sh
BusyBox sh 路由器 HTTP 暴露入口,优先使用 BusyBox httpd 暴露运行时文件scripts/update_vmess_links.py
可选工具,用运行时文件里的值批量替换 vmess:// 节点配置文件:
config.server.json
服务器模式配置,输出默认是:
runtime/current_domain.txtruntime/current_domain.jsonruntime/state.jsonruntime/substore_vars.jsonconfig.router.json
本地 cfst 模式配置,输出默认是:
cfip_runtime/current_ip.txtcfip_runtime/current_ip.jsoncfip_runtime/state.jsoncfip_runtime/substore_vars.jsonrouter_local.conf
BusyBox 路由器脚本配置,给 router_local_update.sh / router_local_http.sh 使用两套模式共用同一套“输出抽象”:
关键点:
runtime/current_domain.txtrun_update_and_commit.sh 会先解析配置里的输出路径,再决定同步哪些文件domain_updater.py 会按 --config 所在目录解析相对路径适用场景:
python3runtime-state入口:
python3 scripts/domain_updater.py --config config.server.jsonbash scripts/run_update_and_commit.sh config.server.jsonsudo bash scripts/install_debian.sh --config config.server.jsoncfst 模式适用场景:
cfstdomain_updater.py 直接调用本地 cfst入口:
python3 scripts/domain_updater.py --config config.router.json适用场景:
sh / awk / sed 等基础工具即可执行更新脚本BUSYBOX_BIN="./busybox_armv7l",脚本会调用它的 httpd applet;系统自带精简 nc 不够入口:
sh scripts/router_local_update.sh ./router_local.confsh scripts/router_local_http.sh ./router_local.confgit clone 后在仓库目录执行originconfig.server.json 中的 API服务器模式固定使用 config.server.json。
它当前默认行为:
source.type = "api"api.url 拉取候选结果parser、record_mapping、record_filter、scoring 选择目标runtime/你通常只需要修改:
api.urlapi.headersparserrecord_mappingrecord_filterscoringhealthcheck先做语法检查:
env PYTHONPYCACHEPREFIX=/tmp/pycache python3 -m py_compile scripts/domain_updater.py
执行一次:
python3 scripts/domain_updater.py --config config.server.json
查看结果:
cat runtime/current_domain.txt
cat runtime/current_domain.json
cat runtime/state.json
cat runtime/substore_vars.json
如果你只想看脚本解析出的输出路径:
python3 scripts/domain_updater.py --config config.server.json --print-output-settings
服务器模式提交脚本:
bash scripts/run_update_and_commit.sh config.server.json
它会执行:
domain_updater.pyruntime-state 分支上次记录强制提交:
bash scripts/run_update_and_commit.sh --force-commit config.server.json
或:
GIT_FORCE_COMMIT=1 bash scripts/run_update_and_commit.sh config.server.json
推荐命令:
sudo bash scripts/install_debian.sh --config config.server.json
默认行为:
sudo 前的用户作为 service 用户1hruntime-state常用参数:
sudo bash scripts/install_debian.sh \
--config config.server.json \
--interval 10min \
--git-push 1 \
--git-push-remote origin
如果用 token:
sudo bash scripts/install_debian.sh \
--config config.server.json \
--git-http-username <your-user> \
--git-http-token-file /root/.config/vmess-token \
--git-use-credential-store 1
sudo systemctl status vmess-domain-rotator.timer
sudo systemctl status vmess-domain-rotator.service
sudo systemctl start vmess-domain-rotator.service
sudo journalctl -u vmess-domain-rotator.service -n 120 --no-pager
成功时通常应看到:
committed output changes on runtime-statepushed to origin/runtime-statesudo bash scripts/uninstall_debian.sh
保留认证文件:
sudo bash scripts/uninstall_debian.sh --keep-auth-files
cfst 模式部署python3cfstdomain_updater.py 的统一输出逻辑本模式使用 config.router.json。
它当前默认指向:
./cfst_darwin_arm64/cfst./cfst_darwin_arm64/result.csv./cfip_runtime你通常只需要修改:
cfst_local.work_dircfst_local.binarycfst_local.run_argscfst_local.result_filecfst_local.columnsoutput.*python3 scripts/domain_updater.py --config config.router.json
查看结果:
cat cfip_runtime/current_ip.txt
cat cfip_runtime/current_ip.json
cat cfip_runtime/state.json
cat cfip_runtime/substore_vars.json
查看解析出的输出路径:
python3 scripts/domain_updater.py --config config.router.json --print-output-settings
cfst_local 关键项:
work_dir
cfst 工作目录binary
cfst 可执行文件路径run_args
执行参数数组,例如 -f ip.txt -o result.csv -p 10result_file
cfst 输出结果文件skip_run
为 true 时不执行 cfst,只解析现有结果文件columns
CSV 列映射,默认按:
0 IP1 已发送2 已接收3 丢包率4 平均延迟5 下载速度6 地区cfstbusybox_armv7lhttpd applet,不使用 ASUS 固件自带 /usr/sbin/httpd架构以目标路由器实际输出为准:
uname -m
cfst 和完整 BusyBox 都必须匹配路由器架构。ASUS RT-AC68U 示例里,完整 BusyBox 文件名使用 busybox_armv7l。
示例(ASUS RT-AC68U 推荐放在 /jffs/vmess):
/jffs/vmess/
├── busybox_armv7l
├── router_local.conf
├── scripts/
│ ├── router_local_update.sh
│ └── router_local_http.sh
└── cfst/
├── cfst
├── ip.txt
└── result.csv
其中:
router_local.conf 指定 CFST_WORK_DIR、输出目录、HTTP 端口、完整 BusyBox 路径等busybox_armv7l 是你下载的完整 BusyBox,HTTP 服务脚本会优先调用它,而不是系统自带 BusyBox/ASUS httpdcfst/ 放路由器架构对应的 cfst当前仓库里的 router_local.conf 就是 BusyBox 配置文件。
最重要的字段:
CFST_WORK_DIR
cfst 所在目录CFST_BIN
cfst 可执行文件名,一般是 ./cfstCFST_IP_FILE
输入 IP 列表CFST_RESULT_FILE
cfst 结果文件RUNTIME_DIR
运行时输出目录,默认 ./cfip_runtimeVALUE_TEXT_FILE
当前值文本文件,默认 current_ip.txtVALUE_JSON_FILE
当前值 JSON 文件,默认 current_ip.jsonBUSYBOX_BIN
完整 BusyBox 二进制路径,默认 ./busybox_armv7l;HTTP 脚本会优先调用它的 httpd applet,避免误用 ASUS /usr/sbin/httpdHTTP_PORT
局域网 HTTP 监听端口,默认 8080sh scripts/router_local_update.sh ./router_local.conf
成功时会输出类似:
[router-local] selected ip: x.x.x.x
生成文件默认在:
cfip_runtime/current_ip.txtcfip_runtime/index.html(复制当前 IP 文本,供 / 访问)cfip_runtime/current_ip.jsoncfip_runtime/state.jsoncfip_runtime/substore_vars.jsonsh scripts/router_local_http.sh ./router_local.conf
默认会监听:
0.0.0.0:8080
这个脚本不再使用系统自带的精简 nc 或 ASUS /usr/sbin/httpd。它会读取 router_local.conf 里的 BUSYBOX_BIN,优先调用项目目录下完整 BusyBox 的 httpd applet:
./busybox_armv7l httpd -f -p 8080 -h ./cfip_runtime
如果你的 BusyBox applet 列表里没有 httpd,当前脚本会明确报错。ASUS 固件自带的 /usr/sbin/httpd 通常是路由器管理后台服务,不是 BusyBox 静态文件服务器;即使支持 -p 端口参数,也不代表支持 -h ./cfip_runtime 这类目录发布。
可访问路径:
/(由 index.html 返回当前 IP 文本)/current_ip.txt/current_ip.json/state.json/substore_vars.json例如局域网内访问:
curl http://192.168.50.1:8080/current_ip.json
curl http://192.168.50.1:8080/current_ip.txt
如果路由器使用 /jffs/scripts/services-start 统一启动任务,可以用 cru 注册定时更新和 watchdog。这个小节是 ASUS RT-AC68U / KoolShare 风格固件专用示例,假设项目放在 /jffs/vmess,完整 BusyBox 位于 /jffs/vmess/busybox_armv7l。
部署前建议确认:
chmod +x /jffs/vmess/busybox_armv7l
chmod +x /jffs/scripts/services-start
/jffs/vmess/busybox_armv7l --list | grep '^httpd$'
router_local.conf 至少需要包含:
BUSYBOX_BIN="./busybox_armv7l"
HTTP_PORT="8080"
把 /jffs/scripts/services-start 写成:
#!/bin/sh
/koolshare/bin/ks-services-start.sh
VMESS_DIR="/jffs/vmess"
CONFIG="./router_local.conf"
UPDATE_LOG="/tmp/router_local_update.log"
HTTP_LOG="/tmp/router_http.log"
HTTP_PROCESS_PATTERN='[r]outer_local_http.sh'
start_vmess_http() {
if ps | grep -q "$HTTP_PROCESS_PATTERN"; then
return 0
fi
cd "$VMESS_DIR" || exit 1
nohup sh scripts/router_local_http.sh "$CONFIG" >> "$HTTP_LOG" 2>&1 &
}
cd "$VMESS_DIR" || exit 1
sh scripts/router_local_update.sh "$CONFIG" >> "$UPDATE_LOG" 2>&1
cru d vmess_rotate
cru a vmess_rotate "0 */3 * * * cd $VMESS_DIR && sh scripts/router_local_update.sh $CONFIG >> $UPDATE_LOG 2>&1"
sleep 10
start_vmess_http
cru d vmess_watchdog
cru a vmess_watchdog "*/5 * * * * if ! ps | grep -q '$HTTP_PROCESS_PATTERN'; then cd $VMESS_DIR && nohup sh scripts/router_local_http.sh $CONFIG >> $HTTP_LOG 2>&1 & fi"
这里用 [r]outer_local_http.sh 作为 grep 关键字,是为了避免 watchdog 的 shell 命令在 ps 里匹配到自己。router_local_http.sh 会保留 wrapper 进程并等待子进程里的完整 BusyBox httpd,所以 watchdog 用这个关键字可以正常判断服务是否仍在运行。示例里先 cru d 再 cru a,避免 services-start 被重复触发后留下旧的定时任务定义;启动 HTTP 前也会先检查进程,避免重复监听同一个端口。
如果你的固件没有 KoolShare,删除 /koolshare/bin/ks-services-start.sh 那一行即可;如果 Web UI 里有“启用 JFFS 自定义脚本”的选项,需要先开启,否则 /jffs/scripts/services-start 不会在开机时执行。
可以用 BusyBox crond 定时更新,例如每 15 分钟执行一次:
*/15 * * * * cd /tmp/home/root/vmess-domain-rotator && sh scripts/router_local_update.sh ./router_local.conf >> /tmp/router_local_update.log 2>&1
HTTP 服务如果需要手动后台启动:
cd /tmp/home/root/vmess-domain-rotator
nohup sh scripts/router_local_http.sh ./router_local.conf >/tmp/router_http.log 2>&1 &
如果下游要消费“当前值文件”,可使用 scripts/update_vmess_links.py。
服务器模式示例:
python3 scripts/update_vmess_links.py \
--input ./nodes.txt \
--output ./nodes.updated.txt \
--domain-file ./runtime/current_domain.txt
路由器/本地 cfst 模式示例:
python3 scripts/update_vmess_links.py \
--input ./nodes.txt \
--output ./nodes.updated.txt \
--domain-file ./cfip_runtime/current_ip.txt
仅替换匹配名称的节点:
python3 scripts/update_vmess_links.py \
--input ./nodes.txt \
--output ./nodes.updated.txt \
--domain-file ./runtime/current_domain.txt \
--name-regex "(argo|cf|vm)"
服务器模式:
sudo systemctl status vmess-domain-rotator.timer
sudo systemctl status vmess-domain-rotator.service
sudo systemctl start vmess-domain-rotator.service
sudo journalctl -u vmess-domain-rotator.service -f
git log runtime-state --oneline -n 20
路由器模式:
sh scripts/router_local_update.sh ./router_local.conf
sh scripts/router_local_http.sh ./router_local.conf
cat cfip_runtime/current_ip.txt
cat cfip_runtime/current_ip.json
run_update_and_commit.sh 设计目标是服务器模式;路由器模式默认不走 git 提交。terminal prompts disabled。credential.helper store 是明文存储,只适合可控服务器。router_local_update.sh 只依赖常见基础 applet;HTTP 暴露会优先调用 BUSYBOX_BIN 指向的完整 BusyBox httpd,不要依赖 ASUS /usr/sbin/httpd 或系统精简 nc。state.json 需要持久化,否则 fallback 不可用。