sh 在Linux上安装Terraform和Packer

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 在Linux上安装Terraform和Packer相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash
# Script prerequisite > install jq > https://stedolan.github.io
# ********************************************************************************************
# UPDATE: Check out Robert's repo here https://github.com/robertpeteuil/terraform-installer
#   Robert's repo is more built out and has more options around the installation process.
#   Cheers!  -Adron
# ********************************************************************************************

cd ~

# Prerequisites
if [ "$(uname)" == "Darwin" ]; then
    brew install jq
# For Linux
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
    sudo apt-get install --assume-yes jq
fi

# Get URLs for most recent versions
# For OS-X
if [ "$(uname)" == "Darwin" ]; then
    terraform_url=$(curl https://releases.hashicorp.com/index.json | jq '{terraform}' | egrep "darwin.*64" | sort --version-sort -r | head -1 | awk -F[\"] '{print $4}')
    packer_url=$(curl https://releases.hashicorp.com/index.json | jq '{packer}' | egrep "darwin.*64" | sort --version-sort -r | head -1 | awk -F[\"] '{print $4}')
# For Linux
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
    terraform_url=$(curl https://releases.hashicorp.com/index.json | jq '{terraform}' | egrep "linux.*amd64" | sort --version-sort -r | head -1 | awk -F[\"] '{print $4}')
    packer_url=$(curl https://releases.hashicorp.com/index.json | jq '{packer}' | egrep "linux.*amd64" | sort --version-sort -r | head -1 | awk -F[\"] '{print $4}')
fi

# Create a move into directory.
cd
mkdir packer
mkdir terraform && cd $_

# Download Terraform. URI: https://www.terraform.io/downloads.html
echo "Downloading $terraform_url."
curl -o terraform.zip $terraform_url
# Unzip and install
unzip terraform.zip

# Change directory to Packer
cd ~/packer

# Download Packer. URI: https://www.packer.io/downloads.html
echo "Downloading $packer_url."
curl -o packer.zip $packer_url
# Unzip and install
unzip packer.zip

if [ "$(uname)" == "Darwin" ]; then
  echo '
  # Terraform & Packer Paths.
  export PATH=~/terraform/:~/packer/:$PATH
  ' >>~/.bash_profile

  source ~/.bash_profile
# For Linux
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
  echo '
  # Terraform & Packer Paths.
  export PATH=~/terraform/:~/packer/:$PATH
  ' >>~/.bashrc

  source ~/.bashrc
fi

以上是关于sh 在Linux上安装Terraform和Packer的主要内容,如果未能解决你的问题,请参考以下文章

Terraform安装指导01

Linux下SSH工具 PAC Manager的安装

Terraform 输出 linux 命令选项?

sh 自动更新ShadowsocksX的PAC。仅在OS X上测试过。(已弃用)

sh 自动更新ShadowsocksX的PAC。仅在OS X上测试过。(已弃用)

sh 自动更新ShadowsocksX的PAC。仅在OS X上测试过。(已弃用)