ensure-rebar3.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. ## rebar3 tag 3.19.0-emqx-1 is compiled using latest official OTP-24 image.
  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. 25*)
  15. VERSION="3.19.0-emqx-1"
  16. ;;
  17. *)
  18. echo "Unsupporetd Erlang/OTP version $OTP_VSN"
  19. exit 1
  20. ;;
  21. esac
  22. # ensure dir
  23. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
  24. DOWNLOAD_URL='https://github.com/emqx/rebar3/releases/download'
  25. download() {
  26. echo "downloading rebar3 ${VERSION}"
  27. curl -f -L "${DOWNLOAD_URL}/${VERSION}/rebar3" -o ./rebar3
  28. }
  29. # get the version number from the second line of the escript
  30. # because command `rebar3 -v` tries to load rebar.config
  31. # which is slow and may print some logs
  32. version() {
  33. head -n 2 ./rebar3 | tail -n 1 | tr ' ' '\n' | grep -E '^.+-emqx-.+'
  34. }
  35. if [ -f 'rebar3' ] && [ "$(version)" = "$VERSION" ]; then
  36. exit 0
  37. fi
  38. download
  39. chmod +x ./rebar3