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
This commit is contained in:
7
.commitmsg
Normal file
7
.commitmsg
Normal file
@@ -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
|
||||||
41
install.sh
41
install.sh
@@ -48,6 +48,47 @@ if command -v dnsmasq &>/dev/null; then
|
|||||||
info "dnsmasq ✓"
|
info "dnsmasq ✓"
|
||||||
fi
|
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" <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Unblock WiFi for clawd
|
||||||
|
Before=NetworkManager.service clawd.service
|
||||||
|
After=sys-subsystem-net-devices-wlan0.device
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/bin/sh -c 'for rf in /sys/class/rfkill/rfkill*; do [ "\$(cat \$rf/type)" = "wlan" ] && echo 0 > \$rf/soft; done'
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable clawd-rfkill
|
||||||
|
info "WiFi rfkill 解锁服务已创建(开机自动执行)✓"
|
||||||
|
fi
|
||||||
|
|
||||||
# ── 安装 clawd ───────────────────────────────────────────────────────────────
|
# ── 安装 clawd ───────────────────────────────────────────────────────────────
|
||||||
INSTALL_DIR="/opt/clawd"
|
INSTALL_DIR="/opt/clawd"
|
||||||
CONFIG_DIR="/etc/clawd"
|
CONFIG_DIR="/etc/clawd"
|
||||||
|
|||||||
@@ -64,15 +64,14 @@ class DnsHijack {
|
|||||||
// 终止系统可能残留的 dnsmasq
|
// 终止系统可能残留的 dnsmasq
|
||||||
try { execSync('pkill -f "dnsmasq.*clawd"', { timeout: 3000 }); } catch (_) {}
|
try { execSync('pkill -f "dnsmasq.*clawd"', { timeout: 3000 }); } catch (_) {}
|
||||||
|
|
||||||
// 检查 dnsmasq 是否安装
|
// 查找 dnsmasq 二进制(/usr/sbin 可能不在普通用户 PATH 中)
|
||||||
try {
|
const dnsmasqBin = findBin('dnsmasq');
|
||||||
execSync('which dnsmasq', { timeout: 3000 });
|
if (!dnsmasqBin) {
|
||||||
} catch (_) {
|
|
||||||
log.error('dns', 'dnsmasq 未安装,请运行: apt install dnsmasq');
|
log.error('dns', 'dnsmasq 未安装,请运行: apt install dnsmasq');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._watchdog = new Watchdog('dns', 'dnsmasq', [
|
this._watchdog = new Watchdog('dns', dnsmasqBin, [
|
||||||
'--no-daemon',
|
'--no-daemon',
|
||||||
`--conf-file=${DNSMASQ_CONF}`,
|
`--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 };
|
module.exports = { DnsHijack, CAPTIVE_DOMAIN };
|
||||||
|
|||||||
Reference in New Issue
Block a user