install_flatbuffers.sh raw
1 #!/usr/bin/env bash
2
3 set -e
4
5 install_mac() {
6 command -v brew >/dev/null ||
7 {
8 echo "[ERROR]: 'brew' command not not found. Exiting" 1>&2
9 exit 1
10 }
11 brew install flatbuffers
12 }
13
14 install_linux() {
15 for CMD in curl cmake g++ make; do
16 command -v "${CMD}" >/dev/null ||
17 {
18 echo "[ERROR]: '${CMD}' command not not found. Exiting" 1>&2
19 exit 1
20 }
21 done
22
23 ## Create Temp Build Directory
24 BUILD_DIR=$(mktemp -d)
25 pushd "${BUILD_DIR}"
26
27 ## Fetch Latest Tarball
28 LATEST_VERSION=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep -oP '(?<=tag_name": ")[^"]+')
29 curl -sLO https://github.com/google/flatbuffers/archive/"${LATEST_VERSION}".tar.gz
30 tar xf "${LATEST_VERSION}".tar.gz
31
32 ## Build Binaries
33 cd flatbuffers-"${LATEST_VERSION#v}"
34 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
35 make
36 ./flattests
37 cp flatc /usr/local/bin/flatc
38
39 ## Cleanup Temp Build Directory
40 popd
41 rm -rf "${BUILD_DIR}"
42 }
43
44 SYSTEM=$(uname -s)
45
46 case ${SYSTEM,,} in
47 linux)
48 sudo bash -c "$(declare -f install_linux); install_linux"
49 ;;
50 darwin)
51 install_mac
52 ;;
53 esac
54