#!/bin/bash
#If the needed docker image does not exist run the script to build it. Pass in that a backup .tar.gz image should not be made.
if [ ! "$(docker images -q acg/thesis_defense_latex:1.0 2> /dev/null)" ]; then
	cd ..
	export SAVE="No"
	bash DOCKER_THESIS_DEFENSE_LATEX.sh
	cd ./LATEX
fi
#If the docker container exists compile the Latex using the container, and output the pdf locally. 
	if [ "$(docker images -q acg/thesis_defense_latex:1.0 2> /dev/null)" ]; then
		docker run -d -t --name beamer_container acg/thesis_defense_latex:1.0
		docker cp ./ beamer_container:/LaTex
		docker exec beamer_container bash /LaTex/build.sh
		docker cp beamer_container:/LaTex/Defense.pdf ./
		docker stop beamer_container
		docker remove beamer_container
	fi
