-
Notifications
You must be signed in to change notification settings - Fork 25
/
ruby-build-update
executable file
·74 lines (61 loc) · 1.54 KB
/
ruby-build-update
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
#!/bin/sh
set -euf
out () { printf %s\\n "$*" ; }
##
# Use the `ruby-build` program to install Ruby in our preferred locations.
#
# We put the `ruby-build` git repo here:
#
# /opt/ruby-build
#
# We install Ruby MRI here:
#
# /opt/ruby/<version>
#
# Example installation directory:
#
# /opt/ruby/3.0.2
#
# Syntax:
#
# ruby-build-update [version [-c]]
#
# Contact: Joel Parker Henderson ([email protected])
# License: GPL
# Updated: 2021-07-17T19:15:44Z
##
# Get the official Ruby interpreter current version.
#
# Example: "3.0.2"
#
ruby_build_definition_of_yarv_current() {
ruby-build --definitions | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | tail -1
}
## Input
if [ "$#" -eq 0 ]; then
RUBY_VERSION=$(ruby_build_definition_of_yarv_current)
CREATE_CURRENT_SYMLINK=1 #true
else
RUBY_VERSION=$1
RUBY_VERSION_SANS_SUFFIX=${RUBY_VERSION%%-p*} # e.g. "3.0.2" but not "3.0.2-dev"
CREATE_CURRENT_SYMLINK=$2
fi
## Config
RUBY_BUILD_DIR=/opt/ruby-build
RUBY_DIR=/opt/ruby
## Install
# Install ruby-build as needed
test -d "$RUBY_BUILD_DIR" || sudo git clone https://github.com/sstephenson/ruby-build "$RUBY_BUILD_DIR"
# Update ruby-build
cd "$RUBY_BUILD_DIR" && git pull && ./install.sh
# Create ruby directory as needed
test -d " $RUBY_DIR" || mkdir -p "$RUBY_DIR"
# Install Ruby as needed
test -d "$RUBY_DIR/$RUBY_VERSION" || ruby-build "$RUBY_VERSION" "$RUBY_DIR/$RUBY_VERSION"
# Create `current` symlink
if [ "$CREATE_CURRENT_SYMLINK" -eq 1 ]; then
cd "$RUBY_DIR"
ln -nsf "$RUBY_VERSION" current
source /etc/environment
ruby -v
fi