#!/bin/bash # shellcheck shell=sh # --------------------------------------------------------- # Hi, savvy user! Thanks for reading the source. # # This script spins up ParadeDB locally via Docker. # It will: # 1. Check that Docker is installed and running # 2. Pull the latest ParadeDB image (or reuse an existing one) # 3. Start a container with a persistent volume # 4. Wait for Postgres to be ready # 5. Drop you straight into a psql session (when run from a terminal) # # Without a terminal (CI, a coding agent's tool call), the script skips # the confirmation prompt and the psql session, and prints the connection # details instead. # # Nothing is installed on your system outside of the ParadeDB # Docker image and associated volume. # # To uninstall, just run: docker rm -f paradedb && docker volume rm paradedb_data # --------------------------------------------------------- # The body of this script is intentionally POSIX-compatible, so it runs # under dash (which is /bin/sh on Debian and Ubuntu) as well as bash. # # `pipefail` is intentionally omitted because dash does not implement it. # @paradedb-skip-check-pipefail # Exit on subcommand errors set -eu SILENT=false for arg in "$@"; do case "$arg" in -y | --yes) SILENT=true ;; esac done # The script is usually piped into sh, so stdin is never a terminal. Probe # /dev/tty directly: it is only openable when there is a controlling terminal. HAS_TTY=false if (: /dev/null; then HAS_TTY=true fi CONTAINER_NAME="${PDB_CONTAINER_NAME:-paradedb}" VOLUME_NAME="${PDB_VOLUME_NAME:-paradedb_data}" IMAGE="${PDB_IMAGE:-paradedb/paradedb:latest}" PG_USER="${PDB_PG_USER:-postgres}" if [ -z "${PDB_PG_PASSWORD:-}" ]; then # Encode 32 random bytes directly: 64 hexadecimal characters, 256 bits. PG_PASSWORD="$(od -An -v -tx1 -N32 /dev/urandom | tr -d ' \n')" case "$PG_PASSWORD" in *[!0-9a-f]* | '') echo "Error: Could not generate a secure database password." >&2 exit 1 ;; esac if [ "${#PG_PASSWORD}" -ne 64 ]; then echo "Error: Could not generate a secure database password." >&2 exit 1 fi else PG_PASSWORD="$PDB_PG_PASSWORD" fi PG_DATABASE="${PDB_PG_DATABASE:-paradedb}" # Color support if [ -t 1 ] && [ "$(tput colors 2>/dev/null)" -ge 8 ] 2>/dev/null; then # printf rather than $'...', which dash does not understand RED=$(printf '\033[0;31m') GREEN=$(printf '\033[0;32m') CYAN=$(printf '\033[0;36m') PURPLE=$(printf '\033[38;5;99m') BOLD=$(printf '\033[1m') RESET=$(printf '\033[0m') else RED='' GREEN='' CYAN='' PURPLE='' BOLD='' RESET='' fi LOG=$(mktemp) trap 'rm -f "$LOG"' EXIT print_connect_cmd() { printf " %sdocker exec -it %s psql -U %s -d %s%s\n" "$CYAN" "$CONTAINER_NAME" "$PG_USER" "$PG_DATABASE" "$RESET" } print_connect_details() { echo " To connect interactively, run:" print_connect_cmd echo "" echo " To run a statement without a terminal:" printf " %sdocker exec %s psql -U %s -d %s -c 'SELECT version();'%s\n" "$CYAN" "$CONTAINER_NAME" "$PG_USER" "$PG_DATABASE" "$RESET" echo "" echo " Connection string:" printf " %spostgres://%s:%s@localhost:5432/%s%s\n" "$CYAN" "$PG_USER" "$PG_PASSWORD" "$PG_DATABASE" "$RESET" } run_with_spinner() { MSG="$1" shift "$@" >"$LOG" 2>&1 & PID=$! i=0 while kill -0 "$PID" 2>/dev/null; do dots=$((i % 3 + 1)) case $dots in 1) printf "\r %s. " "$MSG" ;; 2) printf "\r %s.. " "$MSG" ;; 3) printf "\r %s..." "$MSG" ;; esac i=$((i + 1)) sleep 0.4 done if wait "$PID"; then printf "\r %s... %sdone!%s\n" "$MSG" "$GREEN" "$RESET" else printf "\r %s... %sfailed!%s\n" "$MSG" "$RED" "$RESET" echo "" printf " %sError: %s failed.%s Details:\n" "$RED" "$MSG" "$RESET" >&2 sed 's/^/ /' "$LOG" >&2 exit 1 fi } printf "%s%s" "$PURPLE" "$BOLD" cat <<'BANNER' |||||||| |||||||| |||||||| ||||| |||||||| |||||||| |||||||| ||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| |||||||| ||||||||| |||||||| |||||||| |||||||| |||||||||||||| |||||||| |||||||| |||||||| ||||||||||||| |||||||| |||||||| |||||||| ||||||||||| |||||||| |||||||| |||||||| |||||||| BANNER printf "%s" "$RESET" printf " %sWelcome to ParadeDB%s (%shttps://paradedb.com%s)!\n" "$BOLD" "$RESET" "$CYAN" "$RESET" echo "" echo " Just use Postgres" echo " One Postgres for your application data, full-text search," echo " vector retrieval, and aggregations." echo "" echo " This script will:" echo " 1. Pull the latest ParadeDB Docker image" echo " 2. Start a container named '$CONTAINER_NAME' with a persistent volume ($VOLUME_NAME)" echo " 3. Expose PostgreSQL on port 5432" if [ "$HAS_TTY" = true ]; then echo " 4. Drop you into a psql session" else echo " 4. Print the connection details (no terminal detected, so no psql session)" fi echo "" echo " Nothing is installed on your system outside of Docker." echo " To uninstall later: docker rm -f $CONTAINER_NAME && docker volume rm $VOLUME_NAME" echo "" echo " Tip: Run with -y or --yes to skip this prompt next time." echo "" printf " %sStar us on GitHub to support ParadeDB and follow our progress.%s\n" "$BOLD" "$RESET" printf " %shttps://github.com/paradedb/paradedb%s\n" "$CYAN" "$RESET" echo "" printf " %sParadeDB Cloud is now available in private preview. Sign up:%s\n" "$BOLD" "$RESET" printf " %shttps://app.paradedb.com%s\n" "$CYAN" "$RESET" echo "" if [ "$SILENT" = false ] && [ "$HAS_TTY" = true ]; then printf " Continue? [Y/n] " read -r REPLY /dev/null 2>&1; then printf " %sError: Docker is not installed.%s To use ParadeDB, install it from https://docs.docker.com/get-docker/\n" "$RED" "$RESET" >&2 exit 1 fi if ! docker info >/dev/null 2>&1; then printf " %sError: Docker is not running.%s Please start Docker and try again.\n" "$RED" "$RESET" >&2 exit 1 fi if docker ps -a --format '{{.Names}}' | grep -Fxq "$CONTAINER_NAME"; then if docker ps --format '{{.Names}}' | grep -Fxq "$CONTAINER_NAME"; then printf " %sParadeDB is already running.%s\n" "$GREEN" "$RESET" echo "" echo " To connect interactively, run:" print_connect_cmd echo "" echo " To run a statement without a terminal:" printf " %sdocker exec %s psql -U %s -d %s -c 'SELECT version();'%s\n" "$CYAN" "$CONTAINER_NAME" "$PG_USER" "$PG_DATABASE" "$RESET" echo "" else printf " %sFound existing ParadeDB container.%s\n" "$BOLD" "$RESET" echo " To start it, run: docker start $CONTAINER_NAME" echo "" fi exit 0 else if docker volume ls --format '{{.Name}}' | grep -Fxq "$VOLUME_NAME"; then printf " %sError: Found existing %s volume, exiting...%s\n" "$RED" "$VOLUME_NAME" "$RESET" >&2 echo "" exit 1 fi run_with_spinner "Pulling ParadeDB Docker image" docker pull "$IMAGE" run_with_spinner "Starting ParadeDB" docker run -d --name "$CONTAINER_NAME" -e POSTGRES_USER="$PG_USER" -e POSTGRES_PASSWORD="$PG_PASSWORD" -e POSTGRES_DB="$PG_DATABASE" -v "$VOLUME_NAME:/var/lib/postgresql/" -p 5432:5432 "$IMAGE" fi wait_for_postgres() { retries=0 max_retries=10 until docker exec "$CONTAINER_NAME" pg_isready -U "$PG_USER" -d "$PG_DATABASE" >/dev/null 2>&1; do retries=$((retries + 1)) if [ "$retries" -ge "$max_retries" ]; then echo "PostgreSQL did not become ready after ${max_retries} attempts." return 1 fi sleep 3 done } run_with_spinner "Waiting for PostgreSQL to be ready" wait_for_postgres echo "" printf " %s%sParadeDB is ready!%s\n" "$GREEN" "$BOLD" "$RESET" echo "" printf " Password: %s%s%s\n" "$BOLD" "$PG_PASSWORD" "$RESET" printf " %sSave this password — it won't be shown again.%s\n" "$RED" "$RESET" echo "" print_connect_details echo "" printf " Get started with the docs: %shttps://www.paradedb.com/docs/start/introduction%s\n" "$CYAN" "$RESET" echo "" if [ "$HAS_TTY" != true ]; then # No terminal to hand psql, so stop here with everything needed to connect. exit 0 fi printf " %sLaunching psql...%s\n" "$BOLD" "$RESET" echo "" echo "" docker exec -it "$CONTAINER_NAME" psql -U "$PG_USER" -d "$PG_DATABASE"