#!/bin/bash

# Building a Docker image in which to execute tests
# will require a copy of the local Capo properties
# file, which can be found at /home/casa/capo
# on boxes that can see /home, but which on boxes
# that can't is likely to be at ~/home/.capo for
# any given user. Find local.properties and
# copy it to our test directory.

FILENAME=local.properties
CONTAINER_NAME=$1;shift
if [ -z ${CONTAINER_NAME} ]
then
  echo 'Usage: $0 <container_name>'
  exit 1
fi


if [ -e /home/casa/capo/${FILENAME} ]
then
    SOURCE=/home/casa/capo/${FILENAME}
elif [ -e ~/.capo/${FILENAME} ]
then
    SOURCE=~/.capo/${FILENAME}
else
  echo '${FILENAME} not found!'
  exit 1
fi

pwd
NEW_FILE=./test/${FILENAME}
# echo 'Copying ' ${SOURCE}
cp ${SOURCE} ${NEW_FILE}

# remove extended attributes, which would cause Capo to balk
/usr/bin/xattr -c ${NEW_FILE}

# (if cached stuff might be messing things up, add the --no-cache flag)
docker build . -f test/Dockerfile -t ${CONTAINER_NAME}

# now get rid of the properties file; containing sensitive info, it must NOT be saved or committed
rm -f ${FILENAME}

# to run the image: docker run ${CONTAINER_NAME}:latest
