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

bundle_cmd=/var/vcap/packages/ruby/bin/bundle
mysqlclient_dir=/var/vcap/packages/mysqlclient
libpq_dir=/var/vcap/packages/libpq

cp -a ${BOSH_COMPILE_TARGET}/{admin_ui,vcap-common} ${BOSH_INSTALL_TARGET}

cd ${BOSH_INSTALL_TARGET}/admin_ui
$bundle_cmd config build.mysql2 --with-mysql-config=$mysqlclient_dir/bin/mysql_config
$bundle_cmd config build.pg --with-pg-lib=$libpq_dir/lib --with-pg-include=$libpq_dir/include
$bundle_cmd config build.sequel_pg --with-pg-lib=$libpq_dir/lib --with-pg-include=$libpq_dir/include
$bundle_cmd config build.sqlite3 --with-sqlite3-dir=/var/vcap/packages/sqlite
$bundle_cmd install --local --deployment --without=development test

cd ${BOSH_INSTALL_TARGET}/vcap-common
$bundle_cmd install --local --deployment --without=development test
