all repos — dotfiles @ 3038ed1044c49e77336c33ca2f61da7177aaaad3

linux dotfiles

bin/scripts/tfv (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
#!/bin/bash
set -eo pipefail

TFVDIR=$HOME/.local/share/tfv

if [ -z "$1" ]; then
    echo "usage: $0 <version>"
    exit 1
fi

if [ ! -d $TFVDIR ]; then
    mkdir -p $TFVDIR
fi

version=$1

# check if we have a terraform version already in TFVDIR
if [ -f "$TFVDIR/terraform_$version" ]; then
    mv "$TFVDIR/terraform_$version" ~/.local/bin
    echo "Ready to use terraform $version"
    exit 0
fi

wget -P "/tmp/tfv" "https://releases.hashicorp.com/terraform/$version/terraform_${version}_linux_amd64.zip"
unzip "/tmp/tfv/terraform_${version}_linux_amd64.zip" -d "$TFVDIR/terraform_${version}"
mv $TFVDIR/terraform_${version}/terraform ~/.local/bin
echo "Ready to use terraform $version"