Files
openclaw2/scripts/one-shot-install.sh

89 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
LOG=/home/alex/openclaw2/logs/one-shot-install.log
mkdir -p "$(dirname "$LOG")"
exec > >(tee -a "$LOG") 2>&1
echo "ONE-SHOT INSTALL START: $(date -Iseconds)"
# 1) Backup config and credentials
BACKUP_DIR=/tmp/openclaw_backup_$(date +%s)
mkdir -p "$BACKUP_DIR"
cp -a /home/alex/openclaw2/.openclaw/openclaw.json "$BACKUP_DIR/" || true
cp -a /home/alex/openclaw2/credentials "$BACKUP_DIR/" 2>/dev/null || true
cp -a /home/alex/openclaw2/.openclaw/identity "$BACKUP_DIR/" 2>/dev/null || true
echo "Backups written to $BACKUP_DIR"
# 2) Install system packages (Debian/Ubuntu fallback)
if command -v apt >/dev/null 2>&1; then
echo "Detected apt; installing packages"
apt update
apt install -y ripgrep jq sqlite3 curl gnupg software-properties-common
elif command -v pacman >/dev/null 2>&1; then
echo "Detected pacman; installing packages"
pacman -Syu --noconfirm ripgrep jq sqlite sqlite3 curl
elif command -v dnf >/dev/null 2>&1; then
echo "Detected dnf; installing packages"
dnf install -y ripgrep jq sqlite sqlite3 curl
else
echo "No supported package manager found. Please install: ripgrep, jq, sqlite3, curl" >&2
fi
# 3) Ensure Node 18+ and pnpm
if ! command -v node >/dev/null 2>&1 || [ "$(node -v | sed 's/v//;s/\..*//')" -lt 18 ]; then
echo "Installing Node 18 via NodeSource"
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt install -y nodejs
fi
if ! command -v pnpm >/dev/null 2>&1; then
echo "Installing pnpm via corepack/npm"
if command -v corepack >/dev/null 2>&1; then
corepack enable
corepack prepare pnpm@latest --activate
else
npm install -g pnpm
fi
fi
# 4) Install GitHub CLI if missing (deb-based)
if ! command -v gh >/dev/null 2>&1; then
if command -v apt >/dev/null 2>&1; then
echo "Installing GitHub CLI"
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" >/etc/apt/sources.list.d/github-cli.list
apt update
apt install -y gh
fi
fi
# 5) Deploy suggested systemd unit (generated by helper script earlier)
if [ -f /home/alex/openclaw2/openclaw-gateway.service.suggested ]; then
echo "Deploying suggested service unit"
mv /home/alex/openclaw2/openclaw-gateway.service.suggested /etc/systemd/system/openclaw-gateway.service
systemctl daemon-reload
systemctl enable --now openclaw-gateway.service
systemctl status openclaw-gateway.service --no-pager || true
else
echo "No suggested service unit found; skipping service deploy"
fi
# 6) Build docs index
if command -v rg >/dev/null 2>&1; then
echo "Building docs index"
/home/alex/openclaw2/scripts/build-doc-index.sh || true
else
echo "rg not found; skipping docs index"
fi
# 7) Run openclaw doctor report (non-destructive)
if command -v openclaw >/dev/null 2>&1; then
echo "Running openclaw doctor --report"
sudo -u alex openclaw doctor --report || true
else
echo "openclaw CLI not found in PATH"
fi
echo "ONE-SHOT INSTALL END: $(date -Iseconds)"