1#!/bin/bash 2 3set -ex 4 5[ -n "$CMAKE_VERSION" ] 6 7# Remove system cmake install so it won't get used instead 8ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') 9case "$ID" in 10 ubuntu) 11 apt-get remove cmake -y 12 ;; 13 centos) 14 yum remove cmake -y 15 ;; 16 *) 17 echo "Unable to determine OS..." 18 exit 1 19 ;; 20esac 21 22# Turn 3.6.3 into v3.6 23path=$(echo "${CMAKE_VERSION}" | sed -e 's/\([0-9].[0-9]\+\).*/v\1/') 24file="cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz" 25 26# Download and install specific CMake version in /usr/local 27pushd /tmp 28curl -Os --retry 3 "https://cmake.org/files/${path}/${file}" 29tar -C /usr/local --strip-components 1 --no-same-owner -zxf cmake-*.tar.gz 30rm -f cmake-*.tar.gz 31popd 32