linkerd2/bin/protoc

41 lines
947 B
Bash
Executable File

#!/usr/bin/env sh
set -eu
if [ "$(uname -s)" = Darwin ]; then
os=osx
else
os=linux
fi
arch=$(uname -m)
bindir=$( cd "${0%/*}" && pwd )
targetbin=$( cd "$bindir"/.. && pwd )/target/bin
protocversion=3.6.0
protocbin=$targetbin/protoc-$protocversion
protocurl=https://github.com/google/protobuf/releases/download/v$protocversion/protoc-$protocversion-$os-$arch.zip
require_from() {
if ! command -v "$1" >/dev/null 2>/dev/null ; then
echo "Please acquire $1 from $2" >&2
return 1
fi
}
if [ ! -f "$protocbin" ]; then
require_from curl 'https://curl.se/download.html'
require_from unzip 'http://infozip.sourceforge.net/UnZip.html#Downloads'
tmp=$(mktemp -d -t protoc.XXX)
mkdir -p "$targetbin"
(
cd "$tmp"
curl -L --silent --fail -o "./protoc.zip" "$protocurl"
unzip -q "./protoc.zip" bin/protoc
chmod +x bin/protoc
)
mv "$tmp/bin/protoc" "$protocbin"
rm -rf "$tmp"
fi
"$protocbin" "$@"