Skip to content

Instantly share code, notes, and snippets.

@laidbackware
Last active August 30, 2023 12:35
Show Gist options
  • Save laidbackware/803f96139f42cced524c86c615c8baaa to your computer and use it in GitHub Desktop.
Save laidbackware/803f96139f42cced524c86c615c8baaa to your computer and use it in GitHub Desktop.
Tanzu CLI install one liner

Tanzu CLI Install One liner

Pre-reqs

  • Export your customerconnect.vmware.com credentials as VCC_USER and VCC_PASS
  • (optional) Specify the Tanzu CLI version with TANZU_VERSION, defaults to latest.
  • (optional) Specify Tanzu CLI directory with $TANZU_DIR. Defaults to $HOME/tanzu.

Upgrade/Downgrade

This one-liner can be used to upgrade and downgrade the Tanzu CLI. The only consideration is that during downgrades you will need to remove the contents of the $HOME/.config/tanzu directory, as the CLI will not handle downgrading of the content.

Linux/Mac to $HOME/.local/bin

Requires $HOME/.local/bin must exist and be in your $PATH environment variable

TKG version >=2.3

export TANZU_CLI_VERSION="1.0.0"
os="$(uname -s | awk '{print tolower($0)}')" && if ! command -v vcc &> /dev/null; then umask 002; \
curl -OLf "https://github.com/vmware-labs/vmware-customer-connect-cli/releases/download/v1.1.5/vcc-${os}-v1.1.5"; \
mv vcc-${os}-v1.1.5 "$HOME/.local/bin/vcc"; chmod +x "$HOME/.local/bin/vcc"; fi && version=${TANZU_CLI_VERSION:-*} && \
echo "Attempting to download version $version" && \
vcc download -p vmware_tanzu_cli -s tcli -v "$version" -f "tanzu-cli-${os}-amd64.*" --accepteula && \
tanzu_dir="${TANZU_DIR:-$HOME/tanzu}" && echo "Exporting to $tanzu_dir" && mkdir -p "$tanzu_dir" && \
find $tanzu_dir -mindepth 1 -maxdepth 1 | xargs -rn1 rm -rf && \
tar -xvf "$HOME/vcc-downloads/tanzu-cli-${os}-amd64.tar.gz" --directory "$tanzu_dir" && \
cli="$(find $tanzu_dir -name tanzu-cli-${os}_amd64)" || (exit 1) && echo "$cli" && \
mv "$cli" "$HOME/.local/bin/tanzu" && tanzu plugin clean && tanzu init

TKG version >=1.5

export TANZU_VERSION="1.6.1"
os="$(uname -s | awk '{print tolower($0)}')" && if ! command -v vcc &> /dev/null; then umask 002; \
curl -OLf "https://github.com/vmware-labs/vmware-customer-connect-cli/releases/download/v1.1.5/vcc-${os}-v1.1.5"; \
mv vcc-${os}-v1.1.5 "$HOME/.local/bin/vcc"; chmod +x "$HOME/.local/bin/vcc"; fi && version=${TANZU_VERSION:-*} && \
echo "Attempting to download version $version" && \
vcc download -p vmware_tanzu_kubernetes_grid -s tkg -v "$version" -f "tanzu-cli-bundle-${os}-amd64.*" --accepteula && \
tanzu_dir="${TANZU_DIR:-$HOME/tanzu}" && echo "Exporting to $tanzu_dir" && mkdir -p "$tanzu_dir" && \
find $tanzu_dir -mindepth 1 -maxdepth 1 | xargs -rn1 rm -rf && \
tar -xvf "$HOME/vcc-downloads/tanzu-cli-bundle-${os}-amd64.tar.gz" --directory "$tanzu_dir" && \
cli="$(find $tanzu_dir -name tanzu-core-${os}_amd64)" || (exit 1) && echo "$cli" && \
mv "$cli" "$HOME/.local/bin/tanzu" && tanzu plugin clean && tanzu init

TKG version <=1.4

export TANZU_VERSION="1.4.2"
os="$(uname -s | awk '{print tolower($0)}')" && if ! command -v vcc &> /dev/null; then umask 002; \
curl -OLf "https://github.com/vmware-labs/vmware-customer-connect-cli/releases/download/v1.1.5/vcc-${os}-v1.1.5"; \
mv vcc-${os}-v1.1.5 "$HOME/.local/bin/vcc"; chmod +x "$HOME/.local/bin/vcc"; fi && version=${TANZU_VERSION:-*} && \
echo "Attempting to download version $version" && \
vcc download -p vmware_tanzu_kubernetes_grid -s tkg -v "$version" -f "tanzu-cli-bundle-${os}-amd64.*" --accepteula && \
tanzu_dir="${TANZU_DIR:-$HOME/tanzu}" && echo "Exporting to $tanzu_dir" && mkdir -p "$tanzu_dir" && \
find $tanzu_dir -mindepth 1 -maxdepth 1 | xargs -rn1 rm -rf && \
tar -xvf "$HOME/vcc-downloads/tanzu-cli-bundle-${os}-amd64.tar" --directory "$tanzu_dir" && \
cli="$(find $tanzu_dir -name tanzu-core-${os}_amd64)" || (exit 1) && echo "$cli" && \
mv "$cli" "$HOME/.local/bin/tanzu" && tanzu plugin clean && tanzu init

