ensure-rebar3.sh 606 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. VERSION="$1"
  4. # ensure dir
  5. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
  6. DOWNLOAD_URL='https://github.com/emqx/rebar3/releases/download'
  7. download() {
  8. curl -f -L "${DOWNLOAD_URL}/${VERSION}/rebar3" -o ./rebar3
  9. }
  10. # get the version number from the second line of the escript
  11. # because command `rebar3 -v` tries to load rebar.config
  12. # which is slow and may print some logs
  13. version() {
  14. head -n 2 ./rebar3 | tail -n 1 | tr ' ' '\n' | grep -E '^.+-emqx-.+'
  15. }
  16. if [ -f 'rebar3' ] && [ "$(version)" = "$VERSION" ]; then
  17. exit 0
  18. fi
  19. download
  20. chmod +x ./rebar3