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