From 8a6e5b3666d2dd76cce9f64743983eb44cd9962c Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Mon, 16 Mar 2026 10:06:30 +0800 Subject: [PATCH] fix: dnsmasq path detection and WiFi rfkill persistence - dns-hijack.js: replace `which` with multi-path search (/usr/sbin etc.) since dnsmasq is often not in normal user PATH - install.sh: auto-enable NetworkManager for WiFi provisioning - install.sh: unblock WiFi rfkill at install time - install.sh: create clawd-rfkill.service for persistent boot-time unlock Made-with: Cursor --- .commitmsg | 7 +++++++ install.sh | 41 +++++++++++++++++++++++++++++++++++++++++ lib/dns-hijack.js | 21 ++++++++++++++++----- 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 .commitmsg diff --git a/.commitmsg b/.commitmsg new file mode 100644 index 0000000..a53b206 --- /dev/null +++ b/.commitmsg @@ -0,0 +1,7 @@ +fix: dnsmasq path detection and WiFi rfkill persistence + +- dns-hijack.js: replace `which` with multi-path search (/usr/sbin etc.) + since dnsmasq is often not in normal user PATH +- install.sh: auto-enable NetworkManager for WiFi provisioning +- install.sh: unblock WiFi rfkill at install time +- install.sh: create clawd-rfkill.service for persistent boot-time unlock diff --git a/install.sh b/install.sh index 861be15..7155a94 100644 --- a/install.sh +++ b/install.sh @@ -48,6 +48,47 @@ if command -v dnsmasq &>/dev/null; then info "dnsmasq ✓" fi +# ── 启用 NetworkManager(WiFi 配网需要)────────────────────────────────────── +if command -v nmcli &>/dev/null; then + if ! systemctl is-active --quiet NetworkManager 2>/dev/null; then + info "启用 NetworkManager..." + systemctl enable --now NetworkManager 2>/dev/null || true + fi + info "NetworkManager ✓" +fi + +# ── WiFi rfkill 解锁(部分设备默认禁用 WiFi)──────────────────────────────── +for rf in /sys/class/rfkill/rfkill*; do + if [ -f "$rf/type" ] && [ "$(cat "$rf/type")" = "wlan" ]; then + if [ "$(cat "$rf/soft")" = "1" ]; then + info "解锁 WiFi ($(basename "$rf"))..." + echo 0 > "$rf/soft" + fi + fi +done + +# 持久化:创建 systemd 服务确保开机自动解锁 WiFi +RFKILL_SERVICE="/etc/systemd/system/clawd-rfkill.service" +if [ ! -f "$RFKILL_SERVICE" ]; then + cat > "$RFKILL_SERVICE" < \$rf/soft; done' +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target +EOF + systemctl daemon-reload + systemctl enable clawd-rfkill + info "WiFi rfkill 解锁服务已创建(开机自动执行)✓" +fi + # ── 安装 clawd ─────────────────────────────────────────────────────────────── INSTALL_DIR="/opt/clawd" CONFIG_DIR="/etc/clawd" diff --git a/lib/dns-hijack.js b/lib/dns-hijack.js index ac8d8cb..f805be9 100644 --- a/lib/dns-hijack.js +++ b/lib/dns-hijack.js @@ -64,15 +64,14 @@ class DnsHijack { // 终止系统可能残留的 dnsmasq try { execSync('pkill -f "dnsmasq.*clawd"', { timeout: 3000 }); } catch (_) {} - // 检查 dnsmasq 是否安装 - try { - execSync('which dnsmasq', { timeout: 3000 }); - } catch (_) { + // 查找 dnsmasq 二进制(/usr/sbin 可能不在普通用户 PATH 中) + const dnsmasqBin = findBin('dnsmasq'); + if (!dnsmasqBin) { log.error('dns', 'dnsmasq 未安装,请运行: apt install dnsmasq'); return; } - this._watchdog = new Watchdog('dns', 'dnsmasq', [ + this._watchdog = new Watchdog('dns', dnsmasqBin, [ '--no-daemon', `--conf-file=${DNSMASQ_CONF}`, ], { @@ -96,4 +95,16 @@ class DnsHijack { } } +function findBin(name) { + const searchPaths = ['/usr/sbin', '/usr/bin', '/sbin', '/bin', '/usr/local/sbin', '/usr/local/bin']; + for (const dir of searchPaths) { + const full = path.join(dir, name); + if (fs.existsSync(full)) return full; + } + // 兜底尝试 which(PATH 可能已包含) + try { + return execSync(`which ${name}`, { encoding: 'utf8', timeout: 3000 }).trim() || null; + } catch (_) { return null; } +} + module.exports = { DnsHijack, CAPTIVE_DOMAIN };