#!/bin/sh # # curl -fsSL https://warmbly.com/install.sh | sh # # Installs Warmbly on this machine: pull the published release images, write a # real .env and a compose file, start the stack, print the link that claims it. # No git clone, no Go, Rust, Node or Elixir toolchain, nothing compiled here. # # sh install.sh --wizard ask where the data lives, what is kept and for # how long, and how it is backed up # sh install.sh --dry-run print the exact files it would write, touch nothing # sh install.sh --help every flag, and the environment variable for each # # On reading this before running it: that is the right instinct, and it is why # the checksum is published next to it. The short version of what it does: # # * checks for docker, and offers to install it rather than doing so quietly # * creates one directory (default /opt/warmbly) and writes only inside it # * generates five secrets with openssl, writes them 0600, prints the two # that are unrecoverable and waits for you to say you have copied them # * resolves the newest release once and PINS it in .env, so every later # `docker compose up` in that directory is the same version. Never :latest # * runs `docker compose pull` and `docker compose up -d` # # It asks for sudo only for the steps that need it, names them when it does, # and never wants to be piped into sudo itself. Re-running it reconfigures in # place: it does not regenerate secrets, does not touch an existing data root, # and refuses a directory it did not create unless you pass --force. # # Verify before running, if you would rather: # # curl -fsSLO https://warmbly.com/install.sh # curl -fsSLO https://warmbly.com/install.sh.sha256 # sha256sum -c install.sh.sha256 # less install.sh && sh install.sh # # https://docs.warmbly.com/development/install/ set -eu # ───────────────────────────────────────────────────────────────────────── # Constants # ───────────────────────────────────────────────────────────────────────── SCRIPT_NAME="Warmbly installer" REPO="warmbly/warmbly" DEFAULT_REGISTRY="ghcr.io/warmbly/warmbly" DEFAULT_DIR="/opt/warmbly" DOCS="https://docs.warmbly.com" RELEASES_API="https://api.github.com/repos/${REPO}/releases" # The marker file that says this directory is ours. Its absence in a non-empty # directory is what --force overrides, so the installer can never take over a # path that belongs to something else by accident. MARKER=".warmbly-install" # Ports the stack publishes, in the order they are checked for collisions. # 3000 is the one that actually collides: half of self-hosted software wants it. PORT_BACKEND=8080 PORT_WEB=5173 PORT_ADMIN=5174 PORT_TRACKING=3000 PORT_REALTIME=4000 PORT_FORMS=8090 PORT_PORTAL=8095 # ───────────────────────────────────────────────────────────────────────── # Answers. Every one is a flag, an environment variable and a wizard question, # and the defaults here are exactly what the fast path installs. # ───────────────────────────────────────────────────────────────────────── DIR="${WARMBLY_DIR:-$DEFAULT_DIR}" HOSTNAME_ANSWER="${WARMBLY_HOST:-localhost}" TLS="${WARMBLY_TLS:-none}" DATA_ROOT="${WARMBLY_DATA_ROOT:-}" # empty = /data; "volumes" = docker named volumes BLOBS="${WARMBLY_BLOBS:-filesystem}" # filesystem | s3 COMPONENTS="${WARMBLY_COMPONENTS:-full}" # core | full PORTAL_ANSWER="${WARMBLY_PORTAL_DOMAIN:-}" # empty = derived like the forms host VERSION="${WARMBLY_VERSION:-}" # empty = resolve the newest release CHANNEL="${WARMBLY_CHANNEL:-stable}" REGISTRY="${WARMBLY_IMAGE_PREFIX:-$DEFAULT_REGISTRY}" EXTERNAL_DB="${WARMBLY_DATABASE_URL:-}" EXTERNAL_REDIS="${WARMBLY_REDIS_URL:-}" MAIL_MODE="${WARMBLY_MAIL:-log}" # log | smtp REGISTRATION="${WARMBLY_REGISTRATION:-invite_only}" UPDATE_CHECK="${WARMBLY_UPDATE_CHECK:-true}" BOOTSTRAP_EMAIL="${WARMBLY_BOOTSTRAP_EMAIL:-}" BOOTSTRAP_HASH="${WARMBLY_BOOTSTRAP_PASSWORD_HASH:-}" BACKUP_DIR="${WARMBLY_BACKUP_DIR:-}" # empty = no scheduled backup BACKUP_KEEP="${WARMBLY_BACKUP_KEEP:-14}" BACKUP_SCHEDULE="${WARMBLY_BACKUP_SCHEDULE:-daily}" BACKUP_KEYS="${WARMBLY_BACKUP_KEYS:-true}" BACKUP_S3="${WARMBLY_BACKUP_S3:-}" # Retention and sync, the data-control answers. They are written into .env as # one WARMBLY_SETTINGS_BOOTSTRAP document, applied on first boot and editable # in Instance > Instance settings from then on. SYNC_BACKFILL_DAYS="${WARMBLY_SYNC_BACKFILL_DAYS:-90}" SYNC_BACKFILL_MESSAGES="${WARMBLY_SYNC_BACKFILL_MESSAGES:-5000}" SYNC_DAILY_MAILBOX="${WARMBLY_SYNC_DAILY_MAILBOX:-2000}" SYNC_DAILY_ORG="${WARMBLY_SYNC_DAILY_ORG:-25000}" RET_ENGAGEMENT="${WARMBLY_RETENTION_ENGAGEMENT_DAYS:-365}" RET_FORMS="${WARMBLY_RETENTION_FORM_DAYS:-180}" RET_AUDIT="${WARMBLY_RETENTION_AUDIT_DAYS:-90}" RET_WARMUP_MAIL="${WARMBLY_RETENTION_WARMUP_MAIL_DAYS:-30}" RET_WARMUP_EVENTS="${WARMBLY_RETENTION_WARMUP_EVENT_DAYS:-365}" # S3 blob answers, only read when BLOBS=s3. S3_BUCKET="${WARMBLY_S3_BUCKET:-}" S3_ENDPOINT="${WARMBLY_S3_ENDPOINT:-}" S3_REGION="${WARMBLY_S3_REGION:-auto}" S3_KEY="${WARMBLY_S3_ACCESS_KEY_ID:-}" S3_SECRET="${WARMBLY_S3_SECRET_ACCESS_KEY:-}" # SMTP answers, only read when MAIL_MODE=smtp. SMTP_HOST=""; SMTP_PORT=""; SMTP_USER=""; SMTP_PASS=""; SMTP_SECURITY="starttls" SMTP_FROM="" # Reverse-proxy answer, only read when TLS=proxy. PROXY_CIDRS="${WARMBLY_TRUSTED_PROXIES:-172.16.0.0/12,10.0.0.0/8,192.168.0.0/16}" # ───────────────────────────────────────────────────────────────────────── # Modes # ───────────────────────────────────────────────────────────────────────── MODE=install # install | uninstall WIZARD=0 DEMO=0 ASSUME_YES=0 DRY_RUN=0 PRINT_ENV=0 FORCE=0 PURGE_DATA=0 USE_COLOR=1 # Appending is the default. The wizard reads as a transcript, nothing above it # is touched, and there is no way for a redraw to land on top of something # else. --clear opts into the full-screen version. USE_CLEAR=0 INTERACTIVE=0 TTY=/dev/tty # Filled in as the run proceeds. RESOLVED_TAG="" COMPOSE="docker compose" SUDO="" EXISTING=0 # The palette starts empty so that anything reachable before setup_term (--help, # an unknown flag) still prints under set -u. setup_term fills it in. ESC=""; R=""; B=""; DIM=""; SKY=""; GREEN=""; AMBER="" RED=""; GREY=""; WHITE=""; HIDE=""; SHOW="" COLS=80; WIDTH=76 # ───────────────────────────────────────────────────────────────────────── # Terminal: colour, cursor, and the drawing primitives everything else uses. # # Every escape sequence goes through these, so NO_COLOR, a pipe, a dumb # terminal and --no-color all degrade to plain text in one place instead of # leaking half-rendered ANSI into a log file. # ───────────────────────────────────────────────────────────────────────── setup_term() { # A wizard needs a keyboard. Piped into sh, stdin is the script itself, so # the terminal is reopened explicitly; without one, only the answered # (flag or environment) path can run. if [ -t 0 ] && [ -t 1 ]; then INTERACTIVE=1 TTY=/dev/stdin elif [ -c /dev/tty ] && ( exec 9<>/dev/tty ) 2>/dev/null && [ -t 1 ]; then INTERACTIVE=1 TTY=/dev/tty fi if [ -n "${NO_COLOR:-}" ] || [ "${TERM:-dumb}" = "dumb" ] || [ ! -t 1 ]; then USE_COLOR=0 fi if [ "$USE_COLOR" = 1 ]; then ESC=$(printf '\033') R="${ESC}[0m"; B="${ESC}[1m"; DIM="${ESC}[2m" SKY="${ESC}[38;5;39m" GREEN="${ESC}[38;5;42m"; AMBER="${ESC}[38;5;214m"; RED="${ESC}[38;5;203m" GREY="${ESC}[38;5;245m"; WHITE="${ESC}[38;5;255m" HIDE="${ESC}[?25l"; SHOW="${ESC}[?25h" else ESC=""; R=""; B=""; DIM=""; SKY=""; GREEN=""; AMBER="" RED=""; GREY=""; WHITE=""; HIDE=""; SHOW="" USE_CLEAR=0 fi # Clearing a terminal that is not ours to clear is never right. [ "$INTERACTIVE" = 1 ] || USE_CLEAR=0 # Width. Everything drawn inside a redraw loop is fitted to this, so # getting it wrong is what makes a menu draw over itself. Three sources, # because tput is missing on a minimal image and stty needs the terminal: # an exported COLUMNS wins, since that is how a caller says so explicitly. COLS="" case "${COLUMNS:-}" in ''|*[!0-9]*) ;; *) COLS=$COLUMNS ;; esac if [ -z "$COLS" ] && have tput; then COLS=$(tput cols 2>/dev/null || true) fi if [ -z "$COLS" ] && [ "$INTERACTIVE" = 1 ]; then COLS=$(stty size <"$TTY" 2>/dev/null | cut -d' ' -f2 || true) fi case "$COLS" in ''|*[!0-9]*) COLS=80 ;; esac # Clamped: a 300 column terminal should not get a 300 column rule, and # below the floor the boxes stop being boxes. [ "$COLS" -lt 44 ] && COLS=44 [ "$COLS" -gt 92 ] && COLS=92 WIDTH=$((COLS - 4)) } say() { printf '%s\n' "$*"; } out() { printf '%b\n' "$*"; } outn() { printf '%b' "$*"; } # Restore the cursor whatever happens: a Ctrl-C inside a spinner would # otherwise leave the operator's terminal without one. cleanup_term() { [ "$USE_COLOR" = 1 ] && printf '%b' "$SHOW" stty_sane } stty_sane() { [ "$INTERACTIVE" = 1 ] || return 0 stty sane <"$TTY" 2>/dev/null || true } trap 'cleanup_term' EXIT trap 'cleanup_term; printf "\n"; die "cancelled"' INT # clear_screen is opt-in (--clear). Wiping someone's terminal is a thing to be # asked for, not assumed, and a clear that the terminal declines leaves the # wizard drawing over whatever was already there. ESC[3J is deliberately not # sent: it erases the scrollback buffer, and the conversation above this # command is not ours to delete. clear_screen() { [ "$USE_CLEAR" = 1 ] || return 0 printf '%b' "${ESC}[H${ESC}[2J" } repeat_char() { # $1 char, $2 count. printf pads with spaces and sed swaps them for the # character: no loop and no fork per character, which is what keeps the # redraws smooth. sed rather than tr because tr maps byte to byte and every # box-drawing character here is three bytes of UTF-8. _n=$2 [ "$_n" -lt 1 ] && { printf ''; return; } printf "%${_n}s" "" | sed "s/ /$1/g" } rule() { out "${DIM}$(repeat_char '─' "$WIDTH")${R}"; } # fit truncates plain text to n columns. # # It is what keeps the in-place redraws honest: a line longer than the terminal # wraps onto a second physical row, and every cursor-up in this script counts # LOGICAL rows, so one long option hint is enough to make a menu redraw over # itself and over whatever was on screen before it. Applied to everything drawn # inside a loop; prose printed once is free to wrap. fit() { _t=$1; _w=$2 [ "$_w" -lt 12 ] && _w=12 if [ "${#_t}" -le "$_w" ]; then printf '%s' "$_t" return 0 fi printf '%.*s...' "$((_w - 3))" "$_t" } # A rounded box. Content comes on stdin, one line per row, already coloured. # The border colour is $1. box() { _c="${1:-$DIM}" out "${_c}╭$(repeat_char '─' $((WIDTH - 2)))╮${R}" while IFS= read -r _line; do _plain=$(strip_ansi "$_line") # A content line wider than the box turns the border into a ragged # edge. Truncating costs the line its colour, which is a better trade # than a box that is not one. if [ "${#_plain}" -gt $((WIDTH - 4)) ]; then _line=$(fit "$_plain" $((WIDTH - 4))) _plain=$_line fi _pad=$((WIDTH - 4 - ${#_plain})) [ "$_pad" -lt 0 ] && _pad=0 printf '%b %s%s %b\n' "${_c}│${R}" "$_line" "$(repeat_char ' ' "$_pad")" "${_c}│${R}" done out "${_c}╰$(repeat_char '─' $((WIDTH - 2)))╯${R}" } # strip_ansi is what makes the borders line up: the padding is computed on the # printable text, not on the byte length of a coloured string. ${#} counts # bytes in a POSIX shell, so box CONTENT is kept ASCII; the border itself is # printed rather than measured, and may be anything. strip_ansi() { printf '%s' "$1" | sed "s/$(printf '\033')\[[0-9;]*m//g" } # ───────────────────────────────────────────────────────────────────────── # The wordmark. Drawn once at the top of the run, one row at a time so it # arrives rather than appears. Falls back to a single bold line when the # terminal is not ours to animate. # ───────────────────────────────────────────────────────────────────────── banner() { if [ "$USE_COLOR" = 0 ] || [ "$COLS" -lt 60 ]; then # The block wordmark is 56 columns wide, so on anything narrower it # wraps into noise. One line says the same thing. say "" out " ${B}${SKY}WARMBLY${R} ${DIM}installer${R}" say "" return fi printf '%b' "$HIDE" say "" _i=0 printf '%s\n' \ "██ ██ █████ ██████ ███ ███ ██████ ██ ██ ██" \ "██ █ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██" \ "██ ███ ██ ███████ ██████ ██ ████ ██ ██████ ██ ███ " \ "████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ " \ " ██ ██ ██ ██ ██ ██ ██ ██ ██████ ██████ ██ " \ | while IFS= read -r _row; do _i=$((_i + 1)) case "$_i" in 1|2) _tone="${ESC}[38;5;33m" ;; 3) _tone="${ESC}[38;5;39m" ;; *) _tone="${ESC}[38;5;74m" ;; esac printf ' %b%s%b\n' "$_tone" "$_row" "$R" nap 0.03 done printf ' %b%s%b\n\n' "$DIM" "email warmup and cold outreach, on your own machine" "$R" printf '%b' "$SHOW" } # nap sleeps a fraction of a second where the shell can, and not at all where # it cannot. Animation is a nicety; a busybox sleep that rejects "0.03" must # not turn into an error under set -e. nap() { [ "$USE_COLOR" = 1 ] || return 0 sleep "$1" 2>/dev/null || true } # ───────────────────────────────────────────────────────────────────────── # Messages # ───────────────────────────────────────────────────────────────────────── info() { out " ${SKY}·${R} $*"; } ok() { out " ${GREEN}✓${R} $*"; } warn() { out " ${AMBER}!${R} $*"; } # note is the explanatory prose under a question. It is wrapped to the # terminal rather than hand-wrapped to 72 columns, because the hand-wrapped # version is ragged on anything narrower and this is the only text in the # script long enough to care. note() { if [ "$COLS" -ge 78 ] || ! have fold; then out " ${DIM}$*${R}" return 0 fi printf '%s\n' "$*" | fold -s -w $((COLS - 6)) | while IFS= read -r _l; do out " ${DIM}${_l}${R}" done } step() { out "\n ${B}$*${R}"; } die() { cleanup_term out "\n ${RED}✗${R} ${B}$*${R}\n" >&2 exit 1 } # fail_with prints the error and, under it, what to do about it. An installer # that stops without a next step is a support ticket. fail_with() { _msg=$1; shift cleanup_term out "\n ${RED}✗${R} ${B}${_msg}${R}" >&2 for _l in "$@"; do out " ${DIM}${_l}${R}" >&2; done out "" >&2 exit 1 } # ───────────────────────────────────────────────────────────────────────── # The stepper: where the wizard is, drawn at the top of every question. # ───────────────────────────────────────────────────────────────────────── STEP_TITLES="Where it lives|How it is reached|Where the data sits|Keys and secrets|What is kept|Backups|Who gets in|Footprint|Review" STEP_TOTAL=9 STEP_CURRENT=0 stepper() { STEP_CURRENT=$1 if [ "$USE_CLEAR" = 1 ]; then clear_screen else # Appending, so the steps need their own separator or they run into # each other and into whatever was on screen before the installer. say "" rule fi if [ "$USE_COLOR" = 0 ]; then say "" say "Step ${STEP_CURRENT} of ${STEP_TOTAL}: $(step_title "$STEP_CURRENT")" say "" return fi say "" _line=" " _i=1 while [ "$_i" -le "$STEP_TOTAL" ]; do if [ "$_i" -lt "$STEP_CURRENT" ]; then _line="${_line}${GREEN}●${R}" elif [ "$_i" -eq "$STEP_CURRENT" ]; then _line="${_line}${SKY}◉${R}" else _line="${_line}${DIM}○${R}" fi [ "$_i" -lt "$STEP_TOTAL" ] && _line="${_line}${DIM}──${R}" _i=$((_i + 1)) done out "$_line ${DIM}step ${STEP_CURRENT}/${STEP_TOTAL}${R}" out " ${B}${WHITE}$(step_title "$STEP_CURRENT")${R}" say "" } step_title() { printf '%s' "$STEP_TITLES" | cut -d'|' -f"$1" } # ───────────────────────────────────────────────────────────────────────── # Spinner. Runs a command in the background and animates until it finishes, # then leaves one settled line behind: a tick, or a cross and the log. # ───────────────────────────────────────────────────────────────────────── SPIN_FRAMES="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏" # spin