#!/usr/bin/env bash # Clavex one-click installer # # Usage: # curl -fsSL https://get.clavex.eu | sh # # What it does: # 1. Checks prerequisites (Docker, Compose v2, openssl, curl/wget) # 2. Creates ~/.clavex/ as the installation directory # 3. Generates cryptographically-random secrets with openssl # 4. Downloads docker-compose.minimal.yml from the Clavex releases # 5. Writes a .env file with the generated secrets # 6. Starts all services with docker compose up -d # 7. Waits for Clavex /healthz to become available # 8. Opens http://localhost:8080 in the default browser # # Supported platforms: macOS, Linux (amd64 / arm64) # Requirements: Docker Engine 24+, Compose v2 plugin, openssl, bash 4+ # # Environment variables: # CLAVEX_DIR Installation directory (default: ~/.clavex) # CLAVEX_PORT HTTP port (default: 8080) # CLAVEX_BASE_DOMAIN Public hostname (default: localhost:) # CLAVEX_COMPOSE_URL Override compose file URL (for air-gapped installs) # set -euo pipefail # ── Defaults ────────────────────────────────────────────────────────────────── CLAVEX_DIR="${CLAVEX_DIR:-$HOME/.clavex}" CLAVEX_PORT="${CLAVEX_PORT:-8080}" CLAVEX_BASE_DOMAIN="${CLAVEX_BASE_DOMAIN:-localhost:${CLAVEX_PORT}}" CLAVEX_COMPOSE_URL="${CLAVEX_COMPOSE_URL:-https://raw.githubusercontent.com/clavex-eu/clavex/v3.0.1/docker-compose.minimal.yml}" COMPOSE_FILE="$CLAVEX_DIR/docker-compose.yml" ENV_FILE="$CLAVEX_DIR/.env" # ── Colour helpers ───────────────────────────────────────────────────────────── RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BOLD='\033[1m'; RESET='\033[0m' info() { printf "${GREEN} ✓${RESET} %s\n" "$*"; } warn() { printf "${YELLOW} ⚠${RESET} %s\n" "$*"; } error() { printf "${RED} ✗${RESET} %s\n" "$*" >&2; } step() { printf "\n${BOLD}▶ %s${RESET}\n" "$*"; } die() { error "$*"; exit 1; } # ── Banner ──────────────────────────────────────────────────────────────────── printf "\n${BOLD}" cat <<'EOF' ____ _ / ___|| | __ ___ _____ __ __ | | | |/ _` \ \ / / _ \\ \/ / | |___ | | (_| |\ V / __/ > < \____||_|\__,_| \_/ \___|/_/\_\ Identity platform — self-hosted installer EOF printf "${RESET}\n" # ── Prerequisite checks ─────────────────────────────────────────────────────── step "Checking prerequisites" check_cmd() { command -v "$1" &>/dev/null || die "Required command not found: $1 — please install it and retry." } check_cmd docker check_cmd openssl # Docker must be running docker info &>/dev/null || die "Docker daemon is not running. Start Docker and retry." # Compose v2 (docker compose subcommand) docker compose version &>/dev/null || die "Docker Compose v2 is required. Install the Compose plugin: https://docs.docker.com/compose/install/" # Download helper (prefer curl, fall back to wget) if command -v curl &>/dev/null; then FETCH="curl -fsSL" elif command -v wget &>/dev/null; then FETCH="wget -qO-" else die "Neither curl nor wget found. Install one and retry." fi info "Docker: $(docker --version)" info "Docker Compose: $(docker compose version)" info "OpenSSL: $(openssl version)" # ── Installation directory ──────────────────────────────────────────────────── step "Setting up installation directory: $CLAVEX_DIR" mkdir -p "$CLAVEX_DIR" chmod 700 "$CLAVEX_DIR" info "Directory ready: $CLAVEX_DIR" # ── Generate secrets ────────────────────────────────────────────────────────── step "Generating cryptographic secrets" gen_secret() { openssl rand -hex 32; } # Only generate if .env does not already exist (idempotent re-runs). if [[ -f "$ENV_FILE" ]]; then warn ".env already exists — reusing existing secrets." warn "Delete $ENV_FILE and re-run to rotate secrets." else DB_PASSWORD=$(gen_secret) REDIS_PASSWORD=$(gen_secret) ADMIN_SECRET=$(gen_secret) # Generate RSA signing key for OIDC token signing SIGNING_KEY_FILE="$CLAVEX_DIR/signing.pem" if [[ ! -f "$SIGNING_KEY_FILE" ]]; then openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out "$SIGNING_KEY_FILE" 2>/dev/null chmod 600 "$SIGNING_KEY_FILE" info "RSA signing key: $SIGNING_KEY_FILE" fi cat > "$ENV_FILE" < "$COMPOSE_FILE" || die "Failed to download: $CLAVEX_COMPOSE_URL" info "Compose file: $COMPOSE_FILE" # ── Patch compose to mount the signing key ──────────────────────────────────── # The signing key lives in CLAVEX_DIR on the host; mount it into /data. # We do this by appending a host-path volume override if not already present. if ! grep -q "signing.pem" "$COMPOSE_FILE"; then # Append a volume override for the signing key using Docker Compose syntax. cat >> "$COMPOSE_FILE" < "$OVERRIDE_FILE" </dev/null || echo "000") if [[ "$STATUS" == "200" ]]; then printf "\n" info "Clavex is ready!" break fi printf "." sleep 3 ATTEMPT=$((ATTEMPT + 1)) done if [[ $ATTEMPT -ge $MAX_ATTEMPTS ]]; then printf "\n" warn "Clavex did not become healthy within 90s." warn "Check logs with: docker compose -f $COMPOSE_FILE logs clavex" fi # ── Open browser ────────────────────────────────────────────────────────────── APP_URL="http://localhost:${CLAVEX_PORT}" open_browser() { if command -v xdg-open &>/dev/null; then xdg-open "$1" &>/dev/null & elif command -v open &>/dev/null; then open "$1" else warn "Could not detect a browser. Open manually: $1" fi } open_browser "$APP_URL" # ── Summary ─────────────────────────────────────────────────────────────────── printf "\n${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n" printf "${GREEN}${BOLD} Clavex is running!${RESET}\n\n" printf " Web UI: ${BOLD}${APP_URL}${RESET}\n" printf " Install dir: ${CLAVEX_DIR}\n" printf " Secrets file: ${ENV_FILE}\n" printf "\n" printf " Manage: cd ${CLAVEX_DIR} && docker compose logs -f\n" printf " Stop: docker compose -f ${COMPOSE_FILE} down\n" printf " Upgrade: re-run this installer\n" printf "\n" printf " Enable FGA (OpenFGA ReBAC):\n" printf " docker compose -f ${COMPOSE_FILE} --profile fga up -d\n" printf " Then set CLAVEX_FGA_ENABLED=true in ${ENV_FILE} and restart.\n" printf "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n\n"