-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9954047
commit a270e65
Showing
6 changed files
with
3,848 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
SCRIPT_NAME="$(basename "$0")" | ||
|
||
echo "${SCRIPT_NAME} is running... " | ||
|
||
PROTOC_VERSION=28.3 | ||
PROTOC_OS="" | ||
PROTOC_ARCH="" | ||
PROTOC_ZIP="" | ||
SUDO_CMD="" | ||
|
||
buildProtocZIPName() { | ||
PROTOC_ZIP=protoc-${PROTOC_VERSION}-${PROTOC_OS}-${PROTOC_ARCH}.zip | ||
} | ||
|
||
getOSName(){ | ||
KERNEL_TYPE=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
|
||
case "${KERNEL_TYPE}" in | ||
linux) | ||
PROTOC_OS="linux" | ||
;; | ||
darwin) | ||
PROTOC_OS="osx" | ||
;; | ||
freebsd) | ||
PROTOC_OS="freebsd" | ||
;; | ||
msys* | cygwin*) | ||
PROTOC_OS="win" | ||
echo "Your Operating System ${KERNEL_TYPE}-> ITS NOT SUPPORTED" | ||
exit 1 | ||
;; | ||
* ) | ||
echo "Your Operating System ${KERNEL_TYPE} -> ITS NOT SUPPORTED" | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
getArch(){ | ||
ARCH=$(uname -m) | ||
|
||
# supported archs | ||
# - amd64 | ||
# - arm64 | ||
# - 386 | ||
# - armv7 | ||
|
||
case "${ARCH}" in | ||
x86) | ||
PROTOC_ARCH="x86_32" | ||
;; | ||
i?86) | ||
PROTOC_ARCH="x86_32" | ||
;; | ||
amd64) | ||
PROTOC_ARCH="x86_64" | ||
;; | ||
arm64) | ||
PROTOC_ARCH="arm64" | ||
;; | ||
x86_64) | ||
PROTOC_ARCH="x86_64" | ||
;; | ||
aarch64) | ||
PROTOC_ARCH="aarch_64" | ||
;; | ||
* ) | ||
echo "Your Architecture ${ACRH} -> ITS NOT SUPPORTED." | ||
;; | ||
esac | ||
} | ||
|
||
cleanup() { | ||
trap - EXIT | ||
rm -rf ./protoc-* | ||
} | ||
|
||
downloadProtoc() { | ||
URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}" | ||
|
||
echo "Gonna to download ${PROTOC_ZIP} at ${URL}" | ||
|
||
wget --no-check-certificate -O "${PROTOC_ZIP}" "${URL}" && | ||
"${SUDO_CMD}"unzip -o "${PROTOC_ZIP}" -d /usr/local bin/protoc && | ||
"${SUDO_CMD}"unzip -o "${PROTOC_ZIP}" -d /usr/local 'include/*' && | ||
"${SUDO_CMD}"chmod +x /usr/local/bin/protoc | ||
} | ||
|
||
osxInstall() { | ||
echo "OSX" | ||
|
||
SUDO_CMD="" | ||
|
||
PROTOC_ARCH="x86_64" | ||
} | ||
|
||
linuxInstall() { | ||
echo "LINUX" | ||
|
||
DISTRO_ID=$(grep '^ID=' /etc/os-release | sed "s/ID=//") | ||
echo "${DISTRO_ID}" | ||
|
||
case "${DISTRO_ID}" in | ||
alpine*) | ||
SUDO_CMD="" | ||
;; | ||
ubuntu*) | ||
SUDO_CMD="sudo " | ||
;; | ||
esac | ||
} | ||
|
||
install() { | ||
getOSName | ||
getArch | ||
|
||
case "${PROTOC_OS}" in | ||
osx*) | ||
osxInstall | ||
;; | ||
linux*) | ||
linuxInstall | ||
;; | ||
win*) | ||
## TODO(o.balunenko): add windows installation. | ||
echo "WINDOWS" | ||
exit 1 | ||
;; | ||
*) | ||
echo "unsupported os: ${PROTOC_OS}" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
buildProtocZIPName | ||
|
||
downloadProtoc | ||
|
||
cleanup | ||
|
||
|
||
echo "Protoc version: $(protoc --version)" | ||
} | ||
|
||
install | ||
|
||
echo "${SCRIPT_NAME} done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.