#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")" mkdir -p data/db data/files export APP_HOST="${APP_HOST:-0.0.0.0}" export APP_PORT="${APP_PORT:-3000}" export DATABASE_URL="${DATABASE_URL:-sqlite://$(pwd)/data/db/rustpad.db?mode=rwc}" export FILES_DIR="${FILES_DIR:-$(pwd)/data/files}" export UPLOAD_MAX_SIZE_MB="${UPLOAD_MAX_SIZE_MB:-20}" export STATIC_DIR="${STATIC_DIR:-$(pwd)/static}" export RUST_LOG="${RUST_LOG:-rustpad=debug,tower_http=info}" # Generate a new asset version on each run to prevent stale HTML and JavaScript. export ASSET_VERSION="${ASSET_VERSION:-dev-$(date +%s)}" update_browser_libs() { local python_bin="" if command -v python3 >/dev/null 2>&1; then python_bin="python3" elif command -v python >/dev/null 2>&1; then python_bin="python" fi if [[ -z "$python_bin" ]]; then echo "Python 3 is required to download browser libraries for local Cargo development." >&2 return 1 fi echo "Checking browser libraries..." "$python_bin" scripts/update_browser_libs.py } if command -v cargo >/dev/null 2>&1; then if update_browser_libs; then echo "Cleaning RustPad build artifacts..." cargo clean --package rustpad echo "Starting RustPad..." exec cargo run --package rustpad fi if ! command -v docker >/dev/null 2>&1; then exit 1 fi echo "Local browser libraries could not be prepared; falling back to Docker." >&2 fi if command -v docker >/dev/null 2>&1; then export IMAGE_TAG="${IMAGE_TAG:-dev}" export BROWSER_LIBS_REFRESH="${BROWSER_LIBS_REFRESH:-dev-$(date +%s)}" echo "Starting RustPad with Docker..." exec docker compose up --build --force-recreate --remove-orphans fi echo "Neither Cargo nor Docker was found. Install Rust 1.85+ or Docker." >&2 exit 1