utils.sh 1.5 KB
Newer Older
1
RUBY_BUILD_VERSION="${ASDF_RUBY_BUILD_VERSION:-v20191124}"
2
RUBY_BUILD_TAG="$RUBY_BUILD_VERSION"
3

P
Patrick Oscity 已提交
4 5 6 7
echoerr() {
  >&2 echo -e "\033[0;31m$1\033[0m"
}

8 9 10 11 12 13
ensure_ruby_build_setup() {
  #set_ruby_build_env
  ensure_ruby_build_installed
}

ensure_ruby_build_installed() {
14 15
    local ruby_build_version

16 17 18
    if [ ! -f "$(ruby_build_path)" ]; then
        download_ruby_build
    else
19 20
        current_ruby_build_version="$("$(ruby_build_path)" --version | cut -d ' ' -f2)"
        if [ "$current_ruby_build_version" != "$RUBY_BUILD_VERSION" ]; then
21 22 23 24 25 26 27 28 29 30 31
            # If the ruby-build directory already exists and the version does not
            # match, remove it and download the correct version
            rm -rf "$(ruby_build_dir)"
            download_ruby_build
        fi
    fi
}

download_ruby_build() {
    # Print to stderr so asdf doesn't assume this string is a list of versions
    echo "Downloading ruby-build..." >&2
32
    local build_dir="$(asdf_ruby_plugin_path)/ruby-build-source"
33 34 35

    # Clone down and checkout the correct ruby-build version
    git clone https://github.com/rbenv/ruby-build.git $build_dir >&2 >/dev/null
36
    (cd $build_dir; git checkout $RUBY_BUILD_TAG >&2 >/dev/null)
37 38

    # Install in the ruby-build dir
39
    PREFIX="$(ruby_build_dir)" $build_dir/install.sh
40 41

    # Remove ruby-build source dir
42
    rm -rf $build_dir
43 44
}

45 46 47
asdf_ruby_plugin_path() {
    echo "$(dirname "$(dirname "$0")")"
}
48
ruby_build_dir() {
49
    echo "$(asdf_ruby_plugin_path)/ruby-build"
50 51 52
}
ruby_build_path() {
    echo "$(ruby_build_dir)/bin/ruby-build"
P
Patrick Oscity 已提交
53
}
54 55 56

#set_ruby_build_env() {
#}