github.com/terraform-linters/tflint@v0.51.2-0.20240520175844-3750771571b6/install_linux.sh (about) 1 #!/usr/bin/env bash 2 3 set -e 4 set -o pipefail 5 6 get_machine_arch () { 7 machine_arch="" 8 case $(uname -m) in 9 i386) machine_arch="386" ;; 10 i686) machine_arch="386" ;; 11 x86_64) machine_arch="amd64" ;; 12 arm64) machine_arch="arm64" ;; 13 aarch64) dpkg --print-architecture | grep -q "arm64" && machine_arch="arm64" || machine_arch="arm" ;; 14 esac 15 echo $machine_arch 16 } 17 arch=$(get_machine_arch) 18 19 echo "arch=$arch" 20 21 case "$(uname -s)" in 22 Darwin*) 23 os="darwin_${arch}" 24 ;; 25 MINGW64*) 26 os="windows_${arch}" 27 ;; 28 MSYS_NT*) 29 os="windows_${arch}" 30 ;; 31 *) 32 os="linux_${arch}" 33 ;; 34 esac 35 36 echo "os=$os" 37 38 echo -e "\n\n====================================================" 39 40 get_latest_release() { 41 headers=() 42 if [ -n "${GITHUB_TOKEN}" ]; then 43 headers=(-H "Authorization: Bearer ${GITHUB_TOKEN}") 44 fi 45 curl --fail -sS "${headers[@]}" "https://api.github.com/repos/terraform-linters/tflint/releases/latest" | # Get latest release from GitHub api 46 grep '"tag_name":' | # Get tag line 47 sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value 48 } 49 50 download_path=$(mktemp -d -t tflint.XXXXXXXXXX) 51 download_zip="${download_path}/tflint.zip" 52 download_executable="${download_path}/tflint" 53 54 if [ -z "${TFLINT_VERSION}" ] || [ "${TFLINT_VERSION}" == "latest" ]; then 55 echo "Looking up the latest version ..." 56 if [ -n "${GITHUB_TOKEN}" ]; then 57 echo "Requesting with GITHUB_TOKEN ..." 58 fi 59 version=$(get_latest_release) 60 else 61 version=${TFLINT_VERSION} 62 fi 63 64 echo "Downloading TFLint $version" 65 curl --fail -sS -L -o "${download_zip}" "https://github.com/terraform-linters/tflint/releases/download/${version}/tflint_${os}.zip" 66 echo "Downloaded successfully" 67 68 echo -e "\n\n====================================================" 69 echo "Unpacking ${download_zip} ..." 70 unzip -o "${download_zip}" -d "${download_path}" 71 if [[ $os == "windows"* ]]; then 72 dest="${TFLINT_INSTALL_PATH:-/bin}/" 73 echo "Installing ${download_executable} to ${dest} ..." 74 mv "${download_executable}" "$dest" 75 retVal=$? 76 if [ $retVal -ne 0 ]; then 77 echo "Failed to install tflint" 78 exit $retVal 79 else 80 echo "tflint installed at ${dest} successfully" 81 fi 82 else 83 dest="${TFLINT_INSTALL_PATH:-/usr/local/bin}/" 84 echo "Installing ${download_executable} to ${dest} ..." 85 86 if [[ -w "$dest" ]]; then SUDO=""; else 87 # current user does not have write access to install directory 88 SUDO="sudo"; 89 fi 90 91 $SUDO mkdir -p "$dest" 92 $SUDO install -c -v "${download_executable}" "$dest" 93 retVal=$? 94 if [ $retVal -ne 0 ]; then 95 echo "Failed to install tflint" 96 exit $retVal 97 fi 98 fi 99 100 echo "Cleaning temporary downloaded files directory ${download_path} ..." 101 rm -rf "${download_path}" 102 103 echo -e "\n\n====================================================" 104 echo "Current tflint version" 105 "${dest}/tflint" -v