install_flatbuffers.sh 1.1 KB

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