|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Download, configure and install Ruby and Bundler |
| 4 | +# https://github.com/infertux/ruby-bootstrap |
| 5 | + |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +VERSION="3.4.2" |
| 9 | +SHA256="41328ac21f2bfdd7de6b3565ef4f0dd7543354d37e96f157a1552a6bd0eb364b" |
| 10 | + |
| 11 | +[ "${1:-}" = "--force" ] && FORCE=1 || FORCE="" |
| 12 | + |
| 13 | +[ $UID -eq 0 ] || { echo "Root required"; exit 1; } |
| 14 | + |
| 15 | +# Install Ruby and Bundler if they are missing or the force flag is set |
| 16 | +if [ -n "$FORCE" ] || ! command -v ruby > /dev/null; then |
| 17 | + # Dependency list: |
| 18 | + # - wget: to fetch Ruby and pretty useful anyway |
| 19 | + # - gcc & make: to compile Ruby |
| 20 | + # - various libs: libraries for Ruby |
| 21 | + |
| 22 | + if [ -f /etc/debian_version ]; then |
| 23 | + apt-get update |
| 24 | + apt-get install -y wget gcc make libffi-dev libreadline-dev libssl-dev libyaml-dev zlib1g-dev |
| 25 | + elif [ -f /etc/redhat-release ]; then |
| 26 | + yum install -y wget gcc make openssl-devel readline-devel zlib-devel |
| 27 | + fi |
| 28 | + |
| 29 | + cd /tmp |
| 30 | + wget https://cache.ruby-lang.org/pub/ruby/${VERSION%.*}/ruby-${VERSION}.tar.gz |
| 31 | + echo "${SHA256} ruby-${VERSION}.tar.gz" | sha256sum -c - |
| 32 | + tar --no-same-owner -xf ruby-${VERSION}.tar.gz |
| 33 | + |
| 34 | + pushd ruby-${VERSION} |
| 35 | + ./configure --disable-install-doc |
| 36 | + cpus=$(grep -c processor /proc/cpuinfo) |
| 37 | + make -j "$cpus" |
| 38 | + make install |
| 39 | + popd |
| 40 | + |
| 41 | + rm -rf ruby-${VERSION}.tar.gz ruby-${VERSION} |
| 42 | + |
| 43 | + ln -sfv /usr/local/bin/ruby /bin/ruby |
| 44 | + ln -sfv /usr/local/bin/gem /bin/gem |
| 45 | + ln -sfv /usr/local/bin/bundle /bin/bundle |
| 46 | + |
| 47 | + ruby -v |
| 48 | + gem -v |
| 49 | + bundle -v |
| 50 | +fi |
| 51 | + |
| 52 | +echo "All good to go, happy Rubying!" |
0 commit comments