Last active
February 24, 2023 19:50
-
-
Save timburks/ad3be6916e97ad14056f26a5460b2378 to your computer and use it in GitHub Desktop.
Download the latest release of the Registry Tool
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 | |
# Copyright 2023 Google LLC | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
set -e | |
# Determines the operating system. | |
OS="$(uname)" | |
if [ "${OS}" = "Darwin" ] ; then | |
OSEXT="Darwin" | |
else | |
OSEXT="linux" | |
fi | |
# Determine the latest registry version by version number ignoring alpha, beta, and rc versions. | |
if [ "${REGISTRY_VERSION}" = "" ] ; then | |
REGISTRY_VERSION="$(curl -sL https://github.com/apigee/registry/releases/latest | \ | |
grep -i release | grep -o 'v[0-9].[0-9]*.[0-9]*' | tail -1)" | |
REGISTRY_VERSION="${REGISTRY_VERSION##*/}" | |
fi | |
echo "REGISTRY VERSION $REGISTRY_VERSION" | |
LOCAL_ARCH=$(uname -m) | |
if [ "${TARGET_ARCH}" ]; then | |
LOCAL_ARCH=${TARGET_ARCH} | |
fi | |
case "${LOCAL_ARCH}" in | |
x86_64|amd64|arm64) | |
REGISTRY_ARCH=amd64 | |
;; | |
armv8*|aarch64*) | |
REGISTRY_ARCH=arm64 | |
;; | |
*) | |
echo "This system's architecture, ${LOCAL_ARCH}, isn't supported" | |
exit 1 | |
;; | |
esac | |
if [ "${REGISTRY_VERSION}" = "" ] ; then | |
printf "Unable to get latest registry version. Set REGISTRY_VERSION env var and re-run. For example: export REGISTRY_VERSION=v1.104" | |
exit 1; | |
fi | |
# older versions of registry used a file called .registry. This changed to a folder in v1.108 | |
REGISTRY_FILE=~/.registry | |
if [ -f "$REGISTRY_FILE" ]; then | |
rm ${REGISTRY_FILE} | |
fi | |
# Downloads the registry binary archive. | |
tmp=$(mktemp -d /tmp/registry.XXXXXX) | |
NAME="registry_$REGISTRY_VERSION" | |
cd "$tmp" || exit | |
FILENAME="registry_${REGISTRY_VERSION##v}_${OSEXT}_${REGISTRY_ARCH}.tar.gz" | |
URL="https://github.com/apigee/registry/releases/download/${REGISTRY_VERSION}/${FILENAME}" | |
echo $URL | |
download_cli() { | |
printf "\nDownloading %s from %s ...\n" "$NAME" "$URL" | |
if ! curl -o /dev/null -sIf "$URL"; then | |
printf "\n%s is not found, please specify a valid REGISTRY_VERSION and TARGET_ARCH\n" "$URL" | |
exit 1 | |
fi | |
curl -fsLO "$URL" | |
tar xzf "${FILENAME}" | |
} | |
download_cli | |
printf "" | |
printf "\nregistry %s Download Complete!\n" "$REGISTRY_VERSION" | |
printf "\n" | |
printf "registry has been successfully downloaded into the %s folder on your system.\n" "$tmp" | |
printf "\n" | |
# setup registry | |
cd "$HOME" || exit | |
mkdir -p "$HOME/.registry/bin" | |
mv "${tmp}/registry" "$HOME/.registry/bin" | |
printf "Copied registry into the $HOME/.registry/bin folder.\n" | |
chmod +x "$HOME/.registry/bin/registry" | |
rm -r "${tmp}" | |
# Print message | |
printf "\n" | |
printf "Added the registry to your path with:" | |
printf "\n" | |
printf " export PATH=\$PATH:\$HOME/.registry/bin \n" | |
printf "\n" | |
export PATH=$PATH:$HOME/.registry/bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment