github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/scripts/download-protoc.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2022 PingCAP, Inc.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  set -eu
    16  
    17  TOOLS_BIN_DIR=tools/bin
    18  TOOLS_INCLUDE_DIR=tools/include
    19  GOGO_VERSION=1.3.2
    20  PROTOC_VERSION=3.20.1
    21  # Google APIs doesn't have a semantic version, so we use the commit SHA.
    22  GOOGLE_API_VERSION=643311525df18aff3090d13449db4e9c2e9df419
    23  OS="$(uname)"
    24  
    25  case $OS in
    26  'Linux')
    27  	PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip
    28  	;;
    29  'Darwin')
    30  	if [[ $(uname -m) == 'x86_64' ]]; then
    31  		PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-osx-x86_64.zip
    32  	else
    33  		PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-osx-aarch_64.zip
    34  	fi
    35  	;;
    36  *)
    37  	echo "only supports Linux and macOS"
    38  	exit 1
    39  	;;
    40  esac
    41  
    42  echo "download gogo.proto..."
    43  [ ! -d $TOOLS_INCLUDE_DIR/gogoproto ] && mkdir -p $TOOLS_INCLUDE_DIR/gogoproto
    44  [ ! -f $TOOLS_INCLUDE_DIR/gogoproto/gogo.proto ] &&
    45  	curl -sL https://raw.githubusercontent.com/gogo/protobuf/v$GOGO_VERSION/gogoproto/gogo.proto \
    46  		-o $TOOLS_INCLUDE_DIR/gogoproto/gogo.proto
    47  
    48  echo "download necessary google apis for grpc gateway..."
    49  mkdir -p $TOOLS_INCLUDE_DIR/google/api/
    50  [ ! -f $TOOLS_INCLUDE_DIR/google/api/annotations.proto ] &&
    51  	curl -sL https://raw.githubusercontent.com/googleapis/googleapis/$GOOGLE_API_VERSION/google/api/annotations.proto \
    52  		-o $TOOLS_INCLUDE_DIR/google/api/annotations.proto
    53  [ ! -f $TOOLS_INCLUDE_DIR/google/api/http.proto ] &&
    54  	curl -sL https://raw.githubusercontent.com/googleapis/googleapis/$GOOGLE_API_VERSION/google/api/http.proto \
    55  		-o $TOOLS_INCLUDE_DIR/google/api/http.proto
    56  [ ! -f $TOOLS_INCLUDE_DIR/google/api/field_behavior.proto ] &&
    57  	curl -sL https://raw.githubusercontent.com/googleapis/googleapis/$GOOGLE_API_VERSION/google/api/field_behavior.proto \
    58  		-o $TOOLS_INCLUDE_DIR/google/api/field_behavior.proto
    59  
    60  echo "download protoc..."
    61  [ ! -d $TOOLS_BIN_DIR ] && mkdir -p $TOOLS_BIN_DIR
    62  [ ! -f $TOOLS_BIN_DIR/protoc ] &&
    63  	mkdir -p /tmp/cdc/protoc &&
    64  	curl -sL $PROTOC_URL -o /tmp/cdc/protoc/protoc-$PROTOC_VERSION-linux-x86_64.zip &&
    65  	unzip -q -o -d /tmp/cdc/protoc /tmp/cdc/protoc/protoc-$PROTOC_VERSION-linux-x86_64.zip &&
    66  	mv /tmp/cdc/protoc/include/google/protobuf $TOOLS_INCLUDE_DIR/google/ &&
    67  	mv /tmp/cdc/protoc/bin/protoc $TOOLS_BIN_DIR/protoc