istio.io/istio@v0.0.0-20240520182934-d79c90f27776/release/downloadIstioCandidate.sh (about)

     1  #!/bin/sh
     2  
     3  # Copyright Istio Authors
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  #
    18  # This file will be fetched as: curl -L https://git.io/getLatestIstio | sh -
    19  # so it should be pure bourne shell, not bash (and not reference other scripts)
    20  #
    21  # The script fetches the latest Istio release candidate and untars it.
    22  # You can pass variables on the command line to download a specific version
    23  # or to override the processor architecture. For example, to download
    24  # Istio 1.6.8 for the x86_64 architecture and linux OS,
    25  # run curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.6.8 TARGET_ARCH=x86_64 TARGET_OS=Linux sh -.
    26  
    27  set -e
    28  
    29  # Determines the operating system.
    30  OS="${TARGET_OS:-$(uname)}"
    31  if [ "${OS}" = "Darwin" ] ; then
    32    OSEXT="osx"
    33  else
    34    OSEXT="linux"
    35  fi
    36  
    37  # Determine the latest Istio version by version number ignoring alpha, beta, and rc versions.
    38  if [ "${ISTIO_VERSION}" = "" ] ; then
    39    ISTIO_VERSION="$(curl -sL https://github.com/istio/istio/releases | \
    40                    grep -o 'releases/[0-9]*.[0-9]*.[0-9]*/' | sort -V | \
    41                    tail -1 | awk -F'/' '{ print $2}')"
    42    ISTIO_VERSION="${ISTIO_VERSION##*/}"
    43  fi
    44  
    45  LOCAL_ARCH=$(uname -m)
    46  if [ "${TARGET_ARCH}" ]; then
    47      LOCAL_ARCH=${TARGET_ARCH}
    48  fi
    49  
    50  case "${LOCAL_ARCH}" in
    51    x86_64|amd64)
    52      ISTIO_ARCH=amd64
    53      ;;
    54    armv8*|aarch64*|arm64)
    55      ISTIO_ARCH=arm64
    56      ;;
    57    armv*)
    58      ISTIO_ARCH=armv7
    59      ;;
    60    *)
    61      echo "This system's architecture, ${LOCAL_ARCH}, isn't supported"
    62      exit 1
    63      ;;
    64  esac
    65  
    66  if [ "${ISTIO_VERSION}" = "" ] ; then
    67    printf "Unable to get latest Istio version. Set ISTIO_VERSION env var and re-run. For example: export ISTIO_VERSION=1.0.4"
    68    exit 1;
    69  fi
    70  
    71  NAME="istio-$ISTIO_VERSION"
    72  URL="https://github.com/istio/istio/releases/download/${ISTIO_VERSION}/istio-${ISTIO_VERSION}-${OSEXT}.tar.gz"
    73  ARCH_URL="https://github.com/istio/istio/releases/download/${ISTIO_VERSION}/istio-${ISTIO_VERSION}-${OSEXT}-${ISTIO_ARCH}.tar.gz"
    74  
    75  with_arch() {
    76    printf "\nDownloading %s from %s ...\n" "$NAME" "$ARCH_URL"
    77    if ! curl -o /dev/null -sIf "$ARCH_URL"; then
    78      printf "\n%s is not found, please specify a valid ISTIO_VERSION and TARGET_ARCH\n" "$ARCH_URL"
    79      exit 1
    80    fi
    81    curl -fsLO "$ARCH_URL"
    82    filename="istio-${ISTIO_VERSION}-${OSEXT}-${ISTIO_ARCH}.tar.gz"
    83    tar -xzf "${filename}"
    84    rm "${filename}"
    85  }
    86  
    87  without_arch() {
    88    printf "\nDownloading %s from %s ..." "$NAME" "$URL"
    89    if ! curl -o /dev/null -sIf "$URL"; then
    90      printf "\n%s is not found, please specify a valid ISTIO_VERSION\n" "$URL"
    91      exit 1
    92    fi
    93    curl -fsLO "$URL"
    94    filename="istio-${ISTIO_VERSION}-${OSEXT}.tar.gz"
    95    tar -xzf "${filename}"
    96    rm "${filename}"
    97  }
    98  
    99  # Istio 1.6 and above support arch
   100  # Istio 1.5 and below do not have arch support
   101  ARCH_SUPPORTED="1.6"
   102  # Istio 1.10 and above support arch for osx arm64
   103  ARCH_SUPPORTED_OSX="1.10"
   104  
   105  if [ "${OS}" = "Linux" ] ; then
   106    # This checks if ISTIO_VERSION is less than ARCH_SUPPORTED (version-sort's before it)
   107    if [ "$(printf '%s\n%s' "${ARCH_SUPPORTED}" "${ISTIO_VERSION}" | sort -V | head -n 1)" = "${ISTIO_VERSION}" ]; then
   108      without_arch
   109    else
   110      with_arch
   111    fi
   112  elif [ "${OS}" = "Darwin" ] ; then
   113    # This checks if ISTIO_VERSION is less than ARCH_SUPPORTED_OSX (version-sort's before it) or ISTIO_ARCH not equal to arm64
   114    if [ "$(printf '%s\n%s' "${ARCH_SUPPORTED_OSX}" "${ISTIO_VERSION}" | sort -V | head -n 1)" = "${ISTIO_VERSION}" ] || [ "${ISTIO_ARCH}" != "arm64" ]; then
   115      without_arch
   116    else
   117      with_arch
   118    fi
   119  else
   120    printf "\n\n"
   121    printf "Unable to download Istio %s at this moment!\n" "$ISTIO_VERSION"
   122    printf "Please verify the version you are trying to download.\n\n"
   123    exit 1
   124  fi
   125  
   126  printf ""
   127  printf "\nIstio %s Download Complete!\n" "$ISTIO_VERSION"
   128  printf "\n"
   129  printf "Istio has been successfully downloaded into the %s folder on your system.\n" "$NAME"
   130  printf "\n"
   131  BINDIR="$(cd "$NAME/bin" && pwd)"
   132  printf "Next Steps:\n"
   133  printf "See https://istio.io/latest/docs/setup/install/ to add Istio to your Kubernetes cluster.\n"
   134  printf "\n"
   135  printf "To configure the istioctl client tool for your workstation,\n"
   136  printf "add the %s directory to your environment path variable with:\n" "$BINDIR"
   137  printf "\t export PATH=\"\$PATH:%s\"\n" "$BINDIR"
   138  printf "\n"
   139  printf "Begin the Istio pre-installation check by running:\n"
   140  printf "\t istioctl x precheck \n"
   141  printf "\n"
   142  printf "Need more information? Visit https://istio.io/latest/docs/setup/install/ \n"