#!/bin/bash -ex
#
# setup up and run a docker build.
# this is used by travis.
#
# run the build and regression in a newly created container.
# pass the compiler from the travis matrix through CC, CXX.
# we need the default charmap to be UTF-8 for test_encoding_utf8, explicit set it here through LC_ALL.
# travis has got the code to test in the pwd.

ver=${1}
versuffix=${ver:+_$1}
docker run \
--rm \
--mount type=bind,source="$(pwd)",target=/app \
--env CC=$CC \
--env CXX=$CXX \
--env LC_ALL=C.UTF-8 \
--mount type=bind,source=/etc/passwd,target=/etc/passwd,readonly \
--mount type=bind,source=/etc/group,target=/etc/group,readonly \
--user "$(id -u):$(id -g)" \
tsteven4/gpsbabel_build_environment${versuffix} \
bash -c "if [ -n ${ver} ]; then if [ -e /opt/${ver}.env ]; then . /opt/${ver}.env; fi; fi; ./build_and_test"
