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