dgiot/scripts/ensure-rebar3.sh

29 lines
594 B
Bash
Raw Normal View History

2021-05-18 14:54:48 +08:00
#!/usr/bin/env bash
set -euo pipefail
VERSION="$1"
# ensure dir
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
2022-01-07 18:05:15 +08:00
DOWNLOAD_URL='https://dgiot-dev-1306147891.cos.ap-nanjing.myqcloud.com'
2021-05-18 14:54:48 +08:00
download() {
2022-01-07 19:45:54 +08:00
wget ${DOWNLOAD_URL}/${VERSION}/rebar3
2021-05-18 14:54:48 +08:00
}
# get the version number from the second line of the escript
# because command `rebar3 -v` tries to load rebar.config
# which is slow and may print some logs
version() {
head -n 2 ./rebar3 | tail -n 1 | tr ' ' '\n' | grep -E '^.+-emqx-.+'
}
if [ -f 'rebar3' ] && [ "$(version)" = "$VERSION" ]; then
2022-01-07 18:05:15 +08:00
exit 0
2021-05-18 14:54:48 +08:00
fi
download
chmod +x ./rebar3