github.com/weedge/lib@v0.0.0-20230424045628-a36dcc1d90e4/.devcontainer/reinstall-cmake.sh (about)

     1  #!/usr/bin/env bash
     2  #-------------------------------------------------------------------------------------------------------------
     3  # Copyright (c) Microsoft Corporation. All rights reserved.
     4  # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
     5  #-------------------------------------------------------------------------------------------------------------
     6  #
     7  set -e
     8  
     9  CMAKE_VERSION=${1:-"none"}
    10  
    11  if [ "${CMAKE_VERSION}" = "none" ]; then
    12      echo "No CMake version specified, skipping CMake reinstallation"
    13      exit 0
    14  fi
    15  
    16  # Cleanup temporary directory and associated files when exiting the script.
    17  cleanup() {
    18      EXIT_CODE=$?
    19      set +e
    20      if [[ -n "${TMP_DIR}" ]]; then
    21          echo "Executing cleanup of tmp files"
    22          rm -Rf "${TMP_DIR}"
    23      fi
    24      exit $EXIT_CODE
    25  }
    26  trap cleanup EXIT
    27  
    28  
    29  echo "Installing CMake..."
    30  apt-get -y purge --auto-remove cmake
    31  mkdir -p /opt/cmake
    32  
    33  architecture=$(dpkg --print-architecture)
    34  case "${architecture}" in
    35      arm64)
    36          ARCH=aarch64 ;;
    37      amd64)
    38          ARCH=x86_64 ;;
    39      *)
    40          echo "Unsupported architecture ${architecture}."
    41          exit 1
    42          ;;
    43  esac
    44  
    45  CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
    46  CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
    47  TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)
    48  
    49  echo "${TMP_DIR}"
    50  cd "${TMP_DIR}"
    51  
    52  curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
    53  curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O
    54  
    55  sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
    56  sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license
    57  
    58  ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake