#!/bin/bash 

export SEMAPHORE=/tmp/semaphore

if [ -f $SEMAPHORE ]
then
	# we have been started
	# do nothing
	echo ` date` 
	echo not doing a darn thing as semaphore is set
	peter=paul
	exit
else
	# first remove anything that will cause problems
	# (only do this on startup)
	#LIST=`docker ps -a  | grep auto | awk '{ print $1}'` 
	LIST=`docker ps -a | grep -v "CONTAINER ID" | awk '{ print $1}'` 
	#echo $LIST

	docker rm $LIST 

	sleep 5

	# start up our xds-server
	cd /home/admin
	# from online docs
	mkdir -p /tmp/xds-server/logs
	chown -R admin:admin /tmp/xds-server
	chmod -R 777 /tmp/xds-server
	# from XDS_usersguide.pdf
	mkdir -p /tmp/logs
	chmod -R 777 /tmp/logs
	chown -R admin:admin /tmp/logs
	bash ./xds-docker-create-container.sh -nuu --volume /my-workspace:$HOME/my-workspace

	touch $SEMAPHORE
	chmod 777 $SEMAPHORE
fi

