#!/bin/bash

# Define the paths to the Singularity definition files and the output directories
CONTAINERS_DIR="./containers"

# Create directory for containers if it doesn't exist
mkdir -p $CONTAINERS_DIR

# Define Singularity definition files and container names
declare -A CONTAINERS
CONTAINERS["fastqc"]="fastqc.def"
CONTAINERS["fastp"]="fastp.def"
CONTAINERS["bwa"]="bwa.def"
CONTAINERS["samtools"]="samtools.def"
CONTAINERS["bcftools"]="bcftools.def"

# Build each container
for TOOL in "${!CONTAINERS[@]}"
do
    DEF_FILE=${CONTAINERS[$TOOL]}
    CONTAINER_NAME="${CONTAINERS_DIR}/${TOOL}.sif"

    echo "Building Singularity container for $TOOL..."

    singularity build $CONTAINER_NAME $DEF_FILE

    if [ $? -eq 0 ]; then
        echo "$TOOL container built successfully!"
    else
        echo "Error building $TOOL container!"
        exit 1
    fi
done

echo "All containers built successfully!"
