Files
platform/scripts/setup-pty-sidecar.sh
T
pastilhas ebd8778007 fix: refactor setup scripts for system-wide Node.js (no nvm)
BREAKING: Officer now uses system Node.js via NodeSource instead of nvm.

Changes:
- Removed nvm sourcing from setup.sh
- Updated Node installation to use NodeSource repository
- All npm global packages installed system-wide with sudo
- Updated PTY sidecar setup to use /usr/bin/node (system node)
- Added Pi validation (test --list-models)
- System packages now available to all users automatically

Benefits:
- Multi-user friendly: all users get same Node version
- No per-user environment setup needed
- Simpler troubleshooting (one node version)
- Services use consistent node binary
- Prevents snap node incompatibility issues

Fixes:
- 'node not found' for secondary users
- systemd services finding correct node
- Pi installation consistency across users

New Files:
- SETUP_GUIDE.md: Comprehensive installation guide
- SETUP_ANALYSIS.md: Technical analysis of previous issues

Migration:
- Remove nvm if installed (optional)
- Run: curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
- Run: sudo apt-get install -y nodejs
- Run: bash scripts/setup.sh
2026-03-04 02:09:47 +00:00

68 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Officer PTY Sidecar — systemd service setup
# Creates and enables a systemd service for the terminal PTY sidecar.
# Usage: bash scripts/setup-pty-sidecar.sh
set -euo pipefail
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
ok() { echo -e " ${GREEN}${NC} $1"; }
warn() { echo -e " ${YELLOW}!${NC} $1"; }
skip() { echo -e " - $1 (already set up)"; }
SERVICE_NAME="officer-pty-sidecar"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
SERVICE_USER="$(whoami)"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
# Use system node (not nvm) for systemd service
NODE_BIN="/usr/bin/node"
if [ ! -f "$NODE_BIN" ]; then
fail "System Node.js not found at $NODE_BIN"
fail "Install Node.js 22 via NodeSource:"
fail " curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -"
fail " sudo apt-get install -y nodejs"
exit 1
fi
echo ""
echo "── PTY Sidecar (systemd service) ──"
echo " Node: $NODE_BIN ($("$NODE_BIN" -v))"
if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then
skip "$SERVICE_NAME service already running"
exit 0
fi
sudo tee "$SERVICE_FILE" > /dev/null << EOF
[Unit]
Description=Officer PTY Sidecar
After=network.target
[Service]
Type=simple
User=$SERVICE_USER
WorkingDirectory=$PROJECT_DIR
Environment=TERMINAL_PTY_PORT=5338
ExecStart=$NODE_BIN $PROJECT_DIR/src/servers/api/terminal/pty-sidecar.mjs
Restart=on-failure
RestartSec=3
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now "$SERVICE_NAME"
if systemctl is-active --quiet "$SERVICE_NAME"; then
ok "$SERVICE_NAME service installed and running"
else
warn "$SERVICE_NAME service failed to start — check 'journalctl -u $SERVICE_NAME'"
fi