ruby

by ligonier
1 deployments · 0 still active · last rev. 5 years ago

Whether you need to setup an MRI version of Ruby, or Rubinius or REE; this StackScript provides the necessary functions to install released versions of various Ruby interpreters.

Compatible with: No distros currently supported
						#!/bin/bash
#
# ---
#
# Ruby StackScript - handles installing a Ruby interpreter from source
#
# Whether you need to setup an MRI version of Ruby, or Rubinius or REE; this
# StackScript provides the necessary functions to install released versions of
# various Ruby interpreters.
#
# ---
#
# Copyright (c) 2011 Ligonier Ministries
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
#   this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
#
# * Neither the name of Ligonier Ministries nor the names of its contributors
#   may be used to endorse or promote products derived from this software
#   without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

function install_mri_ruby {
  # $1 - MRI Version
  if [ ! -n "$1" ];
    then MRI_VERSION="1.9.2-p290"
    else MRI_VERSION="$1"
  fi
  
  if [[ "$MRI_VERSION" =~ "1.9" ]];
    then MRI_MAJOR_VERSION = "1.9"
  fi
  
  if [[ "$MRI_VERSION" =~ "1.8" ]];
    then MRI_MAJOR_VERSION = "1.8"
  fi
  
  # $2 - Extra configure opts
  if [ ! -n "$2" ];
    then MRI_CONF_OPTS=""
    else MRI_CONF_OPTS="$2"
  fi
  
  cd /usr/local/src
  
  wget http://ftp.ruby-lang.org/pub/ruby/$MRI_MAJOR_VERSION/ruby-$MRI_VERSION.tar.gz
  tar xzf ruby-$MRI_VERSION.tar.gz
  cd ruby-$MRI_VERSION
  
  ./configure --prefix=/usr/local $MRI_CONF_OPTS
  make && make install
}

function install_rubinius {
  # $1 - Rubinius Version
  if [ ! -n "$1" ];
    then RBX_VERSION="HEAD"
    else RBX_VERSION="$1"
  fi
  
  # $2 - Extra configure opts
  if [ ! -n "$2" ];
    then RBX_CONF_OPTS=""
    else RBX_CONF_OPTS="$2"
  fi
  
  cd /usr/local/src
  git clone git://github.com/rubinius/rubinius.git
  cd rubinius
  
  if [[ ! "$RBX_VERSION" =~ "HEAD" ]];
    then git checkout $RBX_VERSION
  fi
  
  ./configure --prefix /usr/local/rbx --bindir /usr/local/bin $RBX_CONF_OPTS
  rake install
}

function install_ruby_enterprise {
  # TODO
}

function install_global_gemrc {
  OUTFILE=/etc/skel/.gemrc
  
  (
cat <<EOF
---
gem: --no-ri --no-rdoc  
EOF
  ) > $OUTFILE
  
  cp $OUTFILE /root/.gemrc
}

function update_rubygems_install {
  # $1 - Ruby Interpreter
  if [ ! -n "$1" ];
    then RUBY_INTERPRETER="MRI"
    else RUBY_INTERPRETER="$1"
  fi
  
  if [[ $RUBY_INTERPRETER == "MRI" ]];
    gem update --system --no-ri --no-rdoc
    gem uninstall rubygems-update
  fi
  
  if [[ $RUBY_INTERPRETER == "RBX" ]];
    rbx -S gem update --system --no-ri --no-rdoc
    rbx -S gem uninstall rubygems-update
  fi
  
  log "Updated RubyGems installation..."
}