#!/usr/bin/env bash # Install the cph-hub systemd service on a host. Idempotent. # # Prerequisites already on the host: Node.js, npm, PostgreSQL, systemd. # The Hub repo is expected at HUB_DIR (default /srv/curriculum-project-hub/hub) # with `npm ci` + `npm run build` already run by deploy_platform.sh. # # Usage: # sudo BASE=/srv/curriculum-project-hub bash deploy/install_service.sh set -euo pipefail BASE="${BASE:-/srv/curriculum-project-hub}" HUB_DIR="${HUB_DIR:-$BASE/hub}" SERVICE_USER="${SERVICE_USER:-cph-hub}" HOST="${HOST:-127.0.0.1}" PORT="${PORT:-8788}" ENV_FILE="${ENV_FILE:-$BASE/.secrets/platform.env}" NODE_BIN="${NODE_BIN:-$(command -v node || true)}" if [ -z "$NODE_BIN" ]; then echo "node must be on PATH, or set NODE_BIN." >&2 exit 1 fi if [ ! -d "$HUB_DIR" ]; then echo "HUB_DIR not found: $HUB_DIR (set HUB_DIR or clone the repo there)." >&2 exit 1 fi if [ ! -f "$HUB_DIR/dist/server.js" ]; then echo "build missing: run 'npm ci && npm run build' in $HUB_DIR first." >&2 exit 1 fi # Seed the env file if absent. Secrets stay on the server, never in the repo. if [ ! -f "$ENV_FILE" ]; then install -d -m 0700 "$(dirname "$ENV_FILE")" cat >"$ENV_FILE" <