install-protobuf 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. # Copyright The containerd Authors.
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. #
  13. # Downloads and installs protobuf
  14. #
  15. set -eu -o pipefail
  16. PROTOBUF_VERSION=3.11.4
  17. GOARCH=$(go env GOARCH)
  18. GOOS=$(go env GOOS)
  19. PROTOBUF_DIR=$(mktemp -d)
  20. case $GOARCH in
  21. arm64)
  22. wget -O $PROTOBUF_DIR/protobuf "https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-linux-aarch64.zip"
  23. unzip $PROTOBUF_DIR/protobuf -d /usr/local
  24. ;;
  25. amd64|386)
  26. if [ "$GOOS" = windows ]; then
  27. wget -O $PROTOBUF_DIR/protobuf "https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-win32.zip"
  28. elif [ "$GOOS" = linux ]; then
  29. wget -O $PROTOBUF_DIR/protobuf "https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-linux-x86_64.zip"
  30. elif [ "$GOOS" = darwin ]; then
  31. wget -O $PROTOBUF_DIR/protobuf "https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-osx-x86_64.zip"
  32. fi
  33. unzip $PROTOBUF_DIR/protobuf -d /usr/local
  34. ;;
  35. ppc64le)
  36. wget -O $PROTOBUF_DIR/protobuf "https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-linux-ppcle_64.zip"
  37. unzip $PROTOBUF_DIR/protobuf -d /usr/local
  38. ;;
  39. *)
  40. wget -O $PROTOBUF_DIR/protobuf "https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-cpp-$PROTOBUF_VERSION.zip"
  41. unzip $PROTOBUF_DIR/protobuf -d /usr/src/protobuf
  42. cd /usr/src/protobuf/protobuf-$PROTOBUF_VERSION
  43. ./autogen.sh
  44. ./configure --disable-shared
  45. make
  46. make check
  47. make install
  48. ldconfig
  49. ;;
  50. esac
  51. rm -rf $PROTOBUF_DIR