Last active
October 16, 2020 19:40
-
-
Save davivcgarcia/2b7f9a028a71cb6a76702068789020f5 to your computer and use it in GitHub Desktop.
Bash script for installing/updating local Cloud-Native Tooling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
####################### | |
### BASIC INIT | |
####################### | |
# Check for root access | |
[ `whoami` = root ] || { sudo "$0" "$@"; exit $?; } | |
# Set workdir | |
cd /usr/local/bin | |
# Terminal colors | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' | |
# Helper functions | |
# Args: <string:component name> <string: component version> | |
print_start_msg() { | |
echo -en "Updating ${YELLOW}${1}${NC} to version ${YELLOW}${2}${NC}: " | |
} | |
# Args: <int: exit code> | |
print_end_msg() { | |
if [ "${1}" -eq "0" ]; then | |
echo -e "[${GREEN}SUCCESS${NC}]" | |
else | |
echo -e "[${RED}FAILURE${NC}]" | |
fi | |
} | |
# Args: <string:github namespace> <string:github repository> <string:exclude regex> ) | |
get_latest_github_release() { | |
if [ -z "$2" ]; then | |
set ${1} ${1} | |
fi | |
if [ -z ${3} ]; then | |
set ${1} ${2} "rc\|alpha\|beta\|latest\|pre" | |
fi | |
curl -sL -s https://api.github.com/repos/${1}/${2}/releases | \ | |
grep tag_name | sed "s/ *\"tag_name\": *\"\\(.*\\)\",*/\\1/" | \ | |
grep -v ${3} | \ | |
sort -V | tail -n 1 | |
} | |
####################### | |
### GITHUB REPOS | |
####################### | |
# Kubernetes CLI (kubectl) | |
KUBERNETES_LATEST=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) | |
print_start_msg "Kubernetes CLI (kubectl)" ${KUBERNETES_LATEST} | |
curl -sL https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_LATEST}/bin/linux/amd64/kubectl \ | |
-o /usr/local/bin/kubectl && \ | |
chmod +x /usr/local/bin/kubectl | |
print_end_msg $? | |
# Minikube and KVM2 Driver | |
MINIKUBE_LATEST=$(get_latest_github_release kubernetes minikube) | |
print_start_msg "Minikube and KVM2 Driver" ${MINIKUBE_LATEST} | |
curl -sL https://github.com/kubernetes/minikube/releases/download/${MINIKUBE_LATEST}/minikube-linux-amd64 \ | |
-o /usr/local/bin/minikube && \ | |
chmod +x /usr/local/bin/minikube | |
curl -sL https://github.com/kubernetes/minikube/releases/download/${MINIKUBE_LATEST}/docker-machine-driver-kvm2 \ | |
-o /usr/local/bin/docker-machine-driver-kvm2 && \ | |
chmod +x /usr/local/bin/docker-machine-driver-kvm2 | |
print_end_msg $? | |
# Kubernetes Kind | |
KIND_LATEST=$(get_latest_github_release kubernetes-sigs kind none | sed 's/v//g') | |
print_start_msg "KinD" 'v'${KIND_LATEST} | |
curl -sL https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_LATEST}/kind-linux-amd64 \ | |
-o /usr/local/bin/kind && \ | |
chmod +x /usr/local/bin/kind | |
print_end_msg $? | |
# Kubernetes Federation CLI (kubefed) | |
KUBEFED_LATEST=$(get_latest_github_release kubernetes-sigs kubefed none | sed 's/v//g') | |
print_start_msg "Kubernetes Federation CLI (kubefed)" ${KUBEFED_LATEST} | |
curl -sL https://github.com/kubernetes-sigs/kubefed/releases/download/v${KUBEFED_LATEST}/kubefedctl-${KUBEFED_LATEST}-linux-amd64.tgz | \ | |
tar xz kubefedctl -C /usr/local/bin | |
print_end_msg $? | |
# Helm CLI | |
HELM_LATEST=$(get_latest_github_release helm helm) | |
print_start_msg "Helm" ${HELM_LATEST} | |
curl -sL https://get.helm.sh/helm-${HELM_LATEST}-linux-amd64.tar.gz | \ | |
tar xz linux-amd64/helm --strip-components=1 -C /usr/local/bin | |
print_end_msg $? | |
# Istio CLI (istioctl) | |
ISTIO_LATEST=$(get_latest_github_release istio) | |
print_start_msg "Istio CLI (istioctl)" ${ISTIO_LATEST} | |
curl -sL https://github.com/istio/istio/releases/download/${ISTIO_LATEST}/istio-${ISTIO_LATEST}-linux-amd64.tar.gz | \ | |
tar xz istio-${ISTIO_LATEST}/bin/istioctl --strip-components=2 -C /usr/local/bin | |
print_end_msg $? | |
# Linkerd2 CLI | |
LINKERD2_LATEST=$(get_latest_github_release linkerd linkerd2) | |
print_start_msg "Linkerd2 CLI" ${LINKERD2_LATEST} | |
curl -sL https://github.com/linkerd/linkerd2/releases/download/${LINKERD2_LATEST}/linkerd2-cli-${LINKERD2_LATEST}-linux \ | |
-o /usr/local/bin/linkerd2 && \ | |
chmod +x /usr/local/bin/linkerd2 | |
print_end_msg $? | |
# Kubevirt CLI (virtctl) | |
KUBEVIRT_LATEST=$(get_latest_github_release kubevirt) | |
print_start_msg "Kubevirt CLI (virtctl)" ${KUBEVIRT_LATEST} | |
curl -sL https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_LATEST}/virtctl-${KUBEVIRT_LATEST}-linux-amd64 \ | |
-o /usr/local/bin/virtctl && \ | |
chmod +x /usr/local/bin/virtctl | |
print_end_msg $? | |
# ArgoCD CLI (argocd) | |
ARGOCD_LATEST=$(get_latest_github_release argoproj argo-cd) | |
print_start_msg "ArgoCD CLI (argocd)" ${ARGOCD_LATEST} | |
curl -sL https://github.com/argoproj/argo-cd/releases/download/${ARGOCD_LATEST}/argocd-linux-amd64 \ | |
-o /usr/local/bin/argocd && \ | |
chmod +x /usr/local/bin/argocd | |
print_end_msg $? | |
# Tekton CLI (tkn) | |
TEKTON_LATEST=$(get_latest_github_release tektoncd cli | sed 's/v//g') | |
print_start_msg "Tekton CLI (tkn)" ${TEKTON_LATEST} | |
curl -sL https://github.com/tektoncd/cli/releases/download/v${TEKTON_LATEST}/tkn_${TEKTON_LATEST}_Linux_x86_64.tar.gz | \ | |
tar xz tkn -C /usr/local/bin | |
print_end_msg $? | |
# Amazon EKS CLI | |
EKSCTL_VERSION=$(get_latest_github_release weaveworks eksctl) | |
print_start_msg "Amazon EKS CLI (eksctl)" ${EKSCTL_VERSION} | |
curl -sL https://github.com/weaveworks/eksctl/releases/download/${EKSCTL_VERSION}/eksctl_Linux_amd64.tar.gz | \ | |
tar xz eksctl -C /usr/local/bin | |
print_end_msg $? | |
# Operator Framework SDK | |
OPERATORSDK_LATEST=$(get_latest_github_release operator-framework operator-sdk) | |
print_start_msg "Operator SDK" ${OPERATORSDK_LATEST} | |
curl -sL https://github.com/operator-framework/operator-sdk/releases/download/${OPERATORSDK_LATEST}/operator-sdk-${OPERATORSDK_LATEST}-x86_64-linux-gnu \ | |
-o /usr/local/bin/operator-sdk && \ | |
chmod +x /usr/local/bin/operator-sdk | |
print_end_msg $? | |
# Noobaa Operator CLI | |
NOOBAA_LATEST=$(get_latest_github_release noobaa noobaa-operator) | |
print_start_msg "Noobaa CLI" ${NOOBAA_LATEST} | |
curl -sL https://github.com/noobaa/noobaa-operator/releases/download/${NOOBAA_LATEST}/noobaa-linux-${NOOBAA_LATEST}\ | |
-o /usr/local/bin/noobaa && \ | |
chmod +x /usr/local/bin/noobaa | |
print_end_msg $? | |
# OpenShift ODO | |
ODO_LATEST=$(get_latest_github_release openshift odo) | |
print_start_msg "OpenShift DevX CLI (odo)" ${ODO_LATEST} | |
curl -sL https://github.com/openshift/odo/releases/download/${ODO_LATEST}/odo-linux-amd64 \ | |
-o /usr/local/bin/odo && \ | |
chmod +x /usr/local/bin/odo | |
print_end_msg $? | |
####################### | |
### OTHER REPOS | |
####################### | |
# OpenShift CLI and Installer | |
OPENSHIFT_LATEST=$(curl -s https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/release.txt | grep "Name" | grep -o "[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*") | |
print_start_msg "Openshift CLIs (openshift-install, oc)" ${OPENSHIFT_LATEST} | |
curl -sL https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-install-linux-${OPENSHIFT_LATEST}.tar.gz | tar xz openshift-install | |
curl -sL https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux-${OPENSHIFT_LATEST}.tar.gz | tar xz oc | |
print_end_msg $? | |
# Terraform CLI | |
TERRAFORM_LATEST=$(curl -s https://releases.hashicorp.com/terraform/ | grep -vi 'alpha\|beta\|rc' | grep -m 1 -o "terraform_[[:digit:]]*.[[:digit:]]*.[[:digit:]]*" | sed 's/terraform_//g') | |
print_start_msg "Terraform" ${TERRAFORM_LATEST} | |
curl -sL https://releases.hashicorp.com/terraform/${TERRAFORM_LATEST}/terraform_${TERRAFORM_LATEST}_linux_amd64.zip \ | |
-o /usr/local/bin/terraform.zip && \ | |
unzip -oq terraform.zip && rm -f terraform.zip | |
print_end_msg $? | |
# Packer CLI | |
PACKER_LATEST=$(curl -s https://releases.hashicorp.com/packer/ | grep -vi 'alpha\|beta\|rc' | grep -m 1 -o "packer_[[:digit:]]*.[[:digit:]]*.[[:digit:]]*" | sed 's/packer_//g') | |
print_start_msg "Packer" ${PACKER_LATEST} | |
curl -sL https://releases.hashicorp.com/packer/${PACKER_LATEST}/packer_${PACKER_LATEST}_linux_amd64.zip \ | |
-o /usr/local/bin/packer.zip && \ | |
unzip -oq packer.zip && rm -f packer.zip | |
print_end_msg $? | |
# Vagrant CLI | |
VAGRANT_LATEST=$(curl -s https://releases.hashicorp.com/vagrant/ | grep -vi 'alpha\|beta\|rc' | grep -m 1 -o "vagrant_[[:digit:]]*.[[:digit:]]*.[[:digit:]]*" | sed 's/vagrant_//g') | |
print_start_msg "Vagrant" ${VAGRANT_LATEST} | |
curl -sL https://releases.hashicorp.com/vagrant/${VAGRANT_LATEST}/vagrant_${VAGRANT_LATEST}_linux_amd64.zip \ | |
-o /usr/local/bin/vagrant.zip && \ | |
unzip -oq vagrant.zip && rm -f vagrant.zip | |
print_end_msg $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment