#!/bin/bash

if [[ $1 == "gen" ]]
	then
		echo "it's Gonna Take a Little Bit Longer .... "
		echo -e "UID=$(id -u)\nGID=$(id -g)" > .env
		cd $(dirname $0)/DOCKER/
		#docker build . --no-cache -t pandoc-gen-file-isen &> /dev/null
		docker build .  -t pandoc-gen-file-isen
		[[ "$?" -ne 0 ]] && echo FAILED || echo OK
		exit
fi

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

if [[ $1 == "debug" ]]
	then 
		echo "Connect to another terminal and type : docker exec -ti pandoc-gen-file-isen bash"
		echo "When the debug is finished '[CTRL+C] here'"
		docker run -ti -v $(pwd):/data -u 1000 pandoc-gen-file-isen bash
	else 
		cd $(realpath $(dirname $0))/DOCKER
		docker-compose up 
	fi
docker-compose down
[[ -f ../.tmp ]] && rm ../.tmp 
