install_cmake.sh
The install_cmake.sh
script installs a specific version of CMake, a widely-used cross-platform free and open-source software tool designed to manage the build process in a compiler-independent manner.
The script is straightforward, employing common bash scripting techniques for automation. Here's a detailed analysis of its components and actions:
Shebang and Bash Options
#!/bin/bash
: This line indicates that the script should be executed using the Bash shell.set -ex
: The-e
flag causes the script to exit immediately if any command exits with a non-zero status, ensuring that errors halt the script's execution. The-x
flag makes the script print each command to standard error (stderr) before it's executed, aiding in debugging.
Variables
ARCH=$(uname -m)
: Determines the architecture of the machine on which the script is running. This is important because the CMake binary to download depends on the system architecture (e.g.,x86_64
,arm64
).CMAKE_VERSION="3.24.4"
: Specifies the version of CMake to be installed. This can be modified to install different versions of CMake.PARSED_CMAKE_VERSION=$(echo $CMAKE_VERSION | sed 's/\.[0-9]*$//')
: This command attempts to parse the CMake version by removing the last segment (presumably for formatting purposes), but it seems to be unused in the script. This might be a remnant from a previous version of the script or prepared for future use.CMAKE_FILE_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}"
: Constructs the filename for the CMake tarball based on the specified version and the detected architecture.RELEASE_URL_CMAKE=https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_FILE_NAME}.tar.gz
: Forms the URL to download the CMake tarball from the official GitHub releases page of CMake.
Download and Installation Commands
The script downloads the CMake tarball using
wget
with the--no-verbose
option to minimise the output, placing the file in/tmp
.It then extracts the tarball to
/usr/local/
usingtar -xf
, which unpacks the contents into the directory, preserving the original directory structure contained within the tarball.A symbolic link is created from the extracted directory to
/usr/local/cmake
, making it easier to reference the CMake installation directory.
Environment Variable Update
Finally, the script appends an export
command to the environment variable file defined by the ${ENV}
variable, updating the PATH
to include the CMake binary directory.
This ensures that CMake can be invoked from any location within the container without specifying its full path.
Summary
The install_cmake.sh
script automates the process of downloading, extracting, and setting up CMake in a Docker container, adjusting for the container's architecture.
The use of ${ENV}
for updating the PATH
variable indicates that the script is designed to work within a larger setup where environmental variables are managed centrally, possibly for consistency across multiple scripts or container configurations.
Last updated