get-rebar3 698 B

12345678910111213141516171819202122232425262728293031
  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. local url="${DOWNLOAD_URL}/${VERSION}/rebar3"
  9. echo "Downloading rebar3 from '${url}' ..."
  10. curl --silent --show-error -f -L "${url}" -o ./rebar3
  11. }
  12. # get the version number from the second line of the escript
  13. # because command `rebar3 -v` tries to load rebar.config
  14. # which is slow and may print some logs
  15. version() {
  16. head -n 2 ./rebar3 | tail -n 1 | tr ' ' '\n' | grep -E '^.+-emqx-.+'
  17. }
  18. if [ -f 'rebar3' ] && [ "$(version)" = "$VERSION" ]; then
  19. exit 0
  20. fi
  21. download
  22. chmod +x ./rebar3