Skip to content

Instantly share code, notes, and snippets.

@craigforr
Last active September 19, 2020 22:48
Show Gist options
  • Select an option

  • Save craigforr/f2af21e6dca74bd71c2e29c6b1e2640a to your computer and use it in GitHub Desktop.

Select an option

Save craigforr/f2af21e6dca74bd71c2e29c6b1e2640a to your computer and use it in GitHub Desktop.

Revisions

  1. craigforr revised this gist Sep 19, 2020. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions install_upgrade_kubectl.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,18 @@
    #!/usr/bin/env bash
    # Installs or upgrades kubectl on Linux

    # Chuck for root privileges
    if [[ "$EUID" != "0" ]] ; then
    echo "Please execute script with sudo or as root."
    exit 1
    fi

    # Check Dependencies
    if ! curl --version &>/dev/null; then
    echo "curl must be installed and in \$PATH"
    exit 1
    fi

    INSTALLED_KUBECTL_PATH=$(which kubectl 2>/dev/null || echo NONE)
    INSTALLED_KUBECTL_VERSION="$($INSTALLED_KUBECTL version --client --short | cut -f3 -d' ')"

  2. craigforr revised this gist Sep 19, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions install_upgrade_kubectl.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env bash
    # Installs or upgrades kubectl on Linux

    INSTALLED_KUBECTL=$(which kubectl 2>/dev/null || echo NONE)
    INSTALLED_KUBECTL_PATH=$(which kubectl 2>/dev/null || echo NONE)
    INSTALLED_KUBECTL_VERSION="$($INSTALLED_KUBECTL version --client --short | cut -f3 -d' ')"

    LATEST_KUBECTL_VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
    @@ -19,7 +19,7 @@ fi
    if [ $DOWNLOADED_KUBECTL_VERSION != $LATEST_KUBECTL_VERSION ] ; then
    echo "ERROR: Something went wrong with the download."
    else
    mv ./kubectl $INSTALLED_KUBECTL
    mv ./kubectl $INSTALLED_KUBECTL_PATH
    echo "Installation and/or upgrade complete."
    fi

  3. craigforr created this gist Sep 19, 2020.
    26 changes: 26 additions & 0 deletions install_upgrade_kubectl.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/usr/bin/env bash
    # Installs or upgrades kubectl on Linux

    INSTALLED_KUBECTL=$(which kubectl 2>/dev/null || echo NONE)
    INSTALLED_KUBECTL_VERSION="$($INSTALLED_KUBECTL version --client --short | cut -f3 -d' ')"

    LATEST_KUBECTL_VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)

    if [ $INSTALLED_KUBECTL_VERSION != $LATEST_KUBECTL_VERSION ] ; then
    curl -#LO "https://storage.googleapis.com/kubernetes-release/release/${LATEST_KUBECTL_VERSION}/bin/linux/amd64/kubectl" \
    && chmod ug+x ./kubectl
    if [ -x ./kubectl ] ; then
    DOWNLOADED_KUBECTL_VERSION="$(./kubectl version --client --short | cut -f3 -d' ')"
    fi
    else
    echo "The latest version is already installed."
    fi

    if [ $DOWNLOADED_KUBECTL_VERSION != $LATEST_KUBECTL_VERSION ] ; then
    echo "ERROR: Something went wrong with the download."
    else
    mv ./kubectl $INSTALLED_KUBECTL
    echo "Installation and/or upgrade complete."
    fi

    # EOF