Skip to content

Instantly share code, notes, and snippets.

@kitos9112
Last active June 2, 2020 17:49
Show Gist options
  • Save kitos9112/4265c492442865ef0fe54ade671d9f4a to your computer and use it in GitHub Desktop.
Save kitos9112/4265c492442865ef0fe54ade671d9f4a to your computer and use it in GitHub Desktop.
Fetches and installs the latest Kops Liux AMD64 version released on GitHub artifacts
#!/bin/bash
###########################################################################
# Fetch and install the latest Kops release from the official GitHub repository
# curl -Ls https://gist.githubusercontent.com/kitos9112/4265c492442865ef0fe54ade671d9f4a/raw/50d70d9044a77ade7e7e05aabc34f66155b11b5e/get-kops.sh | bash
##########################################################################
function get_latest_github_release {
curl -s https://api.github.com/repos/$1/$2/releases/latest | grep -oP '"tag_name": "[v]\K(.*)(?=")'
}
INSTALL_DIR='/usr/local/bin'
REGEX="^PATH=.*\K$INSTALL_DIR(?=.*)"
if [[ $(env | grep -oP $REGEX) != $INSTALL_DIR ]]; then
echo "Looks like your install directory $INSTALL_DIR is not in your PATH. Make sure you export it"; fi
INSTALLED_KOPS_VERSION=$(kops version | cut -d " " -f2)
LATEST_KOPS_RELEASE=$(get_latest_github_release kubernetes kops)
# Download and install Terraform if there is a version mismatch
if [[ ${LATEST_KOPS_RELEASE} != ${INSTALLED_KOPS_VERSION} ]]; then
echo "Installing Kops ${LATEST_RELEASE}..."
wget https://github.com/kubernetes/kops/releases/download/v${LATEST_KOPS_RELEASE}/kops-linux-amd64
sudo install kops-linux-amd64 ${INSTALL_DIR}/kops
rm -rf kops-linux-amd64
else
echo "Nothing done. Latest KOPS already installed."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment