From dac68f78b4c37863393761d90c977c49f848b1bb Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Mon, 16 Mar 2026 11:49:07 +0800 Subject: [PATCH] fix: clawd-rfkill.service failed due to systemd $ expansion systemd expands $rf as env var (empty), breaking the inline script. Move rfkill logic to standalone script to avoid escaping issues. Also use quoted heredoc to prevent bash expansion in install.sh. Made-with: Cursor --- .commitmsg | 8 ++++---- install.sh | 29 ++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.commitmsg b/.commitmsg index b07c924..5ee0910 100644 --- a/.commitmsg +++ b/.commitmsg @@ -1,5 +1,5 @@ -fix: kill NetworkManager's dnsmasq before starting our own +fix: clawd-rfkill.service failed due to systemd $ expansion -NetworkManager auto-starts its own dnsmasq when creating a hotspot, -which conflicts with our DNS-hijacking dnsmasq on the same interface. -Now kill ALL dnsmasq instances before starting ours. +systemd expands $rf as env var (empty), breaking the inline script. +Move rfkill logic to standalone script to avoid escaping issues. +Also use quoted heredoc to prevent bash expansion in install.sh. diff --git a/install.sh b/install.sh index 7155a94..cf6e68c 100644 --- a/install.sh +++ b/install.sh @@ -67,10 +67,22 @@ for rf in /sys/class/rfkill/rfkill*; do fi done -# 持久化:创建 systemd 服务确保开机自动解锁 WiFi +# 持久化:独立脚本 + systemd 服务,确保开机自动解锁 WiFi +RFKILL_SCRIPT="/usr/local/bin/clawd-unblock-wifi.sh" +cat > "$RFKILL_SCRIPT" << 'SCRIPT' +#!/bin/sh +for rf in /sys/class/rfkill/rfkill*; do + [ -f "$rf/type" ] || continue + if [ "$(cat "$rf/type")" = "wlan" ] && [ "$(cat "$rf/soft")" = "1" ]; then + echo 0 > "$rf/soft" + echo "clawd-rfkill: unblocked $(basename "$rf")" + fi +done +SCRIPT +chmod +x "$RFKILL_SCRIPT" + RFKILL_SERVICE="/etc/systemd/system/clawd-rfkill.service" -if [ ! -f "$RFKILL_SERVICE" ]; then - cat > "$RFKILL_SERVICE" < "$RFKILL_SERVICE" << 'UNIT' [Unit] Description=Unblock WiFi for clawd Before=NetworkManager.service clawd.service @@ -78,16 +90,15 @@ 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' +ExecStart=/usr/local/bin/clawd-unblock-wifi.sh RemainAfterExit=yes [Install] WantedBy=multi-user.target -EOF - systemctl daemon-reload - systemctl enable clawd-rfkill - info "WiFi rfkill 解锁服务已创建(开机自动执行)✓" -fi +UNIT +systemctl daemon-reload +systemctl enable clawd-rfkill +info "WiFi rfkill 解锁服务已创建 ✓" # ── 安装 clawd ─────────────────────────────────────────────────────────────── INSTALL_DIR="/opt/clawd"