# abort script on any command that exit with a non zero value
set -e

version="0.8.2"
echo "Package Ipsec-tools version: $version"

name="ipsec-tools-$version"

archive=ipsec-tools-$version.tar.bz2

if [[ -f $archive ]] ; then
  echo "Archive: $archive found"
else
  echo "Archive: $archive not found"
  exit 1
fi

echo "Extracting archive..."
tar xkf $archive

if [[ $? != 0 ]] ; then
  echo "Cannot unpack ipsec-tools: $archive"
  exit 1
fi


export PKG_DIR=${BOSH_INSTALL_TARGET}
export JOB_DIR=/var/vcap/jobs/ipsec
export DATA_DIR=/var/vcap/store/ipsec

## configure
cd $name
CFLAGS=-fno-strict-aliasing ./configure  \
--enable-natt \
--enable-dpd \
--disable-ipv6 \
--disable-security-context \
--with-kernel-headers=/usr/include/ \
--prefix=${PKG_DIR} \
--exec-prefix=${PKG_DIR} \
--sharedstatedir=${DATA_DIR}/com \
--localstatedir=${DATA_DIR}/var \
--sysconfdir=${JOB_DIR}/etc \
--datadir=${PKG_DIR}


make && make install
