From e1e3fa95cd1938c349693db534910eba22b070a9 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Mon, 4 May 2026 18:54:52 +0800 Subject: [PATCH] fix: re-exec updated script after git pull so new logic runs; bump to 1.2.8 Co-authored-by: Cursor --- bin/clawd.js | 16 ----------- package.json | 2 +- tools/update-clawd.sh | 65 ++++++++++++++++++++++++++----------------- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/bin/clawd.js b/bin/clawd.js index 5a3fc47..559193a 100755 --- a/bin/clawd.js +++ b/bin/clawd.js @@ -11,22 +11,6 @@ const config = require('../lib/config'); const log = require('../lib/logger'); const { pollSms } = require('../drivers/sim/sms-reader'); -// 修复旧版 clawd.service:确保 ReadWritePaths 包含 /etc/hosts /etc/hostname -const SERVICE_FILE = '/etc/systemd/system/clawd.service'; -const fs = require('fs'); -try { - const svc = fs.readFileSync(SERVICE_FILE, 'utf8'); - if (svc.includes('ReadWritePaths=') && !svc.includes('/etc/hosts')) { - const fixed = svc.replace( - /ReadWritePaths=([^\n]*)/, - (_, rest) => `ReadWritePaths=${rest.trimEnd()} /etc/hosts /etc/hostname` - ); - fs.writeFileSync(SERVICE_FILE, fixed, 'utf8'); - exec('systemctl daemon-reload', () => {}); - log.info('clawd', 'clawd.service ReadWritePaths patched'); - } -} catch (_) { /* not running under systemd or no permission */ } - // 每次启动绑定 Quectel 串口驱动(失败不影响主流程) const bindScript = path.join(__dirname, '..', 'tools', 'bind-quectel-serial.sh'); exec(`bash "${bindScript}"`, (err, stdout, stderr) => { diff --git a/package.json b/package.json index 9bf41a2..fe748eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clawd", - "version": "1.2.7", + "version": "1.2.8", "description": "Claw Box daemon - connects local Linux box to claw.cutos.ai via WebSocket", "main": "lib/client.js", "bin": { diff --git a/tools/update-clawd.sh b/tools/update-clawd.sh index 097950e..7ed4700 100644 --- a/tools/update-clawd.sh +++ b/tools/update-clawd.sh @@ -6,10 +6,12 @@ REMOTE="origin" BRANCH="main" SERVICE="clawd.service" NO_RESTART=false +NO_PULL=false for arg in "$@"; do case "$arg" in --no-restart) NO_RESTART=true ;; + --no-pull) NO_PULL=true ;; esac done @@ -23,32 +25,43 @@ fi 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 +if [ "$NO_PULL" = false ]; then + # 如果 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 ..." + git fetch "$REMOTE" + + LOCAL_COMMIT="$(git rev-parse HEAD)" + REMOTE_COMMIT="$(git rev-parse "$REMOTE/$BRANCH")" + + echo "==> Local : $LOCAL_COMMIT" + echo "==> Remote: $REMOTE_COMMIT" + + if [ "$LOCAL_COMMIT" = "$REMOTE_COMMIT" ]; then + echo "==> Already up to date. Skip upgrade." + exit 0 + fi + + echo "==> Updating working tree to $REMOTE/$BRANCH ..." + git reset --hard "$REMOTE/$BRANCH" + git clean -fd + + # Re-exec the freshly pulled version of this script so all new logic runs + echo "==> Re-executing updated script ..." + exec bash "$REPO_DIR/tools/update-clawd.sh" --no-pull "$@" fi -echo "==> Fetching latest from $REMOTE/$BRANCH ..." -git fetch "$REMOTE" +# ── 以下由新版脚本执行(--no-pull 阶段)──────────────────────────────────────── LOCAL_COMMIT="$(git rev-parse HEAD)" -REMOTE_COMMIT="$(git rev-parse "$REMOTE/$BRANCH")" +REMOTE_COMMIT="$(git rev-parse "$REMOTE/$BRANCH" 2>/dev/null || echo "$LOCAL_COMMIT")" -echo "==> Local : $LOCAL_COMMIT" -echo "==> Remote: $REMOTE_COMMIT" - -if [ "$LOCAL_COMMIT" = "$REMOTE_COMMIT" ]; then - echo "==> Already up to date. Skip upgrade." - exit 0 -fi - -echo "==> Updating working tree to $REMOTE/$BRANCH ..." -git reset --hard "$REMOTE/$BRANCH" -git clean -fd - -if git diff --name-only "$LOCAL_COMMIT" "$REMOTE_COMMIT" | grep -Eq '(^|/)(package.json|package-lock.json)$'; then +if git diff --name-only HEAD~1 HEAD 2>/dev/null | grep -Eq '(^|/)(package.json|package-lock.json)$'; then echo "==> Dependency files changed, running npm install ..." npm install --prefix "$REPO_DIR" else @@ -58,11 +71,6 @@ fi echo "==> Current commit:" git log --oneline -1 -if [ "$NO_RESTART" = true ]; then - echo "==> --no-restart: skip systemctl restart (caller handles restart)" - exit 0 -fi - NODE_BIN=$(command -v node) INSTALL_DIR="/opt/clawd" CONFIG_DIR="/etc/clawd" @@ -113,6 +121,11 @@ EOF systemctl daemon-reload echo "==> daemon-reload done" +if [ "$NO_RESTART" = true ]; then + echo "==> --no-restart: skip systemctl restart (caller handles restart)" + exit 0 +fi + echo "==> Restarting service: $SERVICE" systemctl restart "$SERVICE"