-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprotocw
More file actions
executable file
·188 lines (153 loc) · 5.12 KB
/
protocw
File metadata and controls
executable file
·188 lines (153 loc) · 5.12 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env bash
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## This is an auto-generated wrapper for Protocol Buffer's protoc utility ##
## ##
## Don't edit this file directly ##
## ##
## This file and its companion protocw.properties are expected to be committed ##
## into source control repository, while .protocw folder is expected to be ignored ##
## ##
## For help, run `./protocw --help` or refer to the project Github ##
## To update, run `./protocw --self-update` ##
## ##
## Protoc Wrapper | https://github.com/freenowtech/protoc-wrapper ##
## Lucas Laurindo dos Santos | https://github.com/lucasls ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
INSTALL_BASE_URL="https://raw.githubusercontent.com/freenowtech/protoc-wrapper/master"
basedir=$(dirname "$0")
lower() {
echo $1 | tr '[:upper:]' '[:lower:]'
}
print() {
printf "$1" >&2
}
println() {
echo "$1" >&2
}
version_lte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
version_lt() {
[ "$1" = "$2" ] && return 1 || version_lte $1 $2
}
configure() {
println ""
print "What's the target protoc version? "
read version
echo "protoc_version=$version" > $basedir/protocw.properties
println "Version set to $version, to change it run protocw --configure"
if [ -f pom.xml ]
then
print "* Maven detected, replacing existing calls to protoc with protocw if necessary..."
sed -E -i "" "s /usr/local/bin/protoc(-[0-9]+\.[0-9]+\.[0-9]+)? ./protocw g" pom.xml
println " done."
fi
if [ -d .git ]
then
print "* Git detected, adding .protocw to .gitignore if necessary..."
if ! grep -q ".protocw" .gitignore
then
printf "\n.protocw" >> .gitignore
fi
println " done."
fi
println ""
exit
}
help() {
println "** Protoc Wrapper Help: **"
println ""
println " --configure Sets up what version of protoc to use"
println " --self-update Updates Protoc Wrapper to the newest version"
if [ -z $protoc_version ]
then
exit
fi
println ""
println "** Protoc Help **"
println ""
}
version() {
if ! version_lt $protoc_version "3.22.0"
then
VERSION_DISCLAIMER="Since version 3.22.0, the major version is no longer part of the returned version number"
if [ "$keep_major_version_number" = "true" ]
then
println "INFO: $VERSION_DISCLAIMER, returning backwards compatible version number"
println
echo "libprotoc $protoc_version"
exit 0
else
println "WARN: $VERSION_DISCLAIMER, set \`keep_major_version_number=true\` in \`protocw.properties\` to keep the major version number"
println
fi
fi
}
self_update() {
println "Starting Protoc Wrapper self update..."
println ""
eval "$(curl -fsSL $INSTALL_BASE_URL/install.sh)"
exit
}
# Start
if [ "$1" = "--configure" ]
then
configure
fi
if [ "$1" = "--self-update" ]
then
self_update
fi
touch $basedir/protocw.properties
source $basedir/protocw.properties
if [ "$1" = "--help" ]
then
help
fi
if [ -z $protoc_version ]
then
println "protoc_version not set in protocw.properties"
exit -1
fi
mkdir -p "$basedir/.protocw"
filename="$basedir/.protocw/protoc-$protoc_version"
if [ ! -f $filename ]
then
if [ $(lower $(uname)) = "darwin" ]
then
osname="osx"
else
osname="linux"
fi
if [ $(uname -m) = "arm64" ]
then
if [ $osname = "osx" ] && version_lt $protoc_version "3.17.3"
then
println "WARN: arm64 on osx detected, downloading x86_64 binaries; use protoc_version >= 3.17.3 for native binaries on osx"
osarch="x86_64"
elif [ $osname = "linux" ] && version_lt $protoc_version "3.10.0"
then
println "ERROR: only protoc_version >= 3.10.0 is supported for arm64 on linux"
exit -1
else
osarch="aarch_64"
fi
else
osarch=$(uname -m)
fi
print "Downloading Protoc version: $protoc_version-$osname-$osarch... "
curl "https://repo1.maven.org/maven2/com/google/protobuf/protoc/$protoc_version/protoc-$protoc_version-$osname-$osarch.exe" -o $filename --fail --silent
last_error=$?
if [ $last_error -ne 0 ]; then
println "Error"
println "Could not download protoc, please check if version $protoc_version is a valid version in protoc Maven Repository"
exit $last_error
fi
println "Done"
chmod +x $filename
fi
if [ "$1" = "--version" ]
then
version
fi
"$filename" "$@"