ensure-rebar3.sh 1.2 KB

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