1#!/bin/bash 2 3if [ $# -eq 0 ]; then 4 cat <<EOF 5Usage: $0 <VERSION_NUMBER> 6 7Example: 8 $ $0 3.0.0-beta-4 9 10This script will download pre-built protoc binaries from maven repository 11and package them with well-known type .proto files to create .zip packages 12suitable to be included in the github release page. Each invocation will 13create 5 zip packages: 14 dist/protoc-<VERSION_NUMBER>-win32.zip 15 dist/protoc-<VERSION_NUMBER>-osx-x86_32.zip 16 dist/protoc-<VERSION_NUMBER>-osx-x86_64.zip 17 dist/protoc-<VERSION_NUMBER>-linux-x86_32.zip 18 dist/protoc-<VERSION_NUMBER>-linux-x86_64.zip 19EOF 20 exit 1 21fi 22 23VERSION_NUMBER=$1 24 25# <zip file name> <binary file name> pairs. 26declare -a FILE_NAMES=( \ 27 win32.zip windows-x86_32.exe \ 28 osx-x86_32.zip osx-x86_32.exe \ 29 osx-x86_64.zip osx-x86_64.exe \ 30 linux-x86_32.zip linux-x86_32.exe \ 31 linux-x86_64.zip linux-x86_64.exe \ 32) 33 34# List of all well-known types to be included. 35declare -a WELL_KNOWN_TYPES=( \ 36 google/protobuf/descriptor.proto \ 37 google/protobuf/any.proto \ 38 google/protobuf/api.proto \ 39 google/protobuf/duration.proto \ 40 google/protobuf/empty.proto \ 41 google/protobuf/field_mask.proto \ 42 google/protobuf/source_context.proto \ 43 google/protobuf/struct.proto \ 44 google/protobuf/timestamp.proto \ 45 google/protobuf/type.proto \ 46 google/protobuf/wrappers.proto \ 47 google/protobuf/compiler/plugin.proto \ 48) 49 50set -e 51 52# A temporary working directory to put all files. 53DIR=$(mktemp -d) 54 55# Copy over well-known types. 56mkdir -p ${DIR}/include/google/protobuf/compiler 57for PROTO in ${WELL_KNOWN_TYPES[@]}; do 58 cp -f ../src/${PROTO} ${DIR}/include/${PROTO} 59done 60 61# Create a readme file. 62cat <<EOF > ${DIR}/readme.txt 63Protocol Buffers - Google's data interchange format 64Copyright 2008 Google Inc. 65https://developers.google.com/protocol-buffers/ 66 67This package contains a precompiled binary version of the protocol buffer 68compiler (protoc). This binary is intended for users who want to use Protocol 69Buffers in languages other than C++ but do not want to compile protoc 70themselves. To install, simply place this binary somewhere in your PATH. 71 72Please refer to our official github site for more installation instructions: 73 https://github.com/google/protobuf 74EOF 75 76mkdir -p dist 77mkdir -p ${DIR}/bin 78# Create a zip file for each binary. 79for((i=0;i<${#FILE_NAMES[@]};i+=2));do 80 ZIP_NAME=${FILE_NAMES[$i]} 81 BINARY_NAME=${FILE_NAMES[$(($i+1))]} 82 BINARY_URL=http://repo1.maven.org/maven2/com/google/protobuf/protoc/${VERSION_NUMBER}/protoc-${VERSION_NUMBER}-${BINARY_NAME} 83 if ! wget ${BINARY_URL} -O ${DIR}/bin/protoc &> /dev/null; then 84 echo "[ERROR] Failed to download ${BINARY_URL}" >&2 85 echo "[ERROR] Skipped protoc-${VERSION_NAME}-${ZIP_NAME}" >&2 86 continue 87 fi 88 TARGET_ZIP_FILE=`pwd`/dist/protoc-${VERSION_NUMBER}-${ZIP_NAME} 89 pushd $DIR &> /dev/null 90 chmod +x bin/protoc 91 zip -r ${TARGET_ZIP_FILE} include bin readme.txt &> /dev/null 92 popd &> /dev/null 93 echo "[INFO] Successfully created ${TARGET_ZIP_FILE}" 94done 95