|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2022-2023 Tigris Data, Inc. |
| 3 | + |
| 4 | +set -ex |
| 5 | + |
| 6 | +# Settings |
| 7 | +PROTO_VERSION=25.6 |
| 8 | +PROTO_RELEASES="https://github.com/protocolbuffers/protobuf/releases" |
| 9 | + |
| 10 | +### Prereqs checks ### |
| 11 | +# Check if architecture and OS is supported |
| 12 | +# and set environment specifics |
| 13 | +ARCH=$(uname -m) |
| 14 | +OS=$(uname -s) |
| 15 | + |
| 16 | +case "${OS}-${ARCH}" in |
| 17 | +"Darwin-arm64") |
| 18 | + BINARIES="brew curl go" |
| 19 | + ;; |
| 20 | +"Darwin-x86_64") |
| 21 | + BINARIES="brew curl go" |
| 22 | + ;; |
| 23 | +"Linux-aarch64") |
| 24 | + BINARIES="apt-get curl go" |
| 25 | + ;; |
| 26 | +"Linux-arm64") |
| 27 | + BINARIES="apt-get curl go" |
| 28 | + ;; |
| 29 | +"Linux-x86_64") |
| 30 | + BINARIES="apt-get curl go" |
| 31 | + ;; |
| 32 | +*) |
| 33 | + echo "Unsupported architecture ${ARCH} or operating system ${OS}." |
| 34 | + exit 1 |
| 35 | + ;; |
| 36 | +esac |
| 37 | + |
| 38 | +# Check if required binaries are available in PATH |
| 39 | +for bin in ${BINARIES}; do |
| 40 | + binpath=$(command -v "${bin}") |
| 41 | + if [ -z "${binpath}" ] || ! test -x "${binpath}"; then |
| 42 | + echo "Please ensure that $bin binary is installed and in PATH." |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +done |
| 46 | + |
| 47 | +# Install protobuf compiler |
| 48 | +case "${OS}" in |
| 49 | +"Darwin") |
| 50 | + brew install protobuf |
| 51 | + ;; |
| 52 | +"Linux") |
| 53 | + case "${ARCH}" in |
| 54 | + "x86_64") |
| 55 | + PROTO_PKG=protoc-$PROTO_VERSION-linux-x86_64.zip |
| 56 | + ;; |
| 57 | + "aarch64") |
| 58 | + PROTO_PKG=protoc-$PROTO_VERSION-linux-aarch_64.zip |
| 59 | + ;; |
| 60 | + *) |
| 61 | + echo "No supported proto compiler for ${ARCH} or operating system ${OS}." |
| 62 | + exit 1 |
| 63 | + ;; |
| 64 | + esac |
| 65 | + ;; |
| 66 | +*) |
| 67 | + echo "No supported proto compiler for ${ARCH} or operating system ${OS}." |
| 68 | + exit 1 |
| 69 | + ;; |
| 70 | +esac |
| 71 | + |
| 72 | +if [ -n "$PROTO_PKG" ]; then |
| 73 | + DOWNLOAD_URL="$PROTO_RELEASES/download/v$PROTO_VERSION/$PROTO_PKG" |
| 74 | + echo "Fetching protobuf release ${DOWNLOAD_URL}" |
| 75 | + curl -LO "$DOWNLOAD_URL" |
| 76 | + sudo unzip "$PROTO_PKG" -d "/usr/local/" |
| 77 | + sudo chmod +x "/usr/local/bin/protoc" |
| 78 | + sudo chmod -R 755 "/usr/local/include/" |
| 79 | + rm -f "$PROTO_PKG" |
| 80 | +fi |
| 81 | + |
| 82 | +# Install protobuf |
| 83 | +export GO111MODULE=on |
| 84 | +go install google.golang.org/protobuf/cmd/protoc-gen-go@v1 |
| 85 | +go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1 |
0 commit comments