102 lines
2.3 KiB
Bash
102 lines
2.3 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
NODE_VERSION="${NODE_VERSION:-20}"
|
|
SKILLS_DIR="${SKILLS_DIR:-/skills}"
|
|
SKILL_DIR="$(dirname "$(dirname "$0")")"
|
|
|
|
# Idempotent Node.js installation
|
|
install_node() {
|
|
if command -v node &>/dev/null; then
|
|
echo "Node.js already installed: $(node --version)"
|
|
return 0
|
|
fi
|
|
|
|
echo "Installing Node.js ${NODE_VERSION}..."
|
|
|
|
# Install via NodeSource
|
|
apt-get update
|
|
apt-get install -y curl ca-certificates gnupg
|
|
|
|
mkdir -p /etc/apt/keyrings
|
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
|
|
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" > /etc/apt/sources.list.d/nodesource.list
|
|
|
|
apt-get update
|
|
apt-get install -y nodejs
|
|
|
|
echo "Node.js installed: $(node --version)"
|
|
echo "npm installed: $(npm --version)"
|
|
}
|
|
|
|
# Install UI dependencies
|
|
install_deps() {
|
|
local ui_dir="$SKILL_DIR/ui"
|
|
|
|
if [ -d "$ui_dir/node_modules" ]; then
|
|
echo "Dependencies already installed"
|
|
return 0
|
|
fi
|
|
|
|
echo "Installing UI dependencies..."
|
|
cd "$ui_dir"
|
|
npm install
|
|
|
|
echo "Dependencies installed"
|
|
}
|
|
|
|
# Build UI for production
|
|
build_ui() {
|
|
local ui_dir="$SKILL_DIR/ui"
|
|
|
|
if [ -d "$ui_dir/dist" ]; then
|
|
echo "UI already built"
|
|
return 0
|
|
fi
|
|
|
|
echo "Building UI..."
|
|
cd "$ui_dir"
|
|
npm run build
|
|
|
|
echo "UI built"
|
|
}
|
|
|
|
# Configure Caddy if domain set
|
|
configure_caddy() {
|
|
local caddy_dir="$SKILLS_DIR/caddy"
|
|
local dashboard_domain="${DASHBOARD_DOMAIN:-}"
|
|
local dashboard_port="${DASHBOARD_PORT:-3000}"
|
|
|
|
if [ ! -d "$caddy_dir" ]; then
|
|
echo "Caddy not found - dashboard will run standalone"
|
|
return 0
|
|
fi
|
|
|
|
if [ -z "$dashboard_domain" ]; then
|
|
echo "DASHBOARD_DOMAIN not set - skipping Caddy config"
|
|
return 0
|
|
fi
|
|
|
|
echo "Configuring Caddy for $dashboard_domain..."
|
|
|
|
local snippets_dir="$caddy_dir/snippets.d"
|
|
mkdir -p "$snippets_dir"
|
|
|
|
cat > "$snippets_dir/dashboard.caddy" << EOF
|
|
# Auto-generated by dashboard skill
|
|
$dashboard_domain {
|
|
reverse_proxy localhost:$dashboard_port
|
|
}
|
|
EOF
|
|
|
|
echo "Caddy config: $dashboard_domain -> localhost:$dashboard_port"
|
|
}
|
|
|
|
install_node
|
|
install_deps
|
|
build_ui
|
|
configure_caddy
|
|
|
|
echo "Dashboard setup complete"
|