2026-03-24 00:30:38 +00:00
|
|
|
#!/bin/sh
|
2026-03-26 12:36:00 +00:00
|
|
|
# Clawdie Shell — Deployment Module
|
|
|
|
|
# Purpose: Extract Clawdie-AI tarball and run installation
|
|
|
|
|
# POSIX-compliant (no bash-isms)
|
|
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
# Configuration (can be overridden for testing)
|
|
|
|
|
CLAWDIE_HOME="${CLAWDIE_HOME:-/home/clawdie}"
|
|
|
|
|
CLAWDIE_AI_DIR="${CLAWDIE_AI_DIR:-$CLAWDIE_HOME/clawdie-ai}"
|
|
|
|
|
CLAWDIE_TARBALL="${CLAWDIE_TARBALL:-/usr/local/share/clawdie-iso/clawdie-ai.tar.gz}"
|
|
|
|
|
ENV_FILE="${ENV_FILE:-$CLAWDIE_HOME/.env}"
|
|
|
|
|
LOG_FILE="${LOG_FILE:-/var/log/clawdie-firstboot.log}"
|
|
|
|
|
PROGRESS_FILE="${PROGRESS_FILE:-/var/log/clawdie-firstboot.progress}"
|
|
|
|
|
|
|
|
|
|
# ============================================================================
|
|
|
|
|
# MAIN ENTRY POINT
|
|
|
|
|
# ============================================================================
|
|
|
|
|
|
|
|
|
|
clawdie_shell_deploy() {
|
|
|
|
|
# Main orchestrator: extract tarball, generate env, run install-all
|
|
|
|
|
|
|
|
|
|
log_msg "[deploy] Starting Clawdie-AI deployment"
|
|
|
|
|
|
|
|
|
|
# Validate inputs
|
|
|
|
|
if [ -z "${ASSISTANT_NAME:-}" ]; then
|
|
|
|
|
log_msg "[deploy] ERROR: ASSISTANT_NAME not set"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "${AGENT_DOMAIN:-}" ]; then
|
|
|
|
|
log_msg "[deploy] ERROR: AGENT_DOMAIN not set"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Step 1: Extract tarball
|
|
|
|
|
clawdie_shell_deploy_extract_tarball || {
|
|
|
|
|
log_msg "[deploy] ERROR: Failed to extract tarball"
|
|
|
|
|
return 1
|
2026-03-24 00:30:38 +00:00
|
|
|
}
|
2026-03-26 12:36:00 +00:00
|
|
|
|
|
|
|
|
log_msg "[deploy] Tarball extracted to $CLAWDIE_AI_DIR"
|
|
|
|
|
|
|
|
|
|
# Step 2: Validate extracted directory
|
|
|
|
|
if [ ! -d "$CLAWDIE_AI_DIR" ] || [ ! -f "$CLAWDIE_AI_DIR/package.json" ]; then
|
|
|
|
|
log_msg "[deploy] ERROR: Tarball extraction failed or invalid"
|
|
|
|
|
return 1
|
2026-03-24 00:30:38 +00:00
|
|
|
fi
|
2026-03-26 12:36:00 +00:00
|
|
|
|
|
|
|
|
log_msg "[deploy] Package.json verified"
|
|
|
|
|
|
|
|
|
|
# Step 3: Change to Clawdie directory for install
|
|
|
|
|
cd "$CLAWDIE_AI_DIR" || {
|
|
|
|
|
log_msg "[deploy] ERROR: Failed to cd to $CLAWDIE_AI_DIR"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Step 4: Run npm install-all
|
|
|
|
|
log_msg "[deploy] Running npm run install-all..."
|
|
|
|
|
clawdie_shell_deploy_run_install_all || {
|
|
|
|
|
log_msg "[deploy] ERROR: npm run install-all failed"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_msg "[deploy] npm install-all completed successfully"
|
|
|
|
|
|
|
|
|
|
# Step 5: Verify services are running
|
|
|
|
|
clawdie_shell_deploy_verify || {
|
|
|
|
|
log_msg "[deploy] WARNING: Post-install verification found issues"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "[DEPLOY] SUCCESS" >> "$PROGRESS_FILE"
|
|
|
|
|
log_msg "[deploy] Clawdie-AI deployment complete"
|
2026-03-24 00:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
# ============================================================================
|
|
|
|
|
# TARBALL EXTRACTION
|
|
|
|
|
# ============================================================================
|
2026-03-24 00:30:38 +00:00
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
clawdie_shell_deploy_extract_tarball() {
|
|
|
|
|
# Extract Clawdie-AI tarball to CLAWDIE_HOME
|
|
|
|
|
|
|
|
|
|
if [ ! -f "$CLAWDIE_TARBALL" ]; then
|
|
|
|
|
log_msg "[deploy] ERROR: Tarball not found: $CLAWDIE_TARBALL"
|
|
|
|
|
return 1
|
2026-03-24 00:30:38 +00:00
|
|
|
fi
|
|
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
log_msg "[deploy] Extracting $CLAWDIE_TARBALL"
|
2026-03-24 00:30:38 +00:00
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
# Create parent directory if needed
|
|
|
|
|
mkdir -p "$CLAWDIE_HOME"
|
|
|
|
|
|
|
|
|
|
# Extract tarball
|
|
|
|
|
# Note: tarball structure is Clawdie-AI/... so extract to CLAWDIE_HOME parent
|
|
|
|
|
# and rename to clawdie-ai
|
|
|
|
|
if ! tar -xzf "$CLAWDIE_TARBALL" -C "$(dirname "$CLAWDIE_HOME")" 2>/dev/null; then
|
|
|
|
|
log_msg "[deploy] ERROR: tar extraction failed"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Rename if extraction created Clawdie-AI directory
|
|
|
|
|
if [ -d "$(dirname "$CLAWDIE_HOME")/Clawdie-AI" ] && [ ! -d "$CLAWDIE_AI_DIR" ]; then
|
|
|
|
|
mv "$(dirname "$CLAWDIE_HOME")/Clawdie-AI" "$CLAWDIE_AI_DIR"
|
|
|
|
|
log_msg "[deploy] Renamed Clawdie-AI to clawdie-ai"
|
2026-03-24 00:30:38 +00:00
|
|
|
fi
|
2026-03-26 12:36:00 +00:00
|
|
|
|
|
|
|
|
# Fix ownership
|
|
|
|
|
chown -R clawdie:clawdie "$CLAWDIE_HOME" 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
log_msg "[deploy] Tarball extraction complete"
|
|
|
|
|
return 0
|
2026-03-24 00:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
# ============================================================================
|
|
|
|
|
# NPM INSTALL-ALL
|
|
|
|
|
# ============================================================================
|
|
|
|
|
|
|
|
|
|
clawdie_shell_deploy_run_install_all() {
|
|
|
|
|
# Run npm run install-all with error handling
|
2026-03-24 00:30:38 +00:00
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
if [ ! -f "$CLAWDIE_AI_DIR/package.json" ]; then
|
|
|
|
|
log_msg "[deploy] ERROR: package.json not found in $CLAWDIE_AI_DIR"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Run npm install-all as clawdie user if not already clawdie
|
|
|
|
|
local run_cmd="npm run install-all"
|
|
|
|
|
|
|
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
|
|
|
# Running as root, drop to clawdie user
|
|
|
|
|
su - clawdie -c "cd $CLAWDIE_AI_DIR && $run_cmd" 2>&1 | tee -a "$LOG_FILE" || return 1
|
2026-03-24 00:30:38 +00:00
|
|
|
else
|
2026-03-26 12:36:00 +00:00
|
|
|
# Running as clawdie user directly
|
|
|
|
|
$run_cmd 2>&1 | tee -a "$LOG_FILE" || return 1
|
2026-03-24 00:30:38 +00:00
|
|
|
fi
|
2026-03-26 12:36:00 +00:00
|
|
|
|
|
|
|
|
return 0
|
2026-03-24 00:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ============================================================================
|
2026-03-26 12:36:00 +00:00
|
|
|
# POST-INSTALL VERIFICATION
|
2026-03-24 00:30:38 +00:00
|
|
|
# ============================================================================
|
|
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
clawdie_shell_deploy_verify() {
|
|
|
|
|
# Verify basic services are running
|
|
|
|
|
|
|
|
|
|
log_msg "[deploy] Running post-install verification"
|
|
|
|
|
|
|
|
|
|
local failed=0
|
|
|
|
|
|
|
|
|
|
# Check if jails are running (optional, may not be ready yet)
|
|
|
|
|
if command -v jls >/dev/null 2>&1; then
|
|
|
|
|
local jail_count=$(jls -N 2>/dev/null | wc -l || echo "0")
|
|
|
|
|
if [ "$jail_count" -gt 1 ]; then
|
|
|
|
|
log_msg "[deploy] ✓ Jails active: $((jail_count - 1)) jails"
|
|
|
|
|
else
|
|
|
|
|
log_msg "[deploy] ⚠ No jails detected (may still be provisioning)"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check if clawdie service is enabled
|
|
|
|
|
if grep -q "clawdie_enable" /etc/rc.conf 2>/dev/null; then
|
|
|
|
|
log_msg "[deploy] ✓ clawdie service configured in rc.conf"
|
2026-03-24 00:30:38 +00:00
|
|
|
else
|
2026-03-26 12:36:00 +00:00
|
|
|
log_msg "[deploy] ⚠ clawdie service not in rc.conf"
|
|
|
|
|
failed=1
|
2026-03-24 00:30:38 +00:00
|
|
|
fi
|
2026-03-26 12:36:00 +00:00
|
|
|
|
|
|
|
|
# Check if .env file was created
|
|
|
|
|
if [ -f "$ENV_FILE" ]; then
|
|
|
|
|
log_msg "[deploy] ✓ .env file created"
|
|
|
|
|
else
|
|
|
|
|
log_msg "[deploy] ⚠ .env file not found"
|
|
|
|
|
failed=1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return $failed
|
|
|
|
|
}
|
2026-03-24 00:30:38 +00:00
|
|
|
|
|
|
|
|
# ============================================================================
|
2026-03-26 12:36:00 +00:00
|
|
|
# LOGGING HELPER
|
2026-03-24 00:30:38 +00:00
|
|
|
# ============================================================================
|
|
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
log_msg() {
|
|
|
|
|
echo "$(date '+%H:%M:%S') $1" | tee -a "$LOG_FILE" 2>/dev/null || true
|
|
|
|
|
}
|
2026-03-24 00:30:38 +00:00
|
|
|
|
2026-03-26 12:36:00 +00:00
|
|
|
# Only run if sourced directly (not during test)
|
|
|
|
|
if [ "${SHELL_DEPLOY_TEST:-0}" -eq 0 ]; then
|
|
|
|
|
clawdie_shell_deploy
|
2026-03-24 00:30:38 +00:00
|
|
|
fi
|