Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ Android 版目前走的是 DNS 代理接管方案:
桌面端默认提供:

- `开始加速 / 停止加速`
- `恢复 hosts / 彻底恢复原始状态`
- 一键最小化
- 错误详情展示
- 状态与最近操作日志展示
- 当前上游、DoH、证书和域名接管范围预览
- 配置和关于面板

Expand Down Expand Up @@ -134,6 +135,28 @@ cargo run --bin linuxdo-accelerator -- init-config
sudo cargo run --bin linuxdo-accelerator -- setup
```

仅准备 `hosts` 规则:

```bash
sudo cargo run --bin linuxdo-accelerator -- apply-hosts
```

手动确保首次 `hosts` 基线备份存在:

```bash
cargo run --bin linuxdo-accelerator -- backup-hosts
```

恢复到首次接管前的 `hosts` 完整备份:

```bash
sudo cargo run --bin linuxdo-accelerator -- restore-hosts
```

> `backup-hosts` 默认只创建**首次基线备份**,不会覆盖已有备份。
> `clean-hosts` / `restore-hosts` 仅适合在加速服务已停止时使用;
> 如果目标是“尽量完整回到初始状态”,优先使用 `cleanup`。

前台直接启动:

```bash
Expand Down Expand Up @@ -176,6 +199,9 @@ linuxdo-accelerator --config /path/to/linuxdo-accelerator.toml
```

程序会改用该配置文件;对应的 `runtime` 和 `certs` 目录也会优先跟着这个配置目录走。
`runtime` 目录中还会保存 `hosts.backup` 与 `hosts.backup.json`,用于完整恢复首次接管前的
`hosts` 内容与原始文件属性。
此外还会写入 `operations.log`,记录启动、停止、恢复和清理等关键操作结果,便于排查问题。

## Config Example

Expand Down Expand Up @@ -207,7 +233,7 @@ server_common_name = "linux.do"
- `linuxdo-accelerator`
- 默认直接打开桌面 GUI
- 传入命令参数后作为 CLI 使用
- 负责 `setup / start / stop / status / gui` 等命令
- 负责 `setup / apply-hosts / backup-hosts / restore-hosts / start / stop / status / gui` 等命令
- Windows 下打包为可双击启动的 `.exe`
- Linux 下由 `.desktop` 启动
- macOS 下打包为 `.app / .dmg`
Expand Down Expand Up @@ -279,6 +305,16 @@ macOS 不再走本地交叉编译脚本,而是通过 GitHub Actions 原生构
- macOS 本机编译与窗口最小化恢复链路
- 证书、`hosts` 和运行状态文件统一管理

## Hosts Safety Notes

- 首次写入系统 `hosts` 前,会在 `runtime` 目录自动创建完整备份
- `clean-hosts` 只删除 `linuxdo-accelerator` 自己维护的 marker block
- `restore-hosts` 会用完整备份覆盖当前 `hosts`,适合停止使用后的显式恢复
- `cleanup` 会优先尝试恢复首次接管前的完整备份;如果完整备份缺失、损坏、状态异常或恢复失败,会退化为仅清理 marker block;遇到损坏 / 异常备份时还会顺带清掉失效备份,避免后续继续卡在错误状态
- Windows 下会在写入前自动处理 `hosts` 的只读属性,并在写入后恢复原始文件属性
- Windows 下对 `hosts` 原子替换增加了共享冲突重试,降低杀软 / 系统进程短暂占用导致的恢复失败概率
- 当前恢复范围以 `hosts` 内容与常见文件属性为主,不额外恢复自定义 ACL / owner

## Inspirations

- [docmirror/dev-sidecar](https://github.com/docmirror/dev-sidecar)
Expand Down
16 changes: 13 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::path::PathBuf;
use anyhow::Result;
use clap::{Parser, Subcommand};

use crate::config::AppConfig;
#[cfg(any(windows, target_os = "linux", target_os = "macos"))]
use crate::gui;
use crate::config::AppConfig;
use crate::service;

#[derive(Debug, Parser)]
Expand All @@ -30,6 +30,8 @@ pub enum Command {
Status,
CleanHosts,
ApplyHosts,
BackupHosts,
RestoreHosts,
UninstallCert,
Cleanup,
#[command(hide = true)]
Expand All @@ -49,8 +51,8 @@ pub async fn run(cli: Cli) -> Result<()> {
None | Some(Command::Gui) => {
#[cfg(any(windows, target_os = "linux", target_os = "macos"))]
{
let config_path = service::init_config(cli.config.clone())?;
gui::run(config_path)?;
let config_path = service::init_config(cli.config.clone())?;
gui::run(config_path)?;
}
#[cfg(target_os = "android")]
{
Expand Down Expand Up @@ -87,6 +89,14 @@ pub async fn run(cli: Cli) -> Result<()> {
service::apply_hosts_only(cli.config)?;
println!("hosts applied");
}
Some(Command::BackupHosts) => {
service::backup_hosts(cli.config)?;
println!("hosts backup ready");
}
Some(Command::RestoreHosts) => {
service::restore_hosts(cli.config)?;
println!("hosts restored");
}
Some(Command::UninstallCert) => {
service::uninstall_certificate(cli.config)?;
println!("certificate removed");
Expand Down
Loading
Loading