-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathinstall_ruby.sh
More file actions
executable file
·99 lines (84 loc) · 2.6 KB
/
install_ruby.sh
File metadata and controls
executable file
·99 lines (84 loc) · 2.6 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
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -ex
RUBY_VERSION=${RUBY_VERSION-2.6.0}
RUBY_MAJOR=$(echo $RUBY_VERSION | sed -E 's/\.[0-9]+(-.*)?$//g')
RUBYGEMS_VERSION=${RUBYGEMS_VERSION-3.2.3}
function get_released_ruby() {
git clone --depth 1 https://github.com/ruby/www.ruby-lang.org.git /tmp/www
cat << RUBY | ruby - $1 /tmp/www/_data/releases.yml
require "psych"
version = ARGV[0]
releases = Psych.load_file(ARGV[1])
release = releases.find {|x| x["version"] == version }
puts "#{release["url"]["xz"]} #{release["sha256"]["xz"]}"
RUBY
rm -rf /tmp/www
}
case $RUBY_VERSION in
master:*)
RUBY_MASTER_COMMIT=$(echo $RUBY_VERSION | awk -F: '{print $2}' )
RUBY_VERSION=master
;;
*)
read RUBY_DOWNLOAD_URI RUBY_DOWNLOAD_SHA256 < <(get_released_ruby $RUBY_VERSION)
if test -z "$RUBY_DOWNLOAD_URI"; then
echo "Unsupported RUBY_VERSION ($RUBY_VERSION)" >2
exit 1
fi
echo $RUBY_DOWNLOAD_URI
echo $RUBY_DOWNLOAD_SHA256
;;
esac
case $RUBY_VERSION in
2.3.*)
# Need to down grade openssl to 1.0.x for Ruby 2.3.x
apt-get install -y --no-install-recommends libssl1.0-dev
;;
esac
# Since Ruby 2.6, Bundler is a part of Ruby’s standard library, but below this version we need to install Bundler.
if [ "$(printf '%s\n' "$RUBY_VERSION" "2.6.0" | sort -V | head -n1)" = "$RUBY_VERSION" ]; then
gem install bundler
fi
if test -n "$RUBY_MASTER_COMMIT"; then
if test -f /usr/src/ruby/configure.ac; then
cd /usr/src/ruby
git pull --rebase origin
else
rm -r /usr/src/ruby
git clone --shallow-since=$RUBY_MASTER_COMMIT https://github.com/ruby/ruby.git /usr/src/ruby
cd /usr/src/ruby
fi
git checkout $RUBY_MASTER_COMMIT
else
if test -z "$RUBY_DOWNLOAD_URI"; then
RUBY_DOWNLOAD_URI="https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR}/ruby-${RUBY_VERSION}.tar.xz"
fi
wget -O ruby.tar.xz $RUBY_DOWNLOAD_URI
echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum -c -
mkdir -p /usr/src/ruby
tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1
rm ruby.tar.xz
fi
(
cd /usr/src/ruby
autoconf
mkdir -p /tmp/ruby-build
pushd /tmp/ruby-build
gnuArch=$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)
/usr/src/ruby/configure \
--build="$gnuArch" \
--prefix=/usr/local \
--disable-install-doc \
--enable-shared \
${cppflags:+cppflags="${cppflags}"} \
${optflags:+optflags="${debugflags}"} \
optflags="${optflags:--O3}" \
${debugflags:+debugflags="${debugflags}"}
make -j "$(nproc)"
make install
popd
rm -rf /tmp/ruby-build
)
rm -fr /usr/src/ruby /root/.gem/
# rough smoke test
(cd && ruby --version && gem --version && bundle --version)