interactive config

This commit is contained in:
2025-11-30 18:15:57 +01:00
parent 62c12cceba
commit 8cb63d3342

View File

@@ -1,13 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
# --- CHECK PREREQUISITES ----------------------------------------------------- envFile=Docker/.env
envExample=Docker/env.example
echo "Checking Docker installation..." echo "Checking Docker installation..."
if ! command -v docker >/dev/null 2>&1; then if ! command -v docker >/dev/null 2>&1; then
echo "Docker not found. Install Docker? [y/N]" echo "Docker not found. Install Docker? [y/N]"
read -r install_docker read -r install_docker
if [ "$install_docker" = "y" ] || [ "$install_docker" = "Y" ]; then if [[ "$install_docker" =~ ^[Yy]$ ]]; then
curl -fsSL https://get.docker.com | sh curl -fsSL https://get.docker.com | sh
else else
echo "Docker is required. Exiting." echo "Docker is required. Exiting."
@@ -21,37 +22,41 @@ echo "Checking Docker Compose..."
if ! docker compose version >/dev/null 2>&1; then if ! docker compose version >/dev/null 2>&1; then
echo "Docker Compose plugin missing. You may need to update Docker." echo "Docker Compose plugin missing. You may need to update Docker."
exit 1 exit 1
else
echo "Docker Compose available."
fi fi
# --- LOAD ENV FILE ------------------------------------------------------------ echo "Preparing .env file..."
if [ ! -f $envFile ]; then
if [ -f $envExample ]; then
echo ".env not found. Creating interactively from .env.example."
> $envFile
if [ ! -f "Docker/.env" ]; then while IFS="=" read -r key val; do
echo ".env file not found in the current directory." [[ "$key" =~ ^#.*$ || -z "$key" ]] && continue
echo "Create one now? [y/N]" default_value=$(echo "$val" | sed 's/"//g')
read -r create_env printf "Value for $key (default: $default_value): "
if [ "$create_env" = "y" ] || [ "$create_env" = "Y" ]; then read -r user_value < /dev/tty
cp Docker/env.example Docker/.env 2>/dev/null || touch .env if [ -z "$user_value" ]; then
echo "Created .env (./Docker/.env). Edit it before continuing." echo "$key=$default_value" >> $envFile
exit 0 else
echo "$key=$user_value" >> $envFile
fi
done < $envExample
echo ".env created."
else else
echo "A .env file is required. Exiting." echo "No .env or .env.example found."
exit 1 echo "Creating an empty .env file for manual editing."
touch $envFile
fi fi
else else
echo "Using existing .env file (Docker/.env)." echo "Using existing .env. (found at $envFile)"
fi fi
# --- START DOCKER COMPOSE ----------------------------------------------------- echo "Start containers with docker compose up -d? [y/N]"
echo "Start containers now with docker compose up -d? [y/N]"
read -r start_containers read -r start_containers
if [[ "$start_containers" =~ ^[Yy]$ ]]; then
if [ "$start_containers" = "y" ] || [ "$start_containers" = "Y" ]; then
cd Docker
docker compose up -d docker compose up -d
echo "Containers started." echo "Containers started."
else else
echo "You can start containers manually with: docker compose up -d" echo "You can start them manually with: docker compose up -d"
fi fi