#!/bin/bash

cd DOCKER

if [[ $1 == "gen" ]]
	then
		echo "it's Gonna Take a Little Bit Longer .... "
		echo -e "UID=$(id -u)\nGID=$(id -g)" > .env
		echo -n "Running generation of isen-gen-exam docker image : "
		docker build . --no-cache -t isen-gen-exam &> /dev/null
		[[ "$?" -ne 0 ]] && echo FAILED || echo OK
		exit
fi


if [[ -z $(docker image ls | grep isen-gen-exam) ]]
then
	echo "NO IMAGE : $0 gen"
	exit 2
fi

if [[ $1 == "debug" ]]
	then 
		touch .tmp 
		echo "Connect to another terminal and type : docker exec -ti isen-gen-exam bash"
		echo "When the debug is finished '[CTRL+C] here'"
		docker-compose up &> /dev/null
	else 
		echo "START GenPanDoc"
		docker-compose up 2>&1 | grep 'gen-doc_1  |'|cut -d"|" -f2 | sed "s/^/\t* /g"
	fi
echo -n "STOP GenPanDoc : "
docker-compose down  &> /dev/null
[[ $? -eq 0 ]] && echo OK || echo FAILED
[[ -f ../.tmp ]] && rm ../.tmp 
