dctlenv/libexec/dctlenv-install

49 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -uo pipefail
[ "$#" -gt 1 ] && log_error "Need 1 version instead of $#" 'usage: dctlenv install [<version>]'
version_requested="${1:-""}"
[ -n "$version_requested" ] || log_error 'Version is not specified' 'usage: dctlenv install [<version>]'
version="$(dctlenv-list-remote | grep "$version_requested" | head -n 1)"
[ -n "$version" ] || log_error "No version $version_requested found in remote"
dst_path="$DCTLENV_ROOT/versions/$version"
if [ -f "$dst_path/driftctl" ]; then
echo "driftctl v$version is already installed"
exit 0
fi
DCTLENV_ARCH="${DCTLENV_ARCH:-amd64}"
case "$(uname -s)" in
Darwin*)
os="darwin_$DCTLENV_ARCH"
;;
MINGW64*)
os="windows_$DCTLENV_ARCH"
;;
MSYS_NT*)
os="windows_$DCTLENV_ARCH"
;;
CYGWIN_NT*)
os="windows_$DCTLENV_ARCH"
;;
*)
os="linux_$DCTLENV_ARCH"
;;
esac
driftctl_url="https://github.com/cloudskiff/driftctl/releases/download"
tarball_name="driftctl_${version}_$os"
echo "Installing driftctl v$version"
echo "Downloading release tarball from $driftctl_url/v$version/driftctl_$os"
curlw -# -f -L -o "$dst_path/driftctl" --create-dirs "$driftctl_url/v$version/driftctl_$os" || log_error 'Tarball download failed'
echo "Making the $dst_path/driftctl binary executable"
chmod +x "$dst_path/driftctl"
echo "Installation of driftctl v${version} successful. To make this your default version, run 'dctlenv use ${version}'"