ensure-rebar3.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. ## rebar3 tag 3.18.0-emqx-1 is compiled using otp24.1.5.
  4. ## we have to use an otp24-compiled rebar3 because the defination of record #application{}
  5. ## in systools.hrl is changed in otp24.
  6. OTP_VSN="${OTP_VSN:-$(./scripts/get-otp-vsn.sh)}"
  7. case ${OTP_VSN} in
  8. 23*)
  9. VERSION="3.16.1-emqx-1"
  10. ;;
  11. 24*)
  12. VERSION="3.18.0-emqx-1"
  13. ;;
  14. *)
  15. echo "Unsupporetd Erlang/OTP version $OTP_VSN"
  16. exit 1
  17. ;;
  18. esac
  19. # ensure dir
  20. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
  21. DOWNLOAD_URL='https://github.com/emqx/rebar3/releases/download'
  22. download() {
  23. echo "downloading rebar3 ${VERSION}"
  24. curl -f -L "${DOWNLOAD_URL}/${VERSION}/rebar3" -o ./rebar3
  25. }
  26. # get the version number from the second line of the escript
  27. # because command `rebar3 -v` tries to load rebar.config
  28. # which is slow and may print some logs
  29. version() {
  30. head -n 2 ./rebar3 | tail -n 1 | tr ' ' '\n' | grep -E '^.+-emqx-.+'
  31. }
  32. if [ -f 'rebar3' ] && [ "$(version)" = "$VERSION" ]; then
  33. exit 0
  34. fi
  35. download
  36. chmod +x ./rebar3