-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·91 lines (75 loc) · 3.2 KB
/
install.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
#!/bin/bash
set -e
REPO="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PB=$REPO/protobuf
PROTOC_DIR=${PROTOC_DIR:-"/opt/.protoc"}
echo "Installing protoc and plugins in $PROTOC_DIR"
cd "$PB"
rm -rf $PROTOC_DIR && mkdir -p $PROTOC_DIR
source "$REPO/versions.sh"
PROTO_ARCH="linux-x86_64"
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "MacOS detected"
PROTO_ARCH="osx-x86_64"
if [[ $(uname -m) == 'arm64' ]]; then
echo "ARM64 detected"
PROTO_ARCH="osx-aarch_64"
fi
fi
if [[ "$OSTYPE" == "linux"* ]]; then
echo "Linux detected"
PROTO_ARCH="linux-x86_64"
if [[ $(uname -m) == 'aarch64' ]]; then
echo "ARM64 detected"
PROTO_ARCH="linux-aarch_64"
fi
fi
mkdir -p $PROTOC_DIR/bin
echo "Installing protoc $PROTOC_VERSION for $PROTO_ARCH"
wget -nv -O "$PROTOC_DIR/protoc-${PROTOC_VERSION}-${PROTO_ARCH}.zip" https://github.com/protocolbuffers/protobuf/releases/download/v"${PROTOC_VERSION}"/protoc-"${PROTOC_VERSION}"-"${PROTO_ARCH}".zip
unzip -qq -o $PROTOC_DIR/protoc-"${PROTOC_VERSION}"-${PROTO_ARCH}.zip -d "${PROTOC_DIR}"
rm -f $PROTOC_DIR/protoc-"${PROTOC_VERSION}"-${PROTO_ARCH}.zip "$PROTOC_DIR/readme.txt"
GOBIN=$PROTOC_DIR/bin go install github.com/twitchtv/twirp/protoc-gen-twirp@"${PROTO_TWIRP_VERSION}"
GOBIN=$PROTOC_DIR/bin go install google.golang.org/protobuf/cmd/protoc-gen-go@"${PROTO_GO_VERSION}"
GOBIN=$PROTOC_DIR/bin go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@"${PROTO_VTPROTO_VERSION}"
GOBIN=$PROTOC_DIR/bin go install github.com/yoheimuta/protolint/cmd/protolint@"${PROTO_LINT_VERSION}"
(
cd "$REPO/tools"
PROTOC_DIR=$PROTOC_DIR ./install.sh
)
echo "Installing plugins..."
if command -v dart &> /dev/null
then
echo "Installing dart protoc plugin"
PUB_CACHE=${PROTOC_DIR}/.pub-cache dart pub global activate protoc_plugin 20.0.1
cp ${PROTOC_DIR}/.pub-cache/bin/protoc-gen-dart ${PROTOC_DIR}/bin/protoc-gen-dart
else
echo 'Dart is not installed. Skipping...'
fi
# Swift also requires installing Xcode and other tools which are required for iOS
# development. Without this it will error out complaining that the module 'PackageDescription'
# is not found while building. Hence, providing an option to disable it altogether.
if [[ -z $DISABLE_SWIFT ]]; then
if command -v swift &> /dev/null
then
echo "Installing swift protoc plugin"
git clone --depth 1 --branch 1.22.0 https://github.com/apple/swift-protobuf $PROTOC_DIR/.swift-protobuf
(cd $PROTOC_DIR/.swift-protobuf && swift build -c release)
ln -s $PROTOC_DIR/.swift-protobuf/.build/release/protoc-gen-swift $PROTOC_DIR/bin/protoc-gen-swift
else
echo 'Swift compiler is not installed. Skipping...'
fi
else
echo 'Swift is disabled. Skipping...'
fi
if command -v yarn &> /dev/null
then
echo "Installing typescript protoc plugin"
mkdir $PROTOC_DIR/.typescript-protobuf
(cd $PROTOC_DIR/.typescript-protobuf && yarn add @protobuf-ts/[email protected] [email protected] --no-lockfile --disable-pnp)
ln -s $PROTOC_DIR/.typescript-protobuf/node_modules/.bin/protoc-gen-ts $PROTOC_DIR/bin/protoc-gen-ts
ln -s $PROTOC_DIR/.typescript-protobuf/node_modules/.bin/prettier $PROTOC_DIR/bin/prettier
else
echo 'yarn is not installed. Skipping...'
fi
echo "Finished installing plugins"