#!/bin/bash

if [ -z ${RUST_CLASS_ROOT+x} ]; then echo "RUST_CLASS_ROOT is unset"; else echo "var is set to '$RUST_CLASS_ROOT'"; fi
if [ -z ${SL_CLASS_ROOT+x} ]; then echo "SL_CLASS_ROOT is unset"; else echo "var is set to '$SL_CLASS_ROOT'"; fi
if [ -z ${MTI_CLASS_ROOT+x} ]; then echo "MTI_CLASS_ROOT is unset"; else echo "var is set to '$MTI_CLASS_ROOT'"; fi

## declare classes directories
declare -a arr=("$RUST_CLASS_ROOT" "$SL_CLASS_ROOT" "$MTI_CLASS_ROOT")

## now loop through the above array
for i in "${arr[@]}"
do
	echo "Deploying $i"
	## pull them
	git -C $i pull
	## deploy
	make deploy -C $i
done

docker stop rustclass
docker build -t rustclasscont .
docker run --rm \
        --mount src=$RUST_CLASS_ROOT/prog_seq,target=/usr/share/nginx/html/prog_seq/,type=bind\
        --mount src=$SL_CLASS_ROOT/sol,target=/usr/share/nginx/html/sol/,type=bind\
        --mount src=$MTI_CLASS_ROOT/mti,target=/usr/share/nginx/html/mti/,type=bind\
        --name rustclass -p 80:80 -p 443:443 -d rustclasscont
