fix: rewrite install.sh in ASCII English to fix garbled characters

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
stswangzhiping
2026-05-11 10:06:17 +08:00
parent cdf2a5f5ac
commit c9597cf1a0

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# clawd ?????? # clawd installer
# ???curl -fsSL https://git.cutos.ai/claw-daemon/clawd/raw/branch/main/install.sh | sudo bash # Run: curl -fsSL https://git.cutos.ai/claw-daemon/clawd/raw/branch/main/install.sh | sudo bash
# ?? root ???????? Node.js >= 18 # Requires root and Node.js >= 18
set -e set -e
@@ -11,26 +11,26 @@ info() { echo -e "${GREEN}[clawd]${NC} $*"; }
warn() { echo -e "${YELLOW}[clawd]${NC} $*"; } warn() { echo -e "${YELLOW}[clawd]${NC} $*"; }
error() { echo -e "${RED}[clawd]${NC} $*"; exit 1; } error() { echo -e "${RED}[clawd]${NC} $*"; exit 1; }
# ?? ?? root ???????????????????????????????????????????????????????????????? # Check root
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
error "?? root ?????sudo bash install.sh?" error "Please run as root: sudo bash install.sh"
fi fi
# ?? ?? Node.js ????????????????????????????????????????????????????????????? # Check Node.js
if ! command -v node &>/dev/null; then if ! command -v node &>/dev/null; then
error "??? Node.js????? Node.js >= 18" error "Node.js not found. Please install Node.js >= 18"
fi fi
NODE_VER=$(node -e "process.stdout.write(process.versions.node)") NODE_VER=$(node -e "process.stdout.write(process.versions.node)")
MAJOR=$(echo "$NODE_VER" | cut -d. -f1) MAJOR=$(echo "$NODE_VER" | cut -d. -f1)
if [ "$MAJOR" -lt 18 ]; then if [ "$MAJOR" -lt 18 ]; then
error "Node.js ??????? $NODE_VER???? >= 18" error "Node.js version $NODE_VER is too old. Requires >= 18"
fi fi
info "Node.js $NODE_VER ?" info "Node.js $NODE_VER OK"
# ?? ??/?? dnsmasq?WiFi ??????????????????????????????????????????? # Install dnsmasq (required for WiFi captive portal)
if ! command -v dnsmasq &>/dev/null; then if ! command -v dnsmasq &>/dev/null; then
info "?? dnsmasq?WiFi ?????..." info "Installing dnsmasq for WiFi captive portal..."
if command -v apt-get &>/dev/null; then if command -v apt-get &>/dev/null; then
apt-get install -y -qq dnsmasq >/dev/null 2>&1 apt-get install -y -qq dnsmasq >/dev/null 2>&1
elif command -v yum &>/dev/null; then elif command -v yum &>/dev/null; then
@@ -38,25 +38,25 @@ if ! command -v dnsmasq &>/dev/null; then
elif command -v apk &>/dev/null; then elif command -v apk &>/dev/null; then
apk add --quiet dnsmasq >/dev/null 2>&1 apk add --quiet dnsmasq >/dev/null 2>&1
else else
warn "?????? dnsmasq?WiFi ?????????" warn "Cannot install dnsmasq. WiFi captive portal may not work."
fi fi
# ?? dnsmasq ???????clawd ????? # Disable system dnsmasq; clawd manages it directly
systemctl disable dnsmasq 2>/dev/null || true systemctl disable dnsmasq 2>/dev/null || true
systemctl stop dnsmasq 2>/dev/null || true systemctl stop dnsmasq 2>/dev/null || true
fi fi
if command -v dnsmasq &>/dev/null; then if command -v dnsmasq &>/dev/null; then
info "dnsmasq ?" info "dnsmasq OK"
fi fi
# ?? ?? NetworkManager?WiFi ??????????????????????????????????????????? # Configure NetworkManager for WiFi
if command -v nmcli &>/dev/null; then if command -v nmcli &>/dev/null; then
if ! systemctl is-active --quiet NetworkManager 2>/dev/null; then if ! systemctl is-active --quiet NetworkManager 2>/dev/null; then
info "?? NetworkManager..." info "Starting NetworkManager..."
systemctl enable --now NetworkManager 2>/dev/null || true systemctl enable --now NetworkManager 2>/dev/null || true
fi fi
info "NetworkManager ?" info "NetworkManager OK"
# ?? DNS ???????? /etc ?????? # Write captive-portal DNS config
NM_DNSMASQ_DIR="/etc/NetworkManager/dnsmasq-shared.d" NM_DNSMASQ_DIR="/etc/NetworkManager/dnsmasq-shared.d"
mkdir -p "$NM_DNSMASQ_DIR" mkdir -p "$NM_DNSMASQ_DIR"
cat > "$NM_DNSMASQ_DIR/clawd-captive.conf" << 'DNSCONF' cat > "$NM_DNSMASQ_DIR/clawd-captive.conf" << 'DNSCONF'
@@ -64,20 +64,20 @@ if command -v nmcli &>/dev/null; then
# All DNS queries resolve to gateway to trigger captive portal # All DNS queries resolve to gateway to trigger captive portal
address=/#/10.42.0.1 address=/#/10.42.0.1
DNSCONF DNSCONF
info "DNS ??????? $NM_DNSMASQ_DIR ?" info "DNS captive config written to $NM_DNSMASQ_DIR"
fi fi
# ?? WiFi rfkill ??????????? WiFi????????????????????????????????? # Unblock WiFi via rfkill
for rf in /sys/class/rfkill/rfkill*; do for rf in /sys/class/rfkill/rfkill*; do
if [ -f "$rf/type" ] && [ "$(cat "$rf/type")" = "wlan" ]; then if [ -f "$rf/type" ] && [ "$(cat "$rf/type")" = "wlan" ]; then
if [ "$(cat "$rf/soft")" = "1" ]; then if [ "$(cat "$rf/soft")" = "1" ]; then
info "?? WiFi ($(basename "$rf"))..." info "Unblocking WiFi ($(basename "$rf"))..."
echo 0 > "$rf/soft" echo 0 > "$rf/soft"
fi fi
fi fi
done done
# ???????? + systemd ??????????? WiFi # Install rfkill unblock script + systemd unit for persistence
RFKILL_SCRIPT="/usr/local/bin/clawd-unblock-wifi.sh" RFKILL_SCRIPT="/usr/local/bin/clawd-unblock-wifi.sh"
cat > "$RFKILL_SCRIPT" << 'SCRIPT' cat > "$RFKILL_SCRIPT" << 'SCRIPT'
#!/bin/sh #!/bin/sh
@@ -108,39 +108,39 @@ WantedBy=multi-user.target
UNIT UNIT
systemctl daemon-reload systemctl daemon-reload
systemctl enable clawd-rfkill systemctl enable clawd-rfkill
info "WiFi rfkill ??????? ?" info "WiFi rfkill service installed"
# ?? ?? ttyd?Web ??????????????????????????????????????????????????????? # Install ttyd (Web terminal)
info "?? ttyd..." info "Installing ttyd..."
if apt-get install -y ttyd >/dev/null 2>&1; then if apt-get install -y ttyd >/dev/null 2>&1; then
info "ttyd ??? ?" info "ttyd installed OK"
else else
warn "ttyd ?????Web ????????" warn "ttyd install failed. Web terminal will not be available."
fi fi
# ?? ?? clawd ??????????????????????????????????????????????????????????????? # Clone / update clawd
INSTALL_DIR="/opt/clawd" INSTALL_DIR="/opt/clawd"
CONFIG_DIR="/etc/clawd" CONFIG_DIR="/etc/clawd"
ENV_FILE="$CONFIG_DIR/env" ENV_FILE="$CONFIG_DIR/env"
info "??? $INSTALL_DIR ..." info "Setting up $INSTALL_DIR ..."
mkdir -p "$INSTALL_DIR" mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR" cd "$INSTALL_DIR"
# ?????????? package.json?????/???????? git/tarball? # Use git if available, fall back to tarball
CUTOS_REPO="https://git.cutos.ai/claw-daemon/clawd.git" CUTOS_REPO="https://git.cutos.ai/claw-daemon/clawd.git"
if command -v git &>/dev/null && [ -d ".git" ]; then if command -v git &>/dev/null && [ -d ".git" ]; then
CURRENT_REMOTE=$(git remote get-url origin 2>/dev/null || echo "") CURRENT_REMOTE=$(git remote get-url origin 2>/dev/null || echo "")
if echo "$CURRENT_REMOTE" | grep -q "github.com"; then if echo "$CURRENT_REMOTE" | grep -q "github.com"; then
info "?? git remote ? git.cutos.ai ..." info "Migrating git remote to git.cutos.ai ..."
git remote set-url origin "$CUTOS_REPO" git remote set-url origin "$CUTOS_REPO"
fi fi
info "??????..." info "Pulling latest code..."
git fetch origin git fetch origin
git reset --hard origin/main git reset --hard origin/main
git clean -fd git clean -fd
elif [ -f "package.json" ]; then elif [ -f "package.json" ]; then
info "????????? git??????" info "Files already present, skipping git clone"
elif command -v git &>/dev/null; then elif command -v git &>/dev/null; then
git clone --depth=1 "$CUTOS_REPO" . git clone --depth=1 "$CUTOS_REPO" .
else else
@@ -148,18 +148,18 @@ else
curl -fsSL "$TARBALL_URL" | tar -xz --strip-components=1 curl -fsSL "$TARBALL_URL" | tar -xz --strip-components=1
fi fi
# ???? # Install npm dependencies
info "?? npm ??..." info "Running npm install..."
npm install --omit=dev --silent npm install --omit=dev --silent
# ??????? # Create symlink
ln -sf "$INSTALL_DIR/bin/clawd.js" /usr/local/bin/clawd ln -sf "$INSTALL_DIR/bin/clawd.js" /usr/local/bin/clawd
chmod +x "$INSTALL_DIR/bin/clawd.js" chmod +x "$INSTALL_DIR/bin/clawd.js"
info "clawd ???? /usr/local/bin/clawd ?" info "clawd symlinked to /usr/local/bin/clawd"
# ?? ?????? + ?????? ?????????????????????????????????????????????? # Write default config files
mkdir -p "$CONFIG_DIR" mkdir -p "$CONFIG_DIR"
if [ ! -f "$CONFIG_DIR/config.json" ]; then if [ ! -f "$CONFIG_DIR/config.json" ]; then
@@ -171,36 +171,35 @@ if [ ! -f "$CONFIG_DIR/config.json" ]; then
"heartbeat_interval": 30 "heartbeat_interval": 30
} }
EOF EOF
info "????????$CONFIG_DIR/config.json ?" info "Default config written to $CONFIG_DIR/config.json"
fi fi
if [ ! -f "$ENV_FILE" ]; then if [ ! -f "$ENV_FILE" ]; then
cat > "$ENV_FILE" <<EOF cat > "$ENV_FILE" <<EOF
# clawd ?????systemd EnvironmentFile? # clawd environment (loaded by systemd EnvironmentFile)
# ????: debug / info / warn / error # Log level: debug / info / warn / error
CLAWD_LOG_LEVEL=info CLAWD_LOG_LEVEL=info
# ????????0=? journald? # Log to file (0 = journald only)
CLAWD_LOG_FILE=1 CLAWD_LOG_FILE=1
# ????????????? config.json? # Override server URL (default from config.json)
# CLAWD_SERVER=wss://claw.cutos.ai/ws # CLAWD_SERVER=wss://claw.cutos.ai/ws
# BtMonitor?bluetoothctl??????????????? CLAWD_DISABLE_BT? # Enable Bluetooth monitor (bluetoothctl); disabled by default
# ???????????????????
# CLAWD_ENABLE_BT=1 # CLAWD_ENABLE_BT=1
# OpenVFD sysfs ?????? /sys/class/leds/openvfd? # OpenVFD sysfs path (default: /sys/class/leds/openvfd)
# CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd # CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd
# ??? vfdservice ????? /tmp/openvfd_service? # vfdservice pipe path (default: /tmp/openvfd_service)
# CLAWD_VFD_PIPE=/tmp/openvfd_service # CLAWD_VFD_PIPE=/tmp/openvfd_service
# ???/??????? LAN ???????????? clawd ?????? carrier ?? # Wired LAN interface for carrier detection
# CLAWD_ETH_IFACE=end0 # CLAWD_ETH_IFACE=end0
EOF EOF
info "??????????$ENV_FILE ?" info "Default env file written to $ENV_FILE"
fi fi
# ?? ?????? ????????????????????????????????????????????????????????????? # Create log directory
mkdir -p "$CONFIG_DIR/logs" mkdir -p "$CONFIG_DIR/logs"
info "?????$CONFIG_DIR/logs ?" info "Log directory: $CONFIG_DIR/logs"
# ?? ?? systemd service ???????????????????????????????????????????????????? # Write systemd service file
NODE_BIN=$(command -v node) NODE_BIN=$(command -v node)
SERVICE_FILE="/etc/systemd/system/clawd.service" SERVICE_FILE="/etc/systemd/system/clawd.service"
@@ -213,78 +212,77 @@ Wants=NetworkManager.service
[Service] [Service]
Type=simple Type=simple
# systemd-notify ????????? NotifyAccess=main ????? all ??? WatchdogSec # NotifyAccess=all required for systemd-notify with WatchdogSec
NotifyAccess=all NotifyAccess=all
EnvironmentFile=$ENV_FILE EnvironmentFile=$ENV_FILE
ExecStart=$NODE_BIN $INSTALL_DIR/bin/clawd.js ExecStart=$NODE_BIN $INSTALL_DIR/bin/clawd.js
WorkingDirectory=$INSTALL_DIR WorkingDirectory=$INSTALL_DIR
# ???? # Restart policy
Restart=always Restart=always
RestartSec=5 RestartSec=5
# ?? systemd ?? StartLimitIntervalSec?? StartLimitInterval=???
StartLimitInterval=300 StartLimitInterval=300
StartLimitBurst=10 StartLimitBurst=10
# ?????10s ? SIGTERM??? SIGKILL? # Allow 10s for graceful shutdown before SIGKILL
TimeoutStopSec=10 TimeoutStopSec=10
KillMode=mixed KillMode=mixed
KillSignal=SIGTERM KillSignal=SIGTERM
# ?????????? # Resource limits
MemoryMax=256M MemoryMax=256M
CPUQuota=50% CPUQuota=50%
TasksMax=64 TasksMax=64
# ?????ttyd ????? setuid sudo???? NoNewPrivileges/strict? # Sandbox (allow writes to config, tmp, and network files)
ProtectSystem=full ProtectSystem=full
ReadWritePaths=$CONFIG_DIR /tmp /etc/hosts /etc/hostname ReadWritePaths=$CONFIG_DIR /tmp /etc/hosts /etc/hostname
# ?? # Logging
StandardOutput=journal StandardOutput=journal
StandardError=journal StandardError=journal
SyslogIdentifier=clawd SyslogIdentifier=clawd
# systemd Watchdog?60s ???????? # systemd Watchdog: restart if no heartbeat within 60s
WatchdogSec=60 WatchdogSec=60
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
info "systemd ??????? ?" info "systemd service file written"
# ?? journald ???????? ???????????????????????????????????????????????? # Configure journald retention
JOURNAL_CONF="/etc/systemd/journald.conf.d/clawd.conf" JOURNAL_CONF="/etc/systemd/journald.conf.d/clawd.conf"
if [ ! -f "$JOURNAL_CONF" ]; then if [ ! -f "$JOURNAL_CONF" ]; then
mkdir -p /etc/systemd/journald.conf.d mkdir -p /etc/systemd/journald.conf.d
cat > "$JOURNAL_CONF" <<EOF cat > "$JOURNAL_CONF" <<EOF
# clawd journald ?? # clawd journald limits
[Journal] [Journal]
SystemMaxUse=100M SystemMaxUse=100M
MaxFileSec=7day MaxFileSec=7day
EOF EOF
systemctl restart systemd-journald 2>/dev/null || true systemctl restart systemd-journald 2>/dev/null || true
info "journald ??????? ?" info "journald config written"
fi fi
# ?? ????? ?????????????????????????????????????????????????????????????? # Enable and start clawd
systemctl daemon-reload systemctl daemon-reload
systemctl enable clawd systemctl enable clawd
systemctl restart clawd systemctl restart clawd
sleep 2 sleep 2
if systemctl is-active --quiet clawd; then if systemctl is-active --quiet clawd; then
info "clawd ????? ?" info "clawd is running"
echo "" echo ""
echo " ????? journalctl -u clawd -f" echo " Logs: journalctl -u clawd -f"
echo " ????? systemctl status clawd" echo " Status: systemctl status clawd"
echo " ????? systemctl stop clawd" echo " Stop: systemctl stop clawd"
echo " ????? $CONFIG_DIR/config.json" echo " Config: $CONFIG_DIR/config.json"
echo " ????? $ENV_FILE" echo " Env: $ENV_FILE"
echo " ????? $CONFIG_DIR/logs/clawd.log" echo " Log dir: $CONFIG_DIR/logs/clawd.log"
echo "" echo ""
else else
warn "?????????????" warn "clawd failed to start. Check logs:"
echo " journalctl -u clawd -n 50 --no-pager" echo " journalctl -u clawd -n 50 --no-pager"
fi fi