Skip to content

Instantly share code, notes, and snippets.

@cdelashmutt-pivotal
Created July 8, 2022 14:01
Show Gist options
  • Save cdelashmutt-pivotal/df01287bd2d08dc300094917f53e3029 to your computer and use it in GitHub Desktop.
Save cdelashmutt-pivotal/df01287bd2d08dc300094917f53e3029 to your computer and use it in GitHub Desktop.
This script switches between Tanzu CLI versions (and related CLIs). To prep, extract CLIs to /opt/tanzu-<version>, extract embedded CLIs, and chmod any of those CLIs you need to
#!/bin/bash
usage()
{
echo "Usage: tanzu-switch [ -v VERSION ]"
exit 2
}
print_links()
{
ls -l /usr/local/bin/tanzu \
/usr/local/bin/kubectl \
/usr/local/bin/velero \
/usr/local/bin/ytt \
/usr/local/bin/kapp \
/usr/local/bin/kbld \
/usr/local/bin/imgpkg
}
switch_version()
{
echo Switching to version $1
ln -sf /opt/tanzu-$1/cli/core/v*/tanzu-core-linux_amd64 /usr/local/bin/tanzu
ln -sf /opt/tanzu-$1/kubectl-linux-amd64 /usr/local/bin/kubectl
ln -sf /opt/tanzu-$1/velero-linux-amd64 /usr/local/bin/velero
ln -sf /opt/tanzu-$1/cli/ytt-linux-amd64-* /usr/local/bin/ytt
ln -sf /opt/tanzu-$1/cli/kapp-linux-amd64-* /usr/local/bin/kapp
ln -sf /opt/tanzu-$1/cli/kbld-linux-amd64-* /usr/local/bin/kbld
ln -sf /opt/tanzu-$1/cli/imgpkg-linux-amd64-* /usr/local/bin/imgpkg
}
print_versions()
{
echo "Available versions are: "
ls -d tanzu-*/ | grep -Eo '[0-9]\.[0-9]\.[0-9]'
}
if [[ $# == 0 ]]; then
print_links
exit 0
fi
while getopts ":v:h" opt; do
case $opt in
v) switch_version ${OPTARG}
;;
:) if [[ $OPTARG == "v" ]]; then
print_versions
fi
;;
h) usage
;;
\?) usage
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment