Skip to content

Instantly share code, notes, and snippets.

@bitmvr
Last active April 23, 2020 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitmvr/3e36a4bcff57eab56be5609d3e8a0152 to your computer and use it in GitHub Desktop.
Save bitmvr/3e36a4bcff57eab56be5609d3e8a0152 to your computer and use it in GitHub Desktop.
An istioctl installer - Easily install istioctl
#!/bin/sh
__getLatestVersion(){
request="$(curl -sI https://github.com/istio/istio/releases/latest | grep "^location")"
request="${request##*/}"
echo "$request" | tr -d '\r'
}
__getOperatingSystem(){
get_system_name="$(uname | tr '[:upper:]' '[:lower:]')"
case "$get_system_name" in
darwin)
readonly HOST_OS="osx"
readonly EXT="tar.gz"
readonly ARCH="amd64"
;;
mingw64*)
readonly HOST_OS="win"
readonly EXT="zip"
readonly ARCH="amd64"
;;
linux*)
readonly HOST_OS="linux"
readonly EXT="tar.gz"
readonly ARCH="amd64"
;;
*)
readonly HOST_OS="unknown"
return 1
;;
esac
}
__makeIstioHome(){
readonly ISTIO_HOME="$HOME/.istio"
mkdir -p "${ISTIO_HOME}"
}
__createDownloadFolder(){
readonly TEMP_DIR="istio.tmp"
mkdir -p "./${TEMP_DIR}"
}
__downloadBinary(){
readonly VERSION="$(__getLatestVersion)"
readonly ARTIFACT="istioctl-${VERSION}-${HOST_OS}.${EXT}"
readonly ARTIFACT_SHA="${ARTIFACT}.sha256"
readonly ARTIFACT_ENDPOINT="https://github.com/istio/istio/releases/download/${VERSION}"
readonly ARTIFACT_DOWNLOAD_URL="${ARTIFACT_ENDPOINT}/${ARTIFACT}"
curl -sL "${ARTIFACT_DOWNLOAD_URL}" -o "./${TEMP_DIR}/${ARTIFACT}"
}
__extractBinary(){
tar -xf "${TEMP_DIR}/${ARTIFACT}" -C "${TEMP_DIR}"
}
__moveBinaryToIstioHome(){
mv "${TEMP_DIR}/istioctl" "${ISTIO_HOME}/"
}
__installCleanUp(){
rm -rf "${TEMP_DIR}"
}
main(){
if ! __makeIstioHome; then
printf "Could not create the directory %s/.istio" "$HOME"
exit 1
fi
if ! __getOperatingSystem; then
printf "Could not determine your host operating system."
exit 1
fi
if ! __createDownloadFolder; then
printf "Could not create the temporary folder %s" "$TEMP_DIR"
exit 1
fi
if ! __downloadBinary; then
printf "Was unable to download the Istio installer package."
exit 1
fi
if ! __extractBinary; then
printf "Was not able to extract the Istio binary."
exit 1
fi
if ! __moveBinaryToIstioHome; then
printf "Was not able to move the istioctl binary to ISTIO_HOME"
exit 1
fi
if ! __installCleanUp; then
printf "Was not able to perform clean up on ./%s" "$TEMP_DIR"
printf "Try manually deleting it."
fi
printf "istioctl %s was successfully downloaded.\n" "$VERSION"
printf "\n"
printf "To configure your machine to use istioctl, do one of the following:\n"
printf "\n"
printf " Add ISTIO_HOME To Your PATH\n"
printf " export PATH=\"\$PATH:%s\"\n" "$ISTIO_HOME"
printf "\n"
printf " - or -\n"
printf "\n"
printf " Create A Symlink\n"
printf " ln -s $ISTIO_HOME/istioctl /usr/local/bin/istioctl\n"
printf "\n"
printf "\n"
printf "Begin the Istio pre-installation verification check by running:\n"
printf "\n"
printf " istioctl verify-install \n"
printf "\n"
printf "Need more information? Visit https://istio.io/docs/setup/kubernetes/install/ \n"
printf "\n"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment