1ffe3c632Sopenharmony_ci#!/bin/bash
2ffe3c632Sopenharmony_ci
3ffe3c632Sopenharmony_ciif [ $# -ne 1 ]; then
4ffe3c632Sopenharmony_ci  cat <<EOF
5ffe3c632Sopenharmony_ciUsage: $0 <VERSION_NUMBER>
6ffe3c632Sopenharmony_ci
7ffe3c632Sopenharmony_ciExample:
8ffe3c632Sopenharmony_ci  $ $0 3.0.0
9ffe3c632Sopenharmony_ci
10ffe3c632Sopenharmony_ciThis script will download pre-built protoc binaries from maven repository and
11ffe3c632Sopenharmony_cicreate the Google.Protobuf.Tools package. Well-known type .proto files will also
12ffe3c632Sopenharmony_cibe included.
13ffe3c632Sopenharmony_ciEOF
14ffe3c632Sopenharmony_ci  exit 1
15ffe3c632Sopenharmony_cifi
16ffe3c632Sopenharmony_ci
17ffe3c632Sopenharmony_ciVERSION_NUMBER=$1
18ffe3c632Sopenharmony_ci# <directory name> <binary file name> pairs.
19ffe3c632Sopenharmony_cideclare -a FILE_NAMES=(          \
20ffe3c632Sopenharmony_ci  windows_x86 windows-x86_32.exe \
21ffe3c632Sopenharmony_ci  windows_x64 windows-x86_64.exe \
22ffe3c632Sopenharmony_ci  macosx_x64  osx-x86_64.exe     \
23ffe3c632Sopenharmony_ci  linux_x86   linux-x86_32.exe   \
24ffe3c632Sopenharmony_ci  linux_x64   linux-x86_64.exe   \
25ffe3c632Sopenharmony_ci)
26ffe3c632Sopenharmony_ci
27ffe3c632Sopenharmony_ciset -e
28ffe3c632Sopenharmony_ci
29ffe3c632Sopenharmony_cimkdir -p protoc
30ffe3c632Sopenharmony_ci# Create a zip file for each binary.
31ffe3c632Sopenharmony_cifor((i=0;i<${#FILE_NAMES[@]};i+=2));do
32ffe3c632Sopenharmony_ci  DIR_NAME=${FILE_NAMES[$i]}
33ffe3c632Sopenharmony_ci  mkdir -p protoc/$DIR_NAME
34ffe3c632Sopenharmony_ci
35ffe3c632Sopenharmony_ci  if [ ${DIR_NAME:0:3} = "win" ]; then
36ffe3c632Sopenharmony_ci    TARGET_BINARY="protoc.exe"
37ffe3c632Sopenharmony_ci  else
38ffe3c632Sopenharmony_ci    TARGET_BINARY="protoc"
39ffe3c632Sopenharmony_ci  fi
40ffe3c632Sopenharmony_ci
41ffe3c632Sopenharmony_ci  BINARY_NAME=${FILE_NAMES[$(($i+1))]}
42ffe3c632Sopenharmony_ci  BINARY_URL=http://repo1.maven.org/maven2/com/google/protobuf/protoc/${VERSION_NUMBER}/protoc-${VERSION_NUMBER}-${BINARY_NAME}
43ffe3c632Sopenharmony_ci
44ffe3c632Sopenharmony_ci  if ! wget ${BINARY_URL} -O protoc/$DIR_NAME/$TARGET_BINARY &> /dev/null; then
45ffe3c632Sopenharmony_ci    echo "[ERROR] Failed to download ${BINARY_URL}" >&2
46ffe3c632Sopenharmony_ci    echo "[ERROR] Skipped $protoc-${VERSION_NAME}-${DIR_NAME}" >&2
47ffe3c632Sopenharmony_ci    continue
48ffe3c632Sopenharmony_ci  fi
49ffe3c632Sopenharmony_cidone
50ffe3c632Sopenharmony_ci
51ffe3c632Sopenharmony_cinuget pack Google.Protobuf.Tools.nuspec
52