From bb51d8daae89358ae9fb94ac931b1b891a562c32 Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Sun, 8 Oct 2023 17:03:26 -0400 Subject: [PATCH] Add mongocxx to Ubuntu 20 dependencies container image. --- .../core/tools/scripts/lib_install/mongoc.sh | 78 ++++++++++++++++++ .../tools/scripts/lib_install/mongocxx.sh | 81 +++++++++++++++++++ .../install-packages-from-source.sh | 2 + 3 files changed, 161 insertions(+) create mode 100644 components/core/tools/scripts/lib_install/mongoc.sh create mode 100644 components/core/tools/scripts/lib_install/mongocxx.sh diff --git a/components/core/tools/scripts/lib_install/mongoc.sh b/components/core/tools/scripts/lib_install/mongoc.sh new file mode 100644 index 000000000..9dffb5fe4 --- /dev/null +++ b/components/core/tools/scripts/lib_install/mongoc.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# Exit on any error +set -e + +cUsage="Usage: ${BASH_SOURCE[0]} [ <.deb output directory>]" +if [ "$#" -lt 1 ] ; then + echo $cUsage + exit +fi +version=$1 + +package_name=libmongoc-dev +temp_dir=/tmp/${package_name}-installation +deb_output_dir=${temp_dir} +if [[ "$#" -gt 1 ]] ; then + deb_output_dir="$(readlink -f "$2")" + if [ ! -d ${deb_output_dir} ] ; then + echo "${deb_output_dir} does not exist or is not a directory" + exit + fi +fi + +# Check if already installed +set +e +dpkg -l ${package_name} | grep ${version} +installed=$? +set -e +if [ $installed -eq 0 ] ; then + # Nothing to do + exit +fi + +echo "Checking for elevated privileges..." +privileged_command_prefix="" +if [ ${EUID:-$(id -u)} -ne 0 ] ; then + sudo echo "Script can elevate privileges." + privileged_command_prefix="${privileged_command_prefix} sudo" +fi + +# Download +mkdir -p $temp_dir +cd $temp_dir +extracted_dir=${temp_dir}/mongo-c-driver-${version} +if [ ! -e ${extracted_dir} ] ; then + tar_filename=mongo-c-driver-${version}.tar.gz + if [ ! -e ${tar_filename} ] ; then + curl -fsSL https://github.com/mongodb/mongo-c-driver/releases/download/${version}/${tar_filename} -o ${tar_filename} + fi + + tar -xf ${tar_filename} +fi + +# Set up +cd ${extracted_dir} +mkdir -p build +cd build +cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF \ + -DENABLE_TESTS=OFF \ + .. + +# Check if checkinstall is installed +set +e +command -v checkinstall +checkinstall_installed=$? +set -e + +# Install +install_command_prefix="${privileged_command_prefix}" +if [ $checkinstall_installed -eq 0 ] ; then + install_command_prefix="${install_command_prefix} checkinstall --pkgname '${package_name}' --pkgversion '${version}' --provides '${package_name}' --nodoc -y --pakdir \"${deb_output_dir}\"" +fi +${install_command_prefix} cmake --build . --target install + +# Clean up +rm -rf $temp_dir diff --git a/components/core/tools/scripts/lib_install/mongocxx.sh b/components/core/tools/scripts/lib_install/mongocxx.sh new file mode 100644 index 000000000..12fe7ac0b --- /dev/null +++ b/components/core/tools/scripts/lib_install/mongocxx.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# Exit on any error +set -e + +cUsage="Usage: ${BASH_SOURCE[0]} [ <.deb output directory>]" +if [ "$#" -lt 1 ] ; then + echo $cUsage + exit +fi +version=$1 + +package_name=libmongocxx-dev +temp_dir=/tmp/${package_name}-installation +deb_output_dir=${temp_dir} +if [[ "$#" -gt 1 ]] ; then + deb_output_dir="$(readlink -f "$2")" + if [ ! -d ${deb_output_dir} ] ; then + echo "${deb_output_dir} does not exist or is not a directory" + exit + fi +fi + +# Check if already installed +set +e +dpkg -l ${package_name} | grep ${version} +installed=$? +set -e +if [ $installed -eq 0 ] ; then + # Nothing to do + exit +fi + +echo "Checking for elevated privileges..." +privileged_command_prefix="" +if [ ${EUID:-$(id -u)} -ne 0 ] ; then + sudo echo "Script can elevate privileges." + privileged_command_prefix="${privileged_command_prefix} sudo" +fi + +# Download +mkdir -p $temp_dir +cd $temp_dir +extracted_dir=${temp_dir}/mongo-cxx-driver-r${version} +if [ ! -e ${extracted_dir} ] ; then + tar_filename=mongo-cxx-driver-r${version}.tar.gz + if [ ! -e ${tar_filename} ] ; then + curl -fsSL https://github.com/mongodb/mongo-cxx-driver/releases/download/r${version}/${tar_filename} -o ${tar_filename} + fi + + tar -xf ${tar_filename} +fi + +# Set up +cd ${extracted_dir}/build +# NOTE: Although the mongocxx docs indicate we should use +# '-DMONGOCXX_OVERRIDE_DEFAULT_INSTALL_PREFIX=OFF' to install to the default +# location (/usr/local) but this doesn't seem to work, so we specify +# CMAKE_INSTALL_PREFIX here +cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DBUILD_SHARED_AND_STATIC_LIBS=ON \ + -DENABLE_TESTS=OFF \ + .. + +# Check if checkinstall is installed +set +e +command -v checkinstall +checkinstall_installed=$? +set -e + +# Install +install_command_prefix="${privileged_command_prefix}" +if [ $checkinstall_installed -eq 0 ] ; then + install_command_prefix="${install_command_prefix} checkinstall --pkgname '${package_name}' --pkgversion '${version}' --provides '${package_name}' --nodoc -y --pakdir \"${deb_output_dir}\"" +fi +${install_command_prefix} cmake --build . --target install + +# Clean up +rm -rf $temp_dir diff --git a/components/core/tools/scripts/lib_install/ubuntu-focal/install-packages-from-source.sh b/components/core/tools/scripts/lib_install/ubuntu-focal/install-packages-from-source.sh index 583d80130..52b6c0d85 100755 --- a/components/core/tools/scripts/lib_install/ubuntu-focal/install-packages-from-source.sh +++ b/components/core/tools/scripts/lib_install/ubuntu-focal/install-packages-from-source.sh @@ -4,6 +4,8 @@ ./tools/scripts/lib_install/libarchive.sh 3.5.1 ./tools/scripts/lib_install/lz4.sh 1.8.2 ./tools/scripts/lib_install/mariadb-connector-c.sh 3.2.3 +./tools/scripts/lib_install/mongoc.sh 1.24.4 +./tools/scripts/lib_install/mongocxx.sh 3.8.0 ./tools/scripts/lib_install/msgpack.sh 6.0.0 ./tools/scripts/lib_install/spdlog.sh 1.9.2 ./tools/scripts/lib_install/zstandard.sh 1.4.9