|
@@ -3,7 +3,7 @@
|
|
|
一个用于选择优选目标并写出运行时文件的工具集,当前支持两套独立模式:
|
|
一个用于选择优选目标并写出运行时文件的工具集,当前支持两套独立模式:
|
|
|
|
|
|
|
|
- 云服务器模式:调用远程 API,选择优选域名,写入 `runtime/`,可自动提交到 `runtime-state`
|
|
- 云服务器模式:调用远程 API,选择优选域名,写入 `runtime/`,可自动提交到 `runtime-state`
|
|
|
-- 本地路由器模式:调用本地 `cfst`,选择优选 IP,写入 `cfip_runtime/`,可通过 BusyBox `nc` 暴露到局域网
|
|
|
|
|
|
|
+- 本地路由器模式:调用本地 `cfst`,选择优选 IP,写入 `cfip_runtime/`;HTTP 暴露推荐使用项目目录下的完整 BusyBox `httpd`
|
|
|
|
|
|
|
|
这两套模式已经彻底拆开:
|
|
这两套模式已经彻底拆开:
|
|
|
|
|
|
|
@@ -28,7 +28,7 @@
|
|
|
- `scripts/router_local_update.sh`
|
|
- `scripts/router_local_update.sh`
|
|
|
BusyBox `sh` 路由器入口,执行 `cfst` 并写出 `cfip_runtime`
|
|
BusyBox `sh` 路由器入口,执行 `cfst` 并写出 `cfip_runtime`
|
|
|
- `scripts/router_local_http.sh`
|
|
- `scripts/router_local_http.sh`
|
|
|
- BusyBox `sh` 路由器 HTTP 暴露入口,使用 `nc` 暴露 TXT/JSON
|
|
|
|
|
|
|
+ BusyBox `sh` 路由器 HTTP 暴露入口,优先使用 BusyBox `httpd` 暴露运行时文件
|
|
|
- `scripts/update_vmess_links.py`
|
|
- `scripts/update_vmess_links.py`
|
|
|
可选工具,用运行时文件里的值批量替换 `vmess://` 节点
|
|
可选工具,用运行时文件里的值批量替换 `vmess://` 节点
|
|
|
|
|
|
|
@@ -99,9 +99,8 @@
|
|
|
适用场景:
|
|
适用场景:
|
|
|
|
|
|
|
|
- 路由器没有 Python
|
|
- 路由器没有 Python
|
|
|
-- 只有 BusyBox `sh` / `awk` / `sed` / `nc`
|
|
|
|
|
-- 直接在路由器上跑 `cfst`
|
|
|
|
|
-- 需要在局域网暴露 HTTP
|
|
|
|
|
|
|
+- 只有 BusyBox `sh` / `awk` / `sed` 等基础工具即可执行更新脚本
|
|
|
|
|
+- HTTP 暴露推荐使用项目目录下的完整 BusyBox,例如 `BUSYBOX_BIN="./busybox_armv7l"`,脚本会调用它的 `httpd` applet;系统自带精简 `nc` 不够
|
|
|
|
|
|
|
|
入口:
|
|
入口:
|
|
|
|
|
|
|
@@ -335,25 +334,26 @@ python3 scripts/domain_updater.py --config config.router.json --print-output-set
|
|
|
|
|
|
|
|
### 6.1 适用环境
|
|
### 6.1 适用环境
|
|
|
|
|
|
|
|
-- 路由器架构已确认
|
|
|
|
|
|
|
+- 路由器没有 Python
|
|
|
- 已准备对应架构的 `cfst`
|
|
- 已准备对应架构的 `cfst`
|
|
|
-- 路由器只有 BusyBox,没有 Python
|
|
|
|
|
|
|
+- 已准备完整 BusyBox,例如本项目默认使用 `busybox_armv7l`
|
|
|
|
|
+- HTTP 暴露使用完整 BusyBox 的 `httpd` applet,不使用 ASUS 固件自带 `/usr/sbin/httpd`
|
|
|
|
|
|
|
|
-你之前确认的路由器架构是:
|
|
|
|
|
|
|
+架构以目标路由器实际输出为准:
|
|
|
|
|
|
|
|
```bash
|
|
```bash
|
|
|
uname -m
|
|
uname -m
|
|
|
-# armv7
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-所以你需要放入可在 `armv7` 上运行的 `cfst` 二进制。
|
|
|
|
|
|
|
+`cfst` 和完整 BusyBox 都必须匹配路由器架构。ASUS RT-AC68U 示例里,完整 BusyBox 文件名使用 `busybox_armv7l`。
|
|
|
|
|
|
|
|
### 6.2 路由器目录建议
|
|
### 6.2 路由器目录建议
|
|
|
|
|
|
|
|
-示例:
|
|
|
|
|
|
|
+示例(ASUS RT-AC68U 推荐放在 `/jffs/vmess`):
|
|
|
|
|
|
|
|
```text
|
|
```text
|
|
|
-/tmp/home/root/vmess-domain-rotator/
|
|
|
|
|
|
|
+/jffs/vmess/
|
|
|
|
|
+├── busybox_armv7l
|
|
|
├── router_local.conf
|
|
├── router_local.conf
|
|
|
├── scripts/
|
|
├── scripts/
|
|
|
│ ├── router_local_update.sh
|
|
│ ├── router_local_update.sh
|
|
@@ -366,7 +366,8 @@ uname -m
|
|
|
|
|
|
|
|
其中:
|
|
其中:
|
|
|
|
|
|
|
|
-- `router_local.conf` 指定 `CFST_WORK_DIR`、输出目录、HTTP 端口等
|
|
|
|
|
|
|
+- `router_local.conf` 指定 `CFST_WORK_DIR`、输出目录、HTTP 端口、完整 BusyBox 路径等
|
|
|
|
|
+- `busybox_armv7l` 是你下载的完整 BusyBox,HTTP 服务脚本会优先调用它,而不是系统自带 BusyBox/ASUS `httpd`
|
|
|
- `cfst/` 放路由器架构对应的 `cfst`
|
|
- `cfst/` 放路由器架构对应的 `cfst`
|
|
|
|
|
|
|
|
### 6.3 配置 router_local.conf
|
|
### 6.3 配置 router_local.conf
|
|
@@ -389,6 +390,8 @@ uname -m
|
|
|
当前值文本文件,默认 `current_ip.txt`
|
|
当前值文本文件,默认 `current_ip.txt`
|
|
|
- `VALUE_JSON_FILE`
|
|
- `VALUE_JSON_FILE`
|
|
|
当前值 JSON 文件,默认 `current_ip.json`
|
|
当前值 JSON 文件,默认 `current_ip.json`
|
|
|
|
|
+- `BUSYBOX_BIN`
|
|
|
|
|
+ 完整 BusyBox 二进制路径,默认 `./busybox_armv7l`;HTTP 脚本会优先调用它的 `httpd` applet,避免误用 ASUS `/usr/sbin/httpd`
|
|
|
- `HTTP_PORT`
|
|
- `HTTP_PORT`
|
|
|
局域网 HTTP 监听端口,默认 `8080`
|
|
局域网 HTTP 监听端口,默认 `8080`
|
|
|
|
|
|
|
@@ -407,6 +410,7 @@ sh scripts/router_local_update.sh ./router_local.conf
|
|
|
生成文件默认在:
|
|
生成文件默认在:
|
|
|
|
|
|
|
|
- `cfip_runtime/current_ip.txt`
|
|
- `cfip_runtime/current_ip.txt`
|
|
|
|
|
+- `cfip_runtime/index.html`(复制当前 IP 文本,供 `/` 访问)
|
|
|
- `cfip_runtime/current_ip.json`
|
|
- `cfip_runtime/current_ip.json`
|
|
|
- `cfip_runtime/state.json`
|
|
- `cfip_runtime/state.json`
|
|
|
- `cfip_runtime/substore_vars.json`
|
|
- `cfip_runtime/substore_vars.json`
|
|
@@ -423,9 +427,17 @@ sh scripts/router_local_http.sh ./router_local.conf
|
|
|
0.0.0.0:8080
|
|
0.0.0.0:8080
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
+这个脚本不再使用系统自带的精简 `nc` 或 ASUS `/usr/sbin/httpd`。它会读取 `router_local.conf` 里的 `BUSYBOX_BIN`,优先调用项目目录下完整 BusyBox 的 `httpd` applet:
|
|
|
|
|
+
|
|
|
|
|
+```bash
|
|
|
|
|
+./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.txt`
|
|
|
- `/current_ip.json`
|
|
- `/current_ip.json`
|
|
|
- `/state.json`
|
|
- `/state.json`
|
|
@@ -438,7 +450,61 @@ curl http://192.168.50.1:8080/current_ip.json
|
|
|
curl http://192.168.50.1:8080/current_ip.txt
|
|
curl http://192.168.50.1:8080/current_ip.txt
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-### 6.6 定时执行
|
|
|
|
|
|
|
+### 6.6 ASUS RT-AC68U services-start 自启动
|
|
|
|
|
+
|
|
|
|
|
+如果路由器使用 `/jffs/scripts/services-start` 统一启动任务,可以用 `cru` 注册定时更新和 watchdog。这个小节是 ASUS RT-AC68U / KoolShare 风格固件专用示例,假设项目放在 `/jffs/vmess`,完整 BusyBox 位于 `/jffs/vmess/busybox_armv7l`。
|
|
|
|
|
+
|
|
|
|
|
+部署前建议确认:
|
|
|
|
|
+
|
|
|
|
|
+```sh
|
|
|
|
|
+chmod +x /jffs/vmess/busybox_armv7l
|
|
|
|
|
+chmod +x /jffs/scripts/services-start
|
|
|
|
|
+/jffs/vmess/busybox_armv7l --list | grep '^httpd$'
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+`router_local.conf` 至少需要包含:
|
|
|
|
|
+
|
|
|
|
|
+```sh
|
|
|
|
|
+BUSYBOX_BIN="./busybox_armv7l"
|
|
|
|
|
+HTTP_PORT="8080"
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+把 `/jffs/scripts/services-start` 写成:
|
|
|
|
|
+
|
|
|
|
|
+```sh
|
|
|
|
|
+#!/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"
|
|
|
|
|
+
|
|
|
|
|
+start_vmess_http() {
|
|
|
|
|
+ if ps | grep -v grep | grep -q 'router_local_http.sh'; 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 -v grep | grep -q 'router_local_http.sh'; then cd $VMESS_DIR && nohup sh scripts/router_local_http.sh $CONFIG >> $HTTP_LOG 2>&1 & fi"
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+`router_local_http.sh` 会保留 wrapper 进程并等待子进程里的完整 BusyBox `httpd`,所以 watchdog 用 `router_local_http.sh` 作为进程关键字可以正常判断服务是否仍在运行。示例里先 `cru d` 再 `cru a`,避免 `services-start` 被重复触发后留下旧的定时任务定义;启动 HTTP 前也会先检查进程,避免重复监听同一个端口。
|
|
|
|
|
+
|
|
|
|
|
+### 6.7 定时执行
|
|
|
|
|
|
|
|
可以用 BusyBox `crond` 定时更新,例如每 15 分钟执行一次:
|
|
可以用 BusyBox `crond` 定时更新,例如每 15 分钟执行一次:
|
|
|
|
|
|
|
@@ -446,7 +512,9 @@ curl http://192.168.50.1:8080/current_ip.txt
|
|
|
*/15 * * * * cd /tmp/home/root/vmess-domain-rotator && sh scripts/router_local_update.sh ./router_local.conf >> /tmp/router_local_update.log 2>&1
|
|
*/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 服务如果需要常驻,建议独立后台启动:
|
|
|
|
|
|
|
+### 6.8 手动常驻 HTTP
|
|
|
|
|
+
|
|
|
|
|
+HTTP 服务如果需要手动后台启动:
|
|
|
|
|
|
|
|
```bash
|
|
```bash
|
|
|
cd /tmp/home/root/vmess-domain-rotator
|
|
cd /tmp/home/root/vmess-domain-rotator
|
|
@@ -512,5 +580,5 @@ cat cfip_runtime/current_ip.json
|
|
|
2. `run_update_and_commit.sh` 设计目标是服务器模式;路由器模式默认不走 git 提交。
|
|
2. `run_update_and_commit.sh` 设计目标是服务器模式;路由器模式默认不走 git 提交。
|
|
|
3. 服务器模式下,service 用户和 git 凭证用户必须一致,否则会出现 `terminal prompts disabled`。
|
|
3. 服务器模式下,service 用户和 git 凭证用户必须一致,否则会出现 `terminal prompts disabled`。
|
|
|
4. `credential.helper store` 是明文存储,只适合可控服务器。
|
|
4. `credential.helper store` 是明文存储,只适合可控服务器。
|
|
|
-5. BusyBox 路由器模式下,`nc`、`mkfifo`、`awk` 的行为依赖 BusyBox 版本,建议在目标设备上实测。
|
|
|
|
|
|
|
+5. BusyBox 路由器模式下,`router_local_update.sh` 只依赖常见基础 applet;HTTP 暴露会优先调用 `BUSYBOX_BIN` 指向的完整 BusyBox `httpd`,不要依赖 ASUS `/usr/sbin/httpd` 或系统精简 `nc`。
|
|
|
6. `state.json` 需要持久化,否则 fallback 不可用。
|
|
6. `state.json` 需要持久化,否则 fallback 不可用。
|