#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT_DIR" require_config() { local config=$1 local expected=$2 if ! grep -Fq "$expected" <<<"$config"; then echo "Missing expected docker compose config value:" echo " $expected" exit 1 fi } require_env() { local output=$1 local expected=$2 if ! grep -Fxq "$expected" <<<"$output"; then echo "Missing expected derived env value:" echo " $expected" echo "Observed:" echo "$output" exit 1 fi } config="$( FRONTEND_PORT=3100 BACKEND_PORT=9100 docker compose \ --env-file .env.example \ -f docker-compose.selfhost.yml \ config )" require_config "$config" 'published: "3100"' require_config "$config" 'published: "9100"' require_config "$config" 'FRONTEND_ORIGIN: http://localhost:3100' require_config "$config" 'GOOGLE_REDIRECT_URI: http://localhost:3100/auth/callback' require_config "$config" 'MULTICA_APP_URL: http://localhost:3100' for script in scripts/dev.sh scripts/check.sh; do if ! grep -Fq '. scripts/local-env.sh' "$script"; then echo "$script must source scripts/local-env.sh for shared local env derivation." exit 1 fi done tmp_env="$(mktemp)" trap 'rm -f "$tmp_env"' EXIT sed 's/^FRONTEND_PORT=.*/FRONTEND_PORT=3100/' .env.example >"$tmp_env" printf '\nBACKEND_PORT=9100\n' >>"$tmp_env" local_env="$( env -i PATH="$PATH" bash -c ' set -euo pipefail env_file=$1 set -a # shellcheck disable=SC1090 . "$env_file" set +a # shellcheck disable=SC1091 . scripts/local-env.sh printf "%s\n" \ "PORT=${PORT}" \ "FRONTEND_PORT=${FRONTEND_PORT}" \ "FRONTEND_ORIGIN=${FRONTEND_ORIGIN}" \ "MULTICA_APP_URL=${MULTICA_APP_URL}" \ "GOOGLE_REDIRECT_URI=${GOOGLE_REDIRECT_URI}" \ "MULTICA_SERVER_URL=${MULTICA_SERVER_URL}" \ "LOCAL_UPLOAD_BASE_URL=${LOCAL_UPLOAD_BASE_URL}" \ "PLAYWRIGHT_BASE_URL=${PLAYWRIGHT_BASE_URL}" ' _ "$tmp_env" )" require_env "$local_env" 'PORT=9100' require_env "$local_env" 'FRONTEND_PORT=3100' require_env "$local_env" 'FRONTEND_ORIGIN=http://localhost:3100' require_env "$local_env" 'MULTICA_APP_URL=http://localhost:3100' require_env "$local_env" 'GOOGLE_REDIRECT_URI=http://localhost:3100/auth/callback' require_env "$local_env" 'MULTICA_SERVER_URL=ws://localhost:9100/ws' require_env "$local_env" 'LOCAL_UPLOAD_BASE_URL=http://localhost:9100' require_env "$local_env" 'PLAYWRIGHT_BASE_URL=http://localhost:3100' echo "self-host env derivation ok"