-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
122 lines (94 loc) · 2.9 KB
/
install.sh
File metadata and controls
122 lines (94 loc) · 2.9 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
#!/usr/bin/env bash
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Scripts must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
source ./utils.sh
PROTOC_VERSION=${VERSION:-"latest"}
INSTALL_DIRECTLY_FROM_GITHUB_RELEASE=${INSTALLDIRECTLYFROMGITHUBRELEASE:-"true"}
GITHUB_REPO=https://github.com/google/protobuf
# Exit immediately if a command exits with a non-zero status.
set -e
apt_get_update
# Clean up
rm -rf /var/lib/apt/lists/*
export DEBIAN_FRONTEND=noninteractive
get_github_filename() {
local version=$1
local arch=$2
echo "protoc-${version}-linux-${arch}.zip"
}
install_from_github() {
local version_list=$(git ls-remote --tags ${GITHUB_REPO})
# Get 2 latest appropriate versions
versions=($(find_latest_versions $PROTOC_VERSION version_list "tags/v"))
if [ $? -eq 1 ]; then
echo "Can't find appropriate version"
exit 1
fi
latest_version=${versions[0]}
prev_version=${versions[1]}
echo "Downloading protoc v${latest_version}...."
check_packages wget
# Get architecture
local arch=$(dpkg --print-architecture)
# Map to generic architecture
case "$arch" in
amd64)
arch="x86_64"
;;
i386)
arch="x86_32"
;;
arm64)
arch="aarch64"
;;
armhf)
arch="arm"
;;
ppc64el)
arch="ppc64le"
;;
s390x)
arch="s390x"
;;
*)
echo "Unknown architecture $arch."
exit 1
;;
esac
local filename=$(get_github_filename $latest_version $arch)
set +e
# Create temporary directory
mkdir -p /tmp/protoc
pushd /tmp/protoc
# Download zip file
wget ${GITHUB_REPO}/releases/download/v${latest_version}/${filename}
local exit_code=$?
set -e
if [ "$exit_code" != "0" ]; then
# Handle situation where git tags are ahead of what was is available to actually download
echo "(!) protoc version ${latest_version} failed to download. Attempting to fall back to ${prev_version} to retry..."
filename=$(get_github_filename $prev_version $arch)
wget ${GITHUB_REPO}/releases/download/v${prev_version}/${filename}
fi
unzip /tmp/protoc/${filename} -d /tmp/protoc
# Install bin/
if [[ -d /tmp/protoc/bin ]]; then
echo "Installing binaries to /usr/local/bin/..."
cp -r /tmp/protoc/bin/* /usr/local/bin/
fi
# Move include/
if [[ -d /tmp/protoc/include ]]; then
echo "Installing headers to /usr/local/include/..."
cp -r /tmp/protoc/include/* /usr/local/include/
fi
# Remove temporary directory
popd
rm -rf /tmp/protoc
}
# Install curl, unzip if missing
check_packages curl ca-certificates unzip git
install_from_github
# Clean up
rm -rf /var/lib/apt/lists/*