fix: auto-migrate git remote from github to git.cutos.ai on install/update; bump v1.2.2

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
stswangzhiping
2026-05-04 17:36:24 +08:00
parent f71d448047
commit f1c24f75b5
3 changed files with 94 additions and 80 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# clawd 一键安装脚本 # clawd ??????
# 用法:curl -fsSL https://git.cutos.ai/claw-daemon/clawd/raw/branch/main/install.sh | sudo bash # ???curl -fsSL https://git.cutos.ai/claw-daemon/clawd/raw/branch/main/install.sh | sudo bash
# 需要 root 权限,需要已安装 Node.js >= 18 # ?? root ???????? 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 # ?? ?? root ????????????????????????????????????????????????????????????????
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
error "请以 root 身份运行(sudo bash install.sh" error "?? root ?????sudo bash install.sh?"
fi fi
# -- 检查 Node.js # ?? ?? 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????? 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 ??????? $NODE_VER???? >= 18"
fi fi
info "Node.js $NODE_VER OK" info "Node.js $NODE_VER ?"
# -- 检查/安装 dnsmasqWiFi 配网需要) # ?? ??/?? dnsmasq?WiFi ???????????????????????????????????????????
if ! command -v dnsmasq &>/dev/null; then if ! command -v dnsmasq &>/dev/null; then
info "安装 dnsmasqWiFi 配网所需)..." info "?? dnsmasq?WiFi ?????..."
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 "无法自动安装 dnsmasqWiFi 配网功能可能不可用" warn "?????? dnsmasq?WiFi ?????????"
fi fi
# 禁止 dnsmasq 系统服务自启(clawd 自己管理) # ?? dnsmasq ???????clawd ?????
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 OK" info "dnsmasq ?"
fi fi
# -- 启用 NetworkManagerWiFi 配网需要) # ?? ?? NetworkManager?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 "?? NetworkManager..."
systemctl enable --now NetworkManager 2>/dev/null || true systemctl enable --now NetworkManager 2>/dev/null || true
fi fi
info "NetworkManager OK" info "NetworkManager ?"
# 预写 DNS 劫持配置(运行时 /etc 可能为只读) # ?? DNS ???????? /etc ??????
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 ??????? $NM_DNSMASQ_DIR ?"
fi fi
# -- WiFi rfkill 解锁(部分设备默认禁用 WiFi # ?? WiFi rfkill ??????????? WiFi?????????????????????????????????
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 "?? WiFi ($(basename "$rf"))..."
echo 0 > "$rf/soft" echo 0 > "$rf/soft"
fi fi
fi fi
done done
# 持久化:独立脚本 + systemd 服务,确保开机自动解锁 WiFi # ???????? + systemd ??????????? WiFi
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,51 +108,58 @@ 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 ??????? ?"
# -- 安装 ttydWeb 终端) # ?? ?? ttyd?Web ???????????????????????????????????????????????????????
info "安装 ttyd..." info "?? 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 ??? ?"
else else
warn "ttyd 安装失败Web 终端功能将不可用" warn "ttyd ?????Web ????????"
fi fi
# -- 安装 clawd # ?? ?? 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 "??? $INSTALL_DIR ..."
mkdir -p "$INSTALL_DIR" mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR" cd "$INSTALL_DIR"
# 下载源码(若目录已有 package.json,视为离线/已解压部署,跳过 git/tarball # ?????????? package.json?????/???????? git/tarball?
if [ -f "package.json" ]; then CUTOS_REPO="https://git.cutos.ai/claw-daemon/clawd.git"
info "检测到已有源码,跳过 git/tarball 下载" if command -v git &>/dev/null && [ -d ".git" ]; then
elif command -v git &>/dev/null; then CURRENT_REMOTE=$(git remote get-url origin 2>/dev/null || echo "")
if [ -d ".git" ]; then if echo "$CURRENT_REMOTE" | grep -q "github.com"; then
git pull --quiet info "?? git remote ? git.cutos.ai ..."
else git remote set-url origin "$CUTOS_REPO"
git clone --depth=1 https://git.cutos.ai/claw-daemon/clawd.git .
fi fi
info "??????..."
git fetch origin
git reset --hard origin/main
git clean -fd
elif [ -f "package.json" ]; then
info "????????? git??????"
elif command -v git &>/dev/null; then
git clone --depth=1 "$CUTOS_REPO" .
else else
TARBALL_URL="https://git.cutos.ai/claw-daemon/clawd/archive/main.tar.gz" TARBALL_URL="https://git.cutos.ai/claw-daemon/clawd/archive/main.tar.gz"
curl -fsSL "$TARBALL_URL" | tar -xz --strip-components=1 curl -fsSL "$TARBALL_URL" | tar -xz --strip-components=1
fi fi
# 安装依赖 # ????
info "安装 npm 依赖..." info "?? npm ??..."
npm install --omit=dev --silent npm install --omit=dev --silent
# 创建可执行链接 # ???????
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 ???? /usr/local/bin/clawd ?"
# -- 创建配置目录 + 环境变量文件 # ?? ?????? + ?????? ??????????????????????????????????????????????
mkdir -p "$CONFIG_DIR" mkdir -p "$CONFIG_DIR"
if [ ! -f "$CONFIG_DIR/config.json" ]; then if [ ! -f "$CONFIG_DIR/config.json" ]; then
@@ -164,36 +171,36 @@ if [ ! -f "$CONFIG_DIR/config.json" ]; then
"heartbeat_interval": 30 "heartbeat_interval": 30
} }
EOF EOF
info "配置文件已创建:$CONFIG_DIR/config.json" info "????????$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 ?????systemd EnvironmentFile?
# 日志级别: debug / info / warn / error # ????: debug / info / warn / error
CLAWD_LOG_LEVEL=info CLAWD_LOG_LEVEL=info
# 是否写日志文件(0= journald # ????????0=? journald?
CLAWD_LOG_FILE=1 CLAWD_LOG_FILE=1
# 自定义服务器地址(留空则读 config.json # ????????????? config.json?
# CLAWD_SERVER=wss://claw.cutos.ai/ws # CLAWD_SERVER=wss://claw.cutos.ai/ws
# BtMonitorbluetoothctl)默认在程序内关闭,无需在此写 CLAWD_DISABLE_BT # BtMonitor?bluetoothctl??????????????? CLAWD_DISABLE_BT?
# 若产品需要蓝牙指示灯,取消下一行注释: # ???????????????????
# CLAWD_ENABLE_BT=1 # CLAWD_ENABLE_BT=1
# OpenVFD sysfs 根路径(默认 /sys/class/leds/openvfd # OpenVFD sysfs ?????? /sys/class/leds/openvfd?
# CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd # CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd
# 数码管 vfdservice 管道(默认 /tmp/openvfd_service # ??? vfdservice ????? /tmp/openvfd_service?
# CLAWD_VFD_PIPE=/tmp/openvfd_service # CLAWD_VFD_PIPE=/tmp/openvfd_service
# 多网口/特殊板型可固定 LAN 灯监控的以太网口(默认由 clawd 自动锁定首次 carrier 口) # ???/??????? LAN ???????????? clawd ?????? carrier ??
# CLAWD_ETH_IFACE=end0 # CLAWD_ETH_IFACE=end0
EOF EOF
info "环境变量文件已创建:$ENV_FILE" info "??????????$ENV_FILE ?"
fi fi
# -- 创建日志目录 # ?? ?????? ?????????????????????????????????????????????????????????????
mkdir -p "$CONFIG_DIR/logs" mkdir -p "$CONFIG_DIR/logs"
info "日志目录:$CONFIG_DIR/logs" info "?????$CONFIG_DIR/logs ?"
# -- 创建 systemd service # ?? ?? systemd service ????????????????????????????????????????????????????
NODE_BIN=$(command -v node) NODE_BIN=$(command -v node)
SERVICE_FILE="/etc/systemd/system/clawd.service" SERVICE_FILE="/etc/systemd/system/clawd.service"
@@ -206,78 +213,78 @@ Wants=NetworkManager.service
[Service] [Service]
Type=simple Type=simple
# systemd-notify 由子进程执行,默认 NotifyAccess=main 会拒收;需 all 才能喂 WatchdogSec # systemd-notify ????????? NotifyAccess=main ????? all ??? 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=always Restart=always
RestartSec=5 RestartSec=5
# 旧版 systemd 不认 StartLimitIntervalSec,用 StartLimitInterval=(秒) # ?? systemd ?? StartLimitIntervalSec?? StartLimitInterval=???
StartLimitInterval=300 StartLimitInterval=300
StartLimitBurst=10 StartLimitBurst=10
# 优雅停止(10s SIGTERM,超时 SIGKILL # ?????10s ? SIGTERM??? SIGKILL?
TimeoutStopSec=10 TimeoutStopSec=10
KillMode=mixed KillMode=mixed
KillSignal=SIGTERM KillSignal=SIGTERM
# 资源限制(防止失控) # ??????????
MemoryMax=256M MemoryMax=256M
CPUQuota=50% CPUQuota=50%
TasksMax=64 TasksMax=64
# 安全加固ttyd 子进程需要 setuid sudo,不能用 NoNewPrivileges/strict # ?????ttyd ????? setuid sudo???? NoNewPrivileges/strict?
ProtectSystem=full ProtectSystem=full
ReadWritePaths=$CONFIG_DIR /tmp ReadWritePaths=$CONFIG_DIR /tmp
# 日志 # ??
StandardOutput=journal StandardOutput=journal
StandardError=journal StandardError=journal
SyslogIdentifier=clawd SyslogIdentifier=clawd
# systemd Watchdog60s 无响应视为挂死) # systemd Watchdog?60s ????????
WatchdogSec=60 WatchdogSec=60
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
info "systemd 服务文件已创建" info "systemd ??????? ?"
# -- journald 日志限制(可选) # ?? journald ???????? ????????????????????????????????????????????????
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 ??
[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 ??????? ?"
fi fi
# -- 启用并启动 # ?? ????? ??????????????????????????????????????????????????????????????
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 ????? ?"
echo "" echo ""
echo " 查看日志: journalctl -u clawd -f" echo " ????? journalctl -u clawd -f"
echo " 查看状态: systemctl status clawd" echo " ????? systemctl status clawd"
echo " 停止服务: systemctl stop clawd" echo " ????? systemctl stop clawd"
echo " 配置文件: $CONFIG_DIR/config.json" echo " ????? $CONFIG_DIR/config.json"
echo " 环境变量: $ENV_FILE" echo " ????? $ENV_FILE"
echo " 文件日志: $CONFIG_DIR/logs/clawd.log" echo " ????? $CONFIG_DIR/logs/clawd.log"
echo "" echo ""
else else
warn "服务启动失败,请检查日志:" warn "?????????????"
echo " journalctl -u clawd -n 50 --no-pager" echo " journalctl -u clawd -n 50 --no-pager"
fi fi

View File

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

View File

@@ -23,6 +23,13 @@ fi
cd "$REPO_DIR" cd "$REPO_DIR"
# 如果 remote 仍指向 GitHub迁移到 git.cutos.ai
CURRENT_REMOTE=$(git remote get-url "$REMOTE" 2>/dev/null || echo "")
if echo "$CURRENT_REMOTE" | grep -q "github.com"; then
echo "==> Migrating remote from GitHub to git.cutos.ai ..."
git remote set-url "$REMOTE" https://git.cutos.ai/claw-daemon/clawd.git
fi
echo "==> Fetching latest from $REMOTE/$BRANCH ..." echo "==> Fetching latest from $REMOTE/$BRANCH ..."
git fetch "$REMOTE" git fetch "$REMOTE"