ensure-rebar3.sh 935 B

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