reinstall-cmake.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. CMAKE_VERSION=${1:-"none"}
  9. if [ "${CMAKE_VERSION}" = "none" ]; then
  10. echo "No CMake version specified, skipping CMake reinstallation"
  11. exit 0
  12. fi
  13. # Cleanup temporary directory and associated files when exiting the script.
  14. cleanup() {
  15. EXIT_CODE=$?
  16. set +e
  17. if [[ -n "${TMP_DIR}" ]]; then
  18. echo "Executing cleanup of tmp files"
  19. rm -Rf "${TMP_DIR}"
  20. fi
  21. exit $EXIT_CODE
  22. }
  23. trap cleanup EXIT
  24. echo "Installing CMake..."
  25. apt-get -y purge --auto-remove cmake
  26. mkdir -p /opt/cmake
  27. architecture=$(dpkg --print-architecture)
  28. case "${architecture}" in
  29. arm64)
  30. ARCH=aarch64 ;;
  31. amd64)
  32. ARCH=x86_64 ;;
  33. *)
  34. echo "Unsupported architecture ${architecture}."
  35. exit 1
  36. ;;
  37. esac
  38. CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
  39. CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
  40. TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)
  41. echo "${TMP_DIR}"
  42. cd "${TMP_DIR}"
  43. curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
  44. curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O
  45. sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
  46. sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license
  47. ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
  48. ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest