github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/install_linux.sh (about)

     1  #!/bin/bash -e
     2  
     3  processor=$(uname -m)
     4  
     5  if [ "$processor" == "x86_64" ]; then
     6    arch="amd64"
     7  else
     8    arch="386"
     9  fi
    10  
    11  case "$(uname -s)" in
    12    Darwin*)
    13      os="darwin_${arch}"
    14      ;;
    15    MINGW64*)
    16      os="windows_${arch}"
    17      ;;
    18    MSYS_NT*)
    19      os="windows_${arch}"
    20      ;;
    21    *)
    22      os="linux_${arch}"
    23      ;;
    24  esac
    25  
    26  echo "os=$os"
    27  
    28  echo -e "\n\n===================================================="
    29  
    30  get_latest_release() {
    31    curl --silent "https://api.github.com/repos/terraform-linters/tflint/releases/latest" | # Get latest release from GitHub api
    32      grep '"tag_name":' |                                                                  # Get tag line
    33      sed -E 's/.*"([^"]+)".*/\1/'                                                          # Pluck JSON value
    34  }
    35  
    36  if [[ -z "${TFLINT_VERSION}" ]]; then
    37    echo "Looking up the latest version ..."
    38    version=$(get_latest_release)
    39  else
    40    version=${TFLINT_VERSION}
    41  fi
    42  
    43  echo "Downloading TFLint $version"
    44  curl -L -o /tmp/tflint.zip "https://github.com/terraform-linters/tflint/releases/download/${version}/tflint_${os}.zip"
    45  retVal=$?
    46  if [ $retVal -ne 0 ]; then
    47    echo "Failed to download tflint_${os}.zip"
    48    exit $retVal
    49  else
    50    echo "Download was successfully"
    51  fi
    52  
    53  echo -e "\n\n===================================================="
    54  echo "Unpacking /tmp/tflint.zip ..."
    55  unzip -u /tmp/tflint.zip -d /tmp/
    56  if [[ $os == "windows"* ]]; then
    57    echo "Installing /tmp/tflint to /bin..."
    58    mv /tmp/tflint /bin/
    59    retVal=$?
    60    if [ $retVal -ne 0 ]; then
    61      echo "Failed to install tflint"
    62      exit $retVal
    63    else
    64      echo "tflint installed at /bin/ successfully"
    65    fi
    66  else
    67    echo "Installing /tmp/tflint to /usr/local/bin..."
    68    sudo mkdir -p /usr/local/bin
    69    sudo install -b -c -v /tmp/tflint /usr/local/bin/
    70    retVal=$?
    71    if [ $retVal -ne 0 ]; then
    72      echo "Failed to install tflint"
    73      exit $retVal
    74    else
    75      echo "tflint installed at /usr/local/bin/ successfully"
    76    fi
    77  fi
    78  
    79  echo "Cleaning /tmp/tflint.zip and /tmp/tflint ..."
    80  rm /tmp/tflint.zip /tmp/tflint
    81  
    82  echo -e "\n\n===================================================="
    83  echo "Current tflint version"
    84  tflint -v