#!/usr/bin/bash # Check for .env file and create if it doesn't exist if [ ! -f .env ]; then echo "Creating .env file..." touch .env fi # Source .env file to load environment variables if [ -f .env ]; then source .env fi # Set APP_VERSION from .env VERSION, with fallback export APP_VERSION=${VERSION} # Allow local X server connections xhost +local: # Set environment variables export DISPLAY=":0" # Default to local display # Try to get IP address if hostname -I is available if command -v hostname >/dev/null 2>&1; then if hostname --help 2>&1 | grep -q -- "-I"; then IP=$(hostname -I 2>/dev/null | awk '{print $1}' || echo "") if [ -n "$IP" ]; then export DISPLAY="$IP:0" fi fi fi export SRC_PATH=$(pwd) export IMAGE="thechart:$APP_VERSION" export XAUTHORITY=$HOME/.Xauthority echo "Building and running the container..." echo "Using APP_VERSION=$APP_VERSION" echo "Using DISPLAY=$DISPLAY" echo "Using SRC_PATH=$SRC_PATH" echo "Using XAUTHORITY=$XAUTHORITY" # Check if debug mode is requested if [ "$1" = "debug" ]; then echo "Running in debug mode - will open shell instead of running app" docker-compose build docker run --rm -it \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v ${XAUTHORITY:-$HOME/.Xauthority}:/tmp/.docker.xauth:rw \ -e DISPLAY=${DISPLAY:-:0} \ -e XAUTHORITY=/tmp/.docker.xauth \ ${IMAGE} /bin/sh else # First run with debug to see the container's internal state echo "First entering container shell for debugging..." docker run --rm -it \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v ${XAUTHORITY:-$HOME/.Xauthority}:/tmp/.docker.xauth:rw \ -e DISPLAY=${DISPLAY:-:0} \ -e XAUTHORITY=/tmp/.docker.xauth \ ${IMAGE} /bin/sh # Then continue with normal operation if needed echo "Now running the container with docker-compose..." docker-compose up --build fi # Disallow local X server connections when done xhost -local: