#!/bin/bash
# Generate .env file for docker-compose
# Run this script to create your_processors local .env file

set -e

echo "Generating .env file for docker-compose..."

# Detect current user's home directory
if [ -z "$USER_HOME" ]; then
    USER_HOME="$HOME"
fi

# Define variables in the script's environment
HOST_USER_UID=$(id -u)
DOCKER_GROUP_ID=$(getent group docker | cut -d: -f3 || echo 999)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD || echo "master")

# Create .env file
cat > .env << EOF
# Docker Compose Environment Variables
# Generated by ./generate-env.sh

# User paths
PROJECTS_DIR=$USER_HOME/projects
USER_CONFIG_DIR=$USER_HOME/.config

# User/Group IDs
HOST_USER_UID=$HOST_USER_UID
DOCKER_GROUP_ID=$DOCKER_GROUP_ID

# Image and Container names
CURRENT_BRANCH=$CURRENT_BRANCH
EMACS_IMAGE_BRANCH=$CURRENT_BRANCH
EMACS_IMAGE_BASE=skewed-emacs
GENDL_IMAGE_BRANCH=$CURRENT_BRANCH
GENDL_IMAGE_BASE=gendl
NODE_IMAGE_BRANCH=$CURRENT_BRANCH
NODE_IMAGE_BASE=lisply-mcp

# Network name
DOCKER_NETWORK_NAME=skewed-network
EOF

echo ""
echo ".env file has the following settings:"
echo "CURRENT_BRANCH: $CURRENT_BRANCH"
echo "PROJECTS: $USER_HOME/projects"
echo "HOST_USER_UID: $HOST_USER_UID"  # Fixed typo: HOST_USER_ID to HOST_USER_UID
echo ""