Linux/Mac to /usr/local/bin

Requires password input for sudo commands to work

TKG version >=2.3

export TANZU_CLI_VERSION="1.0.0"
os="$(uname -s | awk '{print tolower($0)}')" && if ! command -v vcc &> /dev/null; then umask 002; \
curl -OLf "https://github.com/vmware-labs/vmware-customer-connect-cli/releases/download/v1.1.5/vcc-${os}-v1.1.5"; \
sudo mv vcc-${os}-v1.1.5 "/usr/local/bin/vcc"; sudo chmod +x "/usr/local/bin/vcc"; fi && version=${TANZU_CLI_VERSION:-*} && \
echo "Attempting to download version $version" && \
vcc download -p vmware_tanzu_cli -s tcli -v "$version" -f "tanzu-cli-${os}-amd64.*" --accepteula && \
tanzu_dir="${TANZU_DIR:-$HOME/tanzu}" && echo "Exporting to $tanzu_dir" && mkdir -p $tanzu_dir && \
find $tanzu_dir -mindepth 1 -maxdepth 1 | xargs -rn1 rm -rf && \
tar -xvf "$HOME/vcc-downloads/tanzu-cli-${os}-amd64.tar.gz" --directory "$tanzu_dir" && \
cli="$(find $tanzu_dir -name tanzu-cli-${os}_amd64)" || (exit 1) && echo "$cli" && \
sudo mv "$cli" "/usr/local/bin/tanzu" && tanzu plugin clean && tanzu init

TKG version >=1.5

export TANZU_VERSION="1.6.1"
os="$(uname -s | awk '{print tolower($0)}')" && if ! command -v vcc &> /dev/null; then umask 002; \
curl -OLf "https://github.com/vmware-labs/vmware-customer-connect-cli/releases/download/v1.1.5/vcc-${os}-v1.1.5"; \
sudo mv vcc-${os}-v1.1.5 "/usr/local/bin/vcc"; sudo chmod +x "/usr/local/bin/vcc"; fi && version=${TANZU_VERSION:-*} && \
echo "Attempting to download version $version" && \
vcc download -p vmware_tanzu_kubernetes_grid -s tkg -v "$version" -f "tanzu-cli-bundle-${os}-amd64.*" --accepteula && \
tanzu_dir="${TANZU_DIR:-$HOME/tanzu}" && echo "Exporting to $tanzu_dir" && mkdir -p $tanzu_dir && \
find $tanzu_dir -mindepth 1 -maxdepth 1 | xargs -rn1 rm -rf && \
tar -xvf "$HOME/vcc-downloads/tanzu-cli-bundle-${os}-amd64.tar.gz" --directory "$tanzu_dir" && \
cli="$(find $tanzu_dir -name tanzu-core-${os}_amd64)" || (exit 1) && echo "$cli" && \
sudo mv "$cli" "/usr/local/bin/tanzu" && tanzu plugin clean && tanzu init

TKG version <=1.4

export TANZU_VERSION="1.4.2"
os="$(uname -s | awk '{print tolower($0)}')" && if ! command -v vcc &> /dev/null; then umask 002; \
curl -OLf "https://github.com/vmware-labs/vmware-customer-connect-cli/releases/download/v1.1.5/vcc-${os}-v1.1.5"; \
sudo mv vcc-${os}-v1.1.5 "/usr/local/bin/vcc"; sudo chmod +x "/usr/local/bin/vcc"; fi && version=${TANZU_VERSION:-*} && \
echo "Attempting to download version $version" && \
vcc download -p vmware_tanzu_kubernetes_grid -s tkg -v "$version" -f "tanzu-cli-bundle-${os}-amd64.*" --accepteula && \
tanzu_dir="${TANZU_DIR:-$HOME/tanzu}" && echo "Exporting to $tanzu_dir" && mkdir -p "$tanzu_dir" && \
find $tanzu_dir -mindepth 1 -maxdepth 1 | xargs -rn1 rm -rf && \
tar -xvf "$HOME/vcc-downloads/tanzu-cli-bundle-${os}-amd64.tar" --directory "$tanzu_dir" && \
cli="$(find $tanzu_dir -name tanzu-core-${os}_amd64)" || (exit 1) && echo "$cli" && \
sudo mv "$cli" "/usr/local/bin/tanzu" && tanzu plugin clean && tanzu init

How it works

  • os type is set
  • vcc is downloaded if not available to $HOME/.local/bin
  • curl -OLf will download vcc, show the status on screen and return an error on failure.
  • version variable is set to * meaning latest if TANZU_VERSION is unset
  • vcc attempts the download
  • tanzu_dir is set to $HOME/tanzu unless TANZU_DIR is set
  • The tanzu_dir is created if it does not already exist and emptied
  • The executable file is found, made executable and moved to the final location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment