install_flatbuffers.sh 1.1 KB

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