diff --git a/scripts/daily-commit.sh b/scripts/daily-commit.sh new file mode 100755 index 0000000..56aa8db --- /dev/null +++ b/scripts/daily-commit.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +set -euo pipefail + +# daily-commit.sh +# Commits changes in the workspace and pushes to origin/main using the deploy SSH key. +# Also appends a short summary to memory/YYYY-MM-DD.md + +WORKDIR="/home/alex/openclaw2" +MEMDIR="$WORKDIR/memory" +KEY="$WORKDIR/.ssh/openclaw_deploy_ed25519" +LOGTMP="/tmp/daily_commit_summary.txt" + +mkdir -p "$MEMDIR" +cd "$WORKDIR" + +export GIT_SSH_COMMAND="ssh -i $KEY -o StrictHostKeyChecking=accept-new" + +# Ensure remote is set +git remote get-url origin >/dev/null 2>&1 || git remote add origin git@github.com:alexpolo1/openclaw2.git || true + +# Fetch and rebase to avoid unrelated histories +if git rev-parse --verify origin/main >/dev/null 2>&1; then + git fetch origin main --quiet + # Try a rebase; if it fails, abort and record error + if ! git rebase origin/main --quiet; then + echo "$(date -I) - REBASE_FAILED" >> "$MEMDIR/$(date +%F).md" + git rebase --abort >/dev/null 2>&1 || true + exit 2 + fi +fi + +# Stage changes +git add -A + +# If nothing to commit, write note and exit +if git diff --staged --quiet; then + echo "$(date -I) — nothing to commit" >> "$MEMDIR/$(date +%F).md" + exit 0 +fi + +# Commit and push +MSG="daily backup $(date -I)" +if git commit -m "$MSG" --quiet; then + if git push origin main --quiet; then + COMMIT_HASH=$(git rev-parse --short HEAD) + git --no-pager show --name-only --pretty=format:"%h %ad %s" --date=short "$COMMIT_HASH" > "$LOGTMP" + echo "### $MSG ($COMMIT_HASH)" >> "$MEMDIR/$(date +%F).md" + cat "$LOGTMP" >> "$MEMDIR/$(date +%F).md" + rm -f "$LOGTMP" + exit 0 + else + echo "$(date -I) - PUSH_FAILED" >> "$MEMDIR/$(date +%F).md" + exit 3 + fi +else + echo "$(date -I) - COMMIT_FAILED" >> "$MEMDIR/$(date +%F).md" + exit 4 +fi diff --git a/scripts/fix-gateway-service.sh b/scripts/fix-gateway-service.sh new file mode 100755 index 0000000..49b0eab --- /dev/null +++ b/scripts/fix-gateway-service.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -euo pipefail +# Helper to generate a recommended systemd service content for openclaw gateway +SERVICE_PATH="/etc/systemd/system/openclaw-gateway.service" +cat <<'SERVICE' > ./openclaw-gateway.service.suggested +[Unit] +Description=OpenClaw Gateway +After=network.target + +[Service] +Type=simple +User=openclaw2 +WorkingDirectory=/home/openclaw2/openclaw2 +# Ensure PATH includes node and /usr/local/bin where npm global binaries live +Environment="PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" +# ExecStart should point to gateway entrypoint script inside repo +ExecStart=/home/openclaw2/openclaw2/scripts/gateway-entrypoint.sh +Restart=on-failure +RestartSec=5s +LimitNOFILE=65536 + +[Install] +WantedBy=multi-user.target +SERVICE + +echo "Suggested service saved to ./openclaw-gateway.service.suggested" + +echo "Commands to apply (run as sudo):" +cat <<'CMDS' +sudo mv ./openclaw-gateway.service.suggested /etc/systemd/system/openclaw-gateway.service +sudo systemctl daemon-reload +sudo systemctl enable --now openclaw-gateway.service +# If multiple instances running, list and kill duplicates: +# sudo pgrep -a -f openclaw | xargs -r sudo kill +sudo systemctl status openclaw-gateway.service +CMDS diff --git a/scripts/gateway-entrypoint.sh b/scripts/gateway-entrypoint.sh new file mode 100755 index 0000000..ad3823d --- /dev/null +++ b/scripts/gateway-entrypoint.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Entrypoint wrapper to set PATH and run gateway CLI or node script +set -euo pipefail +export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH" +cd /home/openclaw2/openclaw2 +# If gateway has an npm script or binary, prefer ./node_modules/.bin +export PATH="/home/openclaw2/openclaw2/node_modules/.bin:$PATH" +# Start gateway (example) +if [ -f ./scripts/start-gateway.sh ]; then + exec ./scripts/start-gateway.sh +fi +# Fallback: try node ./gateway/index.js +if [ -f ./gateway/index.js ]; then + exec node ./gateway/index.js +fi +# Fallback to openclaw CLI +exec /home/openclaw2/openclaw2/node_modules/.bin/openclaw gateway diff --git a/scripts/install-cli-tools.sh b/scripts/install-cli-tools.sh new file mode 100755 index 0000000..9956329 --- /dev/null +++ b/scripts/install-cli-tools.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -euo pipefail +# Idempotent installer for required CLIs: ripgrep, pnpm (node/npm), gh, jq +# Designed for Debian/Ubuntu. Run with sudo for system installs. + +which rg >/dev/null 2>&1 || { + echo "Installing ripgrep..." + apt-get update && apt-get install -y ripgrep +} + +which jq >/dev/null 2>&1 || { + echo "Installing jq..." + apt-get update && apt-get install -y jq +} + +which gh >/dev/null 2>&1 || { + echo "Installing gh (GitHub CLI)..." + apt-get update && apt-get install -y gh +} + +# Ensure node is present (use nvm or apt). Prefer node >=16. +if ! command -v node >/dev/null 2>&1; then + echo "Node.js not found. Installing Node 18 LTS..." + curl -fsSL https://deb.nodesource.com/setup_18.x | bash - + apt-get install -y nodejs +fi + +# pnpm +if ! command -v pnpm >/dev/null 2>&1; then + echo "Installing pnpm..." + npm install -g pnpm || true +fi + +echo "Verifying installs..." +for cmd in rg jq gh node pnpm npm; do + if command -v "$cmd" >/dev/null 2>&1; then + echo "OK: $cmd -> $(command -v $cmd)" + else + echo "MISSING: $cmd" + fi +done + +echo "Done."