| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 | #!/bin/bashif [ $# -ne 2 ]; then  cat <<EOFUsage: $0 <TARGET> <VERSION_NUMBER>TARGET: protoc | protoc-gen-javaliteExample:  $ $0 protoc 3.0.0  $ $0 protoc-gen-javalite 3.0.0This script will download pre-built protoc or protoc plugin binaries from mavenrepository and create .zip packages suitable to be included in the githubrelease page. If the target is protoc, well-known type .proto files will also beincluded. Each invocation will create 5 zip packages:  dist/<TARGET>-<VERSION_NUMBER>-win32.zip  dist/<TARGET>-<VERSION_NUMBER>-osx-x86_32.zip  dist/<TARGET>-<VERSION_NUMBER>-osx-x86_64.zip  dist/<TARGET>-<VERSION_NUMBER>-linux-x86_32.zip  dist/<TARGET>-<VERSION_NUMBER>-linux-x86_64.zipEOF  exit 1fiTARGET=$1VERSION_NUMBER=$2# <zip file name> <binary file name> pairs.declare -a FILE_NAMES=( \  win32.zip windows-x86_32.exe \  osx-x86_32.zip osx-x86_32.exe \  osx-x86_64.zip osx-x86_64.exe \  linux-x86_32.zip linux-x86_32.exe \  linux-x86_64.zip linux-x86_64.exe \)# List of all well-known types to be included.declare -a WELL_KNOWN_TYPES=(           \  google/protobuf/descriptor.proto      \  google/protobuf/any.proto             \  google/protobuf/api.proto             \  google/protobuf/duration.proto        \  google/protobuf/empty.proto           \  google/protobuf/field_mask.proto      \  google/protobuf/source_context.proto  \  google/protobuf/struct.proto          \  google/protobuf/timestamp.proto       \  google/protobuf/type.proto            \  google/protobuf/wrappers.proto        \  google/protobuf/compiler/plugin.proto \)set -e# A temporary working directory to put all files.DIR=$(mktemp -d)# Copy over well-known types.mkdir -p ${DIR}/include/google/protobuf/compilerfor PROTO in ${WELL_KNOWN_TYPES[@]}; do  cp -f ../src/${PROTO} ${DIR}/include/${PROTO}done# Create a readme file.cat <<EOF > ${DIR}/readme.txtProtocol Buffers - Google's data interchange formatCopyright 2008 Google Inc.https://developers.google.com/protocol-buffers/This package contains a precompiled binary version of the protocol buffercompiler (protoc). This binary is intended for users who want to use ProtocolBuffers in languages other than C++ but do not want to compile protocthemselves. To install, simply place this binary somewhere in your PATH.Please refer to our official github site for more installation instructions:  https://github.com/google/protobufEOFmkdir -p distmkdir -p ${DIR}/bin# Create a zip file for each binary.for((i=0;i<${#FILE_NAMES[@]};i+=2));do  ZIP_NAME=${FILE_NAMES[$i]}  if [ ${ZIP_NAME:0:3} = "win" ]; then    BINARY="$TARGET.exe"  else    BINARY="$TARGET"  fi  BINARY_NAME=${FILE_NAMES[$(($i+1))]}  BINARY_URL=http://repo1.maven.org/maven2/com/google/protobuf/$TARGET/${VERSION_NUMBER}/$TARGET-${VERSION_NUMBER}-${BINARY_NAME}  if ! wget ${BINARY_URL} -O ${DIR}/bin/$BINARY &> /dev/null; then    echo "[ERROR] Failed to download ${BINARY_URL}" >&2    echo "[ERROR] Skipped $TARGET-${VERSION_NAME}-${ZIP_NAME}" >&2    continue  fi  TARGET_ZIP_FILE=`pwd`/dist/$TARGET-${VERSION_NUMBER}-${ZIP_NAME}  pushd $DIR &> /dev/null  chmod +x bin/$BINARY  if [ "$TARGET" = "protoc" ]; then    zip -r ${TARGET_ZIP_FILE} include bin readme.txt &> /dev/null  else    zip -r ${TARGET_ZIP_FILE} bin &> /dev/null  fi  rm  bin/$BINARY  popd &> /dev/null  echo "[INFO] Successfully created ${TARGET_ZIP_FILE}"done
 |