From 87c219c426c1ba6c615c33f7dbeaa26712755089 Mon Sep 17 00:00:00 2001 From: yankun Date: Thu, 30 Apr 2026 16:50:07 +0800 Subject: [PATCH] update shell --- tools/update-clawd.sh | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tools/update-clawd.sh diff --git a/tools/update-clawd.sh b/tools/update-clawd.sh new file mode 100644 index 0000000..aa79481 --- /dev/null +++ b/tools/update-clawd.sh @@ -0,0 +1,53 @@ +#!/bin/bash +set -euo pipefail + +REPO_DIR="/opt/clawd" +REMOTE="origin" +BRANCH="main" +SERVICE="clawd.service" + +echo "==> clawd update start" +date + +if [ ! -d "$REPO_DIR/.git" ]; then + echo "ERROR: $REPO_DIR is not a git repository" + exit 1 +fi + +cd "$REPO_DIR" + +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 + +if git diff --name-only "$LOCAL_COMMIT" "$REMOTE_COMMIT" | grep -Eq '(^|/)(package.json|package-lock.json)$'; then + echo "==> Dependency files changed, running npm install ..." + npm install --prefix "$REPO_DIR" +else + echo "==> No dependency changes, skip npm install" +fi + +echo "==> Restarting service: $SERVICE" +systemctl restart "$SERVICE" + +echo "==> Service status:" +systemctl status "$SERVICE" --no-pager -l || true + +echo "==> Current commit:" +git log --oneline -1 + +echo "==> clawd update done" \ No newline at end of file