-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·72 lines (65 loc) · 1.95 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Copyright 2021 NSONE, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Utility for generating protobuf and gRPC artifacts for the Bulk Beacon service.
valid_versions="v1 v2"
PB_DIR="proto/bulkbeacon"
PB_OUT="pkg/bulkbeacon"
PKG_PREFIX="github.com/ns1/pulsar-rum"
function validate_version() {
for i in $valid_versions; do
if [[ $i == $1 ]]; then
echo "Bulk Beacon: ${i} is a valid version."
return
fi
done
echo "Error: '$1' is not a valid Bulk Beacon version."
exit 1
}
function build() {
v="${1}"
if [ "${1}" == "v1" ]
then
proto_pkg="${PB_OUT}"
else
# Versions 2 and up follow this convention.
proto_pkg="${PB_OUT}/bulkbeacon_${v}"
fi
proto_file="${PB_DIR}/${v}/bulkbeacon.proto"
opt_m="M${proto_file}=${proto_pkg}"
echo "Bulk Beacon: Building ${proto_file}"
mkdir -p "${proto_pkg}"
protoc --go_out=. --go_opt="${opt_m}" --go-grpc_out=. --go-grpc_opt="${opt_m}" "${proto_file}"
# Outdated versions of protoc do not handle the pkg output very well.
if [ -f "${PB_DIR}/${v}/bulkbeacon.pb.go" ]
then
mv "${PB_DIR}/${v}/bulkbeacon.pb.go" "${proto_pkg}/bulkbeacon.pb.go"
fi
}
function usage() {
echo -n "Utility for generating protobuf and gRPC artifacts for the Pulsar Bulk "
echo "Beacon Service."
echo "(c) NS1 Inc."
echo "Usage:"
echo "$0 <v1|v2>"
}
if [[ $# != 1 ]]; then
usage
exit 1
elif [[ $1 == "-h" || $1 == "--help" ]]; then
usage
exit 1
fi
validate_version "${1}"
build "${1}"