fix: add /etc/hosts /etc/hostname to systemd ReadWritePaths; bump v1.2.5

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
stswangzhiping
2026-05-04 18:14:14 +08:00
parent 9e67969fd1
commit 8990d48d51
2 changed files with 78 additions and 68 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# clawd one-click install script
# Usage: curl -fsSL https://git.cutos.ai/claw-daemon/clawd/raw/branch/main/install.sh | sudo bash
# Requires root and Node.js >= 18
#!/usr/bin/env bash
# clawd ??????
# ???curl -fsSL https://git.cutos.ai/claw-daemon/clawd/raw/branch/main/install.sh | sudo bash
# ?? root ???????? Node.js >= 18
set -e
@@ -11,26 +11,26 @@ info() { echo -e "${GREEN}[clawd]${NC} $*"; }
warn() { echo -e "${YELLOW}[clawd]${NC} $*"; }
error() { echo -e "${RED}[clawd]${NC} $*"; exit 1; }
# -- check root
# ?? ?? root ????????????????????????????????????????????????????????????????
if [ "$EUID" -ne 0 ]; then
error "Please run as root: sudo bash install.sh"
error "?? root ?????sudo bash install.sh?"
fi
# -- check Node.js
# ?? ?? Node.js ?????????????????????????????????????????????????????????????
if ! command -v node &>/dev/null; then
error "Node.js not found. Please install Node.js >= 18 first."
error "??? Node.js????? Node.js >= 18"
fi
NODE_VER=$(node -e "process.stdout.write(process.versions.node)")
MAJOR=$(echo "$NODE_VER" | cut -d. -f1)
if [ "$MAJOR" -lt 18 ]; then
error "Node.js version too low (current: $NODE_VER). Need >= 18."
error "Node.js ??????? $NODE_VER???? >= 18"
fi
info "Node.js $NODE_VER OK"
info "Node.js $NODE_VER ?"
# -- install dnsmasq (needed for WiFi provisioning)
# ?? ??/?? dnsmasq?WiFi ???????????????????????????????????????????
if ! command -v dnsmasq &>/dev/null; then
info "Installing dnsmasq..."
info "?? dnsmasq?WiFi ?????..."
if command -v apt-get &>/dev/null; then
apt-get install -y -qq dnsmasq >/dev/null 2>&1
elif command -v yum &>/dev/null; then
@@ -38,23 +38,25 @@ if ! command -v dnsmasq &>/dev/null; then
elif command -v apk &>/dev/null; then
apk add --quiet dnsmasq >/dev/null 2>&1
else
warn "Cannot auto-install dnsmasq. WiFi provisioning may not work."
warn "?????? dnsmasq?WiFi ?????????"
fi
# ?? dnsmasq ???????clawd ?????
systemctl disable dnsmasq 2>/dev/null || true
systemctl stop dnsmasq 2>/dev/null || true
fi
if command -v dnsmasq &>/dev/null; then
info "dnsmasq OK"
info "dnsmasq ?"
fi
# -- enable NetworkManager
# ?? ?? NetworkManager?WiFi ???????????????????????????????????????????
if command -v nmcli &>/dev/null; then
if ! systemctl is-active --quiet NetworkManager 2>/dev/null; then
info "Enabling NetworkManager..."
info "?? NetworkManager..."
systemctl enable --now NetworkManager 2>/dev/null || true
fi
info "NetworkManager OK"
info "NetworkManager ?"
# ?? DNS ???????? /etc ??????
NM_DNSMASQ_DIR="/etc/NetworkManager/dnsmasq-shared.d"
mkdir -p "$NM_DNSMASQ_DIR"
cat > "$NM_DNSMASQ_DIR/clawd-captive.conf" << 'DNSCONF'
@@ -62,19 +64,20 @@ if command -v nmcli &>/dev/null; then
# All DNS queries resolve to gateway to trigger captive portal
address=/#/10.42.0.1
DNSCONF
info "DNS hijack config written to $NM_DNSMASQ_DIR"
info "DNS ??????? $NM_DNSMASQ_DIR ?"
fi
# -- WiFi rfkill unblock
# ?? 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 "Unblocking WiFi ($(basename "$rf"))..."
info "?? WiFi ($(basename "$rf"))..."
echo 0 > "$rf/soft"
fi
fi
done
# ???????? + systemd ??????????? WiFi
RFKILL_SCRIPT="/usr/local/bin/clawd-unblock-wifi.sh"
cat > "$RFKILL_SCRIPT" << 'SCRIPT'
#!/bin/sh
@@ -105,40 +108,39 @@ WantedBy=multi-user.target
UNIT
systemctl daemon-reload
systemctl enable clawd-rfkill
info "WiFi rfkill service created"
info "WiFi rfkill ??????? ?"
# -- install ttyd
info "Installing ttyd..."
# ?? ?? ttyd?Web ???????????????????????????????????????????????????????
info "?? ttyd..."
if apt-get install -y ttyd >/dev/null 2>&1; then
info "ttyd installed"
info "ttyd ??? ?"
else
warn "ttyd install failed. Web terminal may not be available."
warn "ttyd ?????Web ????????"
fi
# -- install clawd
# ?? ?? clawd ???????????????????????????????????????????????????????????????
INSTALL_DIR="/opt/clawd"
CONFIG_DIR="/etc/clawd"
ENV_FILE="$CONFIG_DIR/env"
CUTOS_REPO="https://git.cutos.ai/claw-daemon/clawd.git"
info "Installing to $INSTALL_DIR ..."
info "??? $INSTALL_DIR ..."
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
# Download source (prioritise .git repo update over package.json skip)
# ?????????? package.json?????/???????? git/tarball?
CUTOS_REPO="https://git.cutos.ai/claw-daemon/clawd.git"
if command -v git &>/dev/null && [ -d ".git" ]; then
# Migrate remote from GitHub to git.cutos.ai if needed
CURRENT_REMOTE=$(git remote get-url origin 2>/dev/null || echo "")
if echo "$CURRENT_REMOTE" | grep -q "github.com"; then
info "Migrating git remote to git.cutos.ai ..."
info "?? git remote ? git.cutos.ai ..."
git remote set-url origin "$CUTOS_REPO"
fi
info "Pulling latest code..."
info "??????..."
git fetch origin
git reset --hard origin/main
git clean -fd
elif [ -f "package.json" ]; then
info "Source already present (no .git). Skipping download."
info "????????? git??????"
elif command -v git &>/dev/null; then
git clone --depth=1 "$CUTOS_REPO" .
else
@@ -146,18 +148,18 @@ else
curl -fsSL "$TARBALL_URL" | tar -xz --strip-components=1
fi
# install npm deps
info "Installing npm dependencies..."
# ????
info "?? npm ??..."
npm install --omit=dev --silent
# create symlink
# ???????
ln -sf "$INSTALL_DIR/bin/clawd.js" /usr/local/bin/clawd
chmod +x "$INSTALL_DIR/bin/clawd.js"
info "clawd installed to /usr/local/bin/clawd"
info "clawd ???? /usr/local/bin/clawd ?"
# -- create config dir + env file
# ?? ?????? + ?????? ??????????????????????????????????????????????
mkdir -p "$CONFIG_DIR"
if [ ! -f "$CONFIG_DIR/config.json" ]; then
@@ -169,36 +171,36 @@ if [ ! -f "$CONFIG_DIR/config.json" ]; then
"heartbeat_interval": 30
}
EOF
info "Config file created: $CONFIG_DIR/config.json"
info "????????$CONFIG_DIR/config.json ?"
fi
if [ ! -f "$ENV_FILE" ]; then
cat > "$ENV_FILE" <<EOF
# clawd environment variables (systemd EnvironmentFile)
# Log level: debug / info / warn / error
# clawd ?????systemd EnvironmentFile?
# ????: debug / info / warn / error
CLAWD_LOG_LEVEL=info
# Write log file (0 = journald only)
# ????????0=? journald?
CLAWD_LOG_FILE=1
# Custom server address (leave empty to read from config.json)
# ????????????? config.json?
# CLAWD_SERVER=wss://claw.cutos.ai/ws
# BtMonitor (bluetoothctl) is disabled by default.
# Uncomment to enable Bluetooth LED:
# BtMonitor?bluetoothctl??????????????? CLAWD_DISABLE_BT?
# ???????????????????
# CLAWD_ENABLE_BT=1
# OpenVFD sysfs path (default: /sys/class/leds/openvfd)
# OpenVFD sysfs ?????? /sys/class/leds/openvfd?
# CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd
# VFD service pipe (default: /tmp/openvfd_service)
# ??? vfdservice ????? /tmp/openvfd_service?
# CLAWD_VFD_PIPE=/tmp/openvfd_service
# Fixed LAN interface for multi-port boards
# ???/??????? LAN ???????????? clawd ?????? carrier ??
# CLAWD_ETH_IFACE=end0
EOF
info "Env file created: $ENV_FILE"
info "??????????$ENV_FILE ?"
fi
# -- create log dir
# ?? ?????? ?????????????????????????????????????????????????????????????
mkdir -p "$CONFIG_DIR/logs"
info "Log dir: $CONFIG_DIR/logs"
info "?????$CONFIG_DIR/logs ?"
# -- create systemd service
# ?? ?? systemd service ????????????????????????????????????????????????????
NODE_BIN=$(command -v node)
SERVICE_FILE="/etc/systemd/system/clawd.service"
@@ -211,70 +213,78 @@ Wants=NetworkManager.service
[Service]
Type=simple
# systemd-notify ????????? NotifyAccess=main ????? all ??? WatchdogSec
NotifyAccess=all
EnvironmentFile=$ENV_FILE
ExecStart=$NODE_BIN $INSTALL_DIR/bin/clawd.js
WorkingDirectory=$INSTALL_DIR
# ????
Restart=always
RestartSec=5
# ?? systemd ?? StartLimitIntervalSec?? StartLimitInterval=???
StartLimitInterval=300
StartLimitBurst=10
# ?????10s ? SIGTERM??? SIGKILL?
TimeoutStopSec=10
KillMode=mixed
KillSignal=SIGTERM
# ??????????
MemoryMax=256M
CPUQuota=50%
TasksMax=64
# ?????ttyd ????? setuid sudo???? NoNewPrivileges/strict?
ProtectSystem=full
ReadWritePaths=$CONFIG_DIR /tmp
ReadWritePaths=$CONFIG_DIR /tmp /etc/hosts /etc/hostname
# ??
StandardOutput=journal
StandardError=journal
SyslogIdentifier=clawd
# systemd Watchdog?60s ????????
WatchdogSec=60
[Install]
WantedBy=multi-user.target
EOF
info "systemd service file created"
info "systemd ??????? ?"
# -- journald log limits
# ?? journald ???????? ????????????????????????????????????????????????
JOURNAL_CONF="/etc/systemd/journald.conf.d/clawd.conf"
if [ ! -f "$JOURNAL_CONF" ]; then
mkdir -p /etc/systemd/journald.conf.d
cat > "$JOURNAL_CONF" <<EOF
# clawd journald limits
# clawd journald ??
[Journal]
SystemMaxUse=100M
MaxFileSec=7day
EOF
systemctl restart systemd-journald 2>/dev/null || true
info "journald limits configured"
info "journald ??????? ?"
fi
# -- enable and start
# ?? ????? ??????????????????????????????????????????????????????????????
systemctl daemon-reload
systemctl enable clawd
systemctl restart clawd
sleep 2
if systemctl is-active --quiet clawd; then
info "clawd service is running"
info "clawd ????? ?"
echo ""
echo " View logs: journalctl -u clawd -f"
echo " View status: systemctl status clawd"
echo " Stop: systemctl stop clawd"
echo " Config: $CONFIG_DIR/config.json"
echo " Env vars: $ENV_FILE"
echo " Log file: $CONFIG_DIR/logs/clawd.log"
echo " ????? journalctl -u clawd -f"
echo " ????? systemctl status clawd"
echo " ????? systemctl stop clawd"
echo " ????? $CONFIG_DIR/config.json"
echo " ????? $ENV_FILE"
echo " ????? $CONFIG_DIR/logs/clawd.log"
echo ""
else
warn "Service failed to start. Check logs:"
warn "?????????????"
echo " journalctl -u clawd -n 50 --no-pager"
fi
fi

View File

@@ -1,6 +1,6 @@
{
"name": "clawd",
"version": "1.2.4",
"version": "1.2.5",
"description": "Claw Box daemon - connects local Linux box to claw.cutos.ai via WebSocket",
"main": "lib/client.js",
"bin": {