#!/bin/bash # Script to set HOST_SITE_URL environment variable based on detected host IP # This should be sourced before running Supabase CLI commands or docker-compose # Usage: source ./scripts/set-host-env.sh # Get the script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # Detect host IP HOST_IP=$("$SCRIPT_DIR/get-host-ip.sh") if [ $? -ne 0 ] || [ -z "$HOST_IP" ]; then echo "Warning: Could not detect host IP, using localhost" >&2 HOST_IP="127.0.0.1" fi # Set the environment variable # Default port is 3000, but can be overridden PORT="${HOST_PORT:-3000}" export HOST_SITE_URL="http://${HOST_IP}:${PORT}" # Only print messages if not being sourced (when run directly) if [ "${BASH_SOURCE[0]}" = "${0}" ]; then echo "Set HOST_SITE_URL=$HOST_SITE_URL" >&2 echo "To use this in your current shell, run:" >&2 echo " source $SCRIPT_DIR/set-host-env.sh" >&2 echo "Or export it manually:" >&2 echo " export HOST_SITE_URL=\"$HOST_SITE_URL\"" >&2 else # Being sourced - just set the variable silently (or with a brief message) echo "HOST_SITE_URL set to: $HOST_SITE_URL" >&2 fi