-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathutils.sh
More file actions
86 lines (71 loc) · 2.2 KB
/
utils.sh
File metadata and controls
86 lines (71 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
RUBY_BUILD_VERSION="${ASDF_RUBY_BUILD_VERSION:-v20251225}"
RUBY_BUILD_TAG="$RUBY_BUILD_VERSION"
echoerr() {
echo >&2 -e "\033[0;31m$1\033[0m"
}
errorexit() {
echoerr "$1"
exit 1
}
ensure_ruby_build_setup() {
ensure_ruby_build_installed
}
ensure_ruby_build_installed() {
local current_ruby_build_version
if [ ! -f "$(ruby_build_path)" ]; then
download_ruby_build
else
current_ruby_build_version="$("$(ruby_build_path)" --version | cut -d ' ' -f2)"
# If ruby-build version does not start with 'v',
# add 'v' to beginning of version
# shellcheck disable=SC2086
if [ ${current_ruby_build_version:0:1} != "v" ]; then
current_ruby_build_version="v$current_ruby_build_version"
fi
if [ "$current_ruby_build_version" != "$RUBY_BUILD_VERSION" ]; then
# 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
echoerr "Downloading ruby-build..."
# shellcheck disable=SC2155
local build_dir="$(ruby_build_source_dir)"
# Remove directory in case it still exists from last download
rm -rf "$build_dir"
# Clone down and checkout the correct ruby-build version
git clone https://github.com/rbenv/ruby-build.git "$build_dir" >/dev/null 2>&1
(
cd "$build_dir" || exit
git checkout "$RUBY_BUILD_TAG" >/dev/null 2>&1
)
# Install in the ruby-build dir
PREFIX="$(ruby_build_dir)" "$build_dir/install.sh"
# Remove ruby-build source dir
rm -rf "$build_dir"
}
asdf_ruby_plugin_path() {
local source_path="${BASH_SOURCE[0]:-$0}"
local script_dir
script_dir="$(cd "$(dirname "$source_path")" >/dev/null 2>&1 && pwd)"
# shellcheck disable=SC2005
echo "$(dirname "$script_dir")"
}
ruby_build_dir() {
echo "$(asdf_ruby_plugin_path)/ruby-build"
}
ruby_build_source_dir() {
echo "$(asdf_ruby_plugin_path)/ruby-build-source"
}
ruby_build_path() {
echo "$(ruby_build_dir)/bin/ruby-build"
}
ruby_build_definitions() {
ensure_ruby_build_setup
"$(ruby_build_path)" --definitions | grep -v "topaz-dev"
}