This repository has been archived by the owner on May 6, 2024. It is now read-only.
forked from dapr/rust-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-protos.sh
executable file
·101 lines (87 loc) · 2.76 KB
/
update-protos.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
# ------------------------------------------------------------
# Copyright 2021 The Dapr Authors
# 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.
# ------------------------------------------------------------
# Protobuf generation
APPCALLBACK="appcallback"
COMMON="common"
DAPR="dapr"
RUNTIME="runtime"
RUNTIME_RELEASE_TAG="master"
# Path to store output
PROTO_PATH="dapr/proto"
# Http request CLI
HTTP_REQUEST_CLI=curl
checkHttpRequestCLI() {
if type "curl" > /dev/null; then
HTTP_REQUEST_CLI=curl
elif type "wget" > /dev/null; then
HTTP_REQUEST_CLI=wget
else
echo "Either curl or wget is required"
exit 1
fi
}
setRuntimeReleaseTag() {
local OPTIND
while getopts ":v:" opt; do
case $opt in
v)
echo "Passed Runtime Release Tag is: $OPTARG" >&2
RUNTIME_RELEASE_TAG=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
}
downloadFile() {
FOLDER_NAME=$1
FILE_NAME=$2
FILE_PATH="${PROTO_PATH}/${FOLDER_NAME}/v1"
# URL for proto file
PROTO_URL="https://raw.githubusercontent.com/dapr/dapr/${RUNTIME_RELEASE_TAG}/dapr/proto/${FOLDER_NAME}/v1/${FILE_NAME}.proto"
mkdir -p "${FILE_PATH}"
echo "Downloading $PROTO_URL ..."
if [ "$HTTP_REQUEST_CLI" == "curl" ]; then
(cd ${FILE_PATH} && curl -SsL "$PROTO_URL" -o "${FILE_NAME}.proto")
else
wget -q -P "$PROTO_URL" "${FILE_PATH}/${FILE_NAME}.proto"
fi
if [ ! -e "${FILE_PATH}/${FILE_NAME}.proto" ]; then
echo "failed to download $PROTO_URL ..."
ret_val=$FILE_NAME
exit 1
fi
}
fail_trap() {
result=$?
if [ $result != 0 ]; then
echo "Failed to download proto files: $ret_val"
fi
exit $result
}
# -----------------------------------------------------------------------------
# main
# -----------------------------------------------------------------------------
trap "fail_trap" EXIT
checkHttpRequestCLI
setRuntimeReleaseTag "$@"
downloadFile $COMMON $COMMON
downloadFile $RUNTIME $DAPR
downloadFile $RUNTIME $APPCALLBACK