#!/bin/sh # Inferaz installer and upgrader for a Linux server. # # curl -fsSL https://get.inferaz.com | sh # # First run: installs Docker if missing, asks a few questions, writes /opt/inferaz/.env with # generated secrets and starts Inferaz. Later runs in the same directory upgrade it: they keep # .env and the data, pull the new release and restart. # # Everything comes from the public images ghcr.io/inferaz/inferaz-server and -web: the server # image carries this bundle (compose file, scripts, guide) in /app/bundle. # # Answers can be given in the environment instead of interactively (needed without a terminal): # INFERAZ_VERSION release to install or upgrade to (default: the latest release) # INFERAZ_DIR installation directory (default: /opt/inferaz) # INFERAZ_PUBLISH caddy (your domain, automatic HTTPS on this server) # | connect (no domain: -app.inferaz.app and so on, through Inferaz Connect) # | tunnel (your domain, your Cloudflare Tunnel) | proxy (your own reverse proxy) # INFERAZ_DOMAIN your domain (caddy, tunnel, proxy) # INFERAZ_NAME short name for the inferaz.app addresses (connect) # INFERAZ_LICENSE license text (required for connect; otherwise optional) # TUNNEL_TOKEN Cloudflare Tunnel token, with INFERAZ_PUBLISH=tunnel # INFERAZ_ADMIN first administrator's user name (default: admin) # INFERAZ_CHATBOT yes | no: run the Chatbot module service (default: no) set -eu VERSION="${INFERAZ_VERSION:-latest}" DIR="${INFERAZ_DIR:-/opt/inferaz}" IMAGES="${INFERAZ_IMAGES:-ghcr.io/inferaz/inferaz}" CONNECT_URL="${INFERAZ_CONNECT_URL:-https://connect.inferaz.com}" CONNECT_DOMAIN="${INFERAZ_CONNECT_DOMAIN:-inferaz.app}" bold() { printf '\033[1m%s\033[0m\n' "$*"; } die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2; exit 1; } has_tty() { (: /dev/null; } # ask VAR "question" [default]: keeps VAR when already set in the environment. ask() { eval "_cur=\${$1:-}" [ -n "$_cur" ] && return 0 _def="${3:-}" if has_tty; then printf '%s%s: ' "$2" "${_def:+ [$_def]}" >/dev/tty IFS= read -r _ans "$1.new" mv "$1.new" "$1" } [ "$(uname -s)" = Linux ] || die "Inferaz installs on Linux. On Windows or macOS, use Docker Desktop with docs/install.md." SUDO="" if [ "$(id -u)" != 0 ]; then command -v sudo >/dev/null || die "run as root, or install sudo" SUDO=sudo fi # ---------------------------------------------------------------- Docker if ! command -v docker >/dev/null 2>&1; then bold "Installing Docker (https://get.docker.com)" curl -fsSL https://get.docker.com | $SUDO sh fi $SUDO docker compose version >/dev/null 2>&1 || die "Docker Compose plugin missing: install docker-compose-plugin" # ---------------------------------------------------------------- release bold "Fetching Inferaz $VERSION" $SUDO docker pull -q "$IMAGES-server:$VERSION" >/dev/null RELEASE=$($SUDO docker run --rm --entrypoint printenv "$IMAGES-server:$VERSION" INFERAZ_VERSION) $SUDO mkdir -p "$DIR" # The bundle replaces the compose file and scripts; .env, docker-compose.override.yml and the data stay. $SUDO docker run --rm --entrypoint tar "$IMAGES-server:$VERSION" -C /app/bundle -cf - . | $SUDO tar -xf - -C "$DIR" cd "$DIR" # ---------------------------------------------------------------- upgrade if $SUDO test -f .env; then bold "Upgrading the installation in $DIR to $RELEASE" TMP=$(mktemp) $SUDO cat .env >"$TMP" setenv "$TMP" INFERAZ_VERSION "$RELEASE" # Installations from before the updater: turn it on (Admin -> Settings -> Updates). if ! grep -q '^INFERAZ_DIR=.' "$TMP"; then setenv "$TMP" INFERAZ_DIR "$DIR" p=$(grep '^COMPOSE_PROFILES=' "$TMP" | cut -d= -f2-) case ",$p," in *,updater,*) ;; *) setenv "$TMP" COMPOSE_PROFILES "${p:+$p,}updater" ;; esac fi $SUDO install -m 600 "$TMP" .env rm -f "$TMP" $SUDO docker compose pull -q $SUDO docker compose up -d --remove-orphans bold "Inferaz $RELEASE is running." exit 0 fi # ---------------------------------------------------------------- questions bold "New installation in $DIR" has_tty || [ -n "${INFERAZ_PUBLISH:-}${INFERAZ_DOMAIN:-}" ] || die "no terminal: set INFERAZ_PUBLISH, INFERAZ_DOMAIN (and the other answers) in the environment" if [ -z "${INFERAZ_PUBLISH:-}" ] && has_tty; then cat >/dev/tty <&2; rm -f "$CLAIM"; die "Inferaz Connect refused the request (HTTP $code)"; } val() { grep "^$1=" "$CLAIM" | head -1 | cut -d= -f2-; } TUNNEL_TOKEN=$(val TUNNEL_TOKEN) WEB=$(val WEB_PUBLIC_URL) GATE=$(val GATEWAY_PUBLIC_URL) AUTH=$(val KEYCLOAK_PUBLIC_URL) BOT=$(val CHATBOT_PUBLIC_URL) rm -f "$CLAIM" [ -n "$TUNNEL_TOKEN" ] && [ -n "$WEB" ] || die "unexpected answer from Inferaz Connect" ;; *) die "INFERAZ_PUBLISH must be caddy, connect, tunnel or proxy" ;; esac if [ -z "${INFERAZ_LICENSE:-}" ] && has_tty; then printf 'License (paste it, or press Enter to add it later in Admin -> Settings): ' >/dev/tty IFS= read -r INFERAZ_LICENSE /dev/null 2>&1 || printf 'warning: %s.%s does not resolve yet; HTTPS starts once it points at this server\n' "$h" "$INFERAZ_DOMAIN" done fi # ---------------------------------------------------------------- start bold "Starting Inferaz $RELEASE (the first start takes a few minutes)" $SUDO docker compose pull -q $SUDO docker compose up -d i=0 while [ "$($SUDO docker compose ps -a --format '{{.State}}' keycloak-setup 2>/dev/null)" != exited ]; do i=$((i + 5)); [ $i -gt 600 ] && die "keycloak-setup did not finish: see 'docker compose logs keycloak-setup' in $DIR" sleep 5 done PASSWORD_LINE=$($SUDO docker compose logs --no-log-prefix keycloak-setup 2>/dev/null | grep 'first administrator' | tail -1 || true) echo bold "Inferaz $RELEASE is running in $DIR" echo " Web app: $WEB" echo " AI clients (MCP): $GATE/mcp" echo " Identity: $AUTH (Keycloak admin console: user admin, password KEYCLOAK_ADMIN_PASSWORD in .env)" [ -n "$BOT" ] && echo " Chatbot: $BOT" echo " $PASSWORD_LINE" echo echo "Next:" echo " 1. Sign in at $WEB with \"Sign in with company account\" and set a new password." if [ -n "${INFERAZ_LICENSE:-}" ]; then echo " 2. The license is installed (check Admin -> Settings -> License)."; else echo " 2. Admin -> Settings -> License: paste your license."; fi echo " 3. Keep OpenBao's unseal key offline:" echo " cd $DIR && sudo docker compose run --rm --entrypoint cat openbao-init /keys/unseal-key" if [ "$INFERAZ_PUBLISH" = proxy ]; then echo " 4. Route your reverse proxy: $WEB -> 127.0.0.1:3000, $GATE -> 127.0.0.1:3001, $AUTH -> 127.0.0.1:8080${BOT:+, $BOT -> 127.0.0.1:3002}" fi if [ "$INFERAZ_PUBLISH" = tunnel ]; then echo " 4. In the tunnel's routes: app -> http://web:3000, gate -> http://gateway:3001, auth -> http://keycloak:8080${BOT:+, bot -> http://chatbot:3002}" fi echo "Upgrade later with the same command, or: sudo sh $DIR/install.sh"