[Bash] Instalador de Ruby (ultima version) en RHEL/CentOS

Iniciado por B3N, Agosto 09, 2015, 12:49:43 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Puesto que RHEL y CentOS siempre estan un poco atrasados en este asunto es necesario instalar "a mano" las cosas actualizadas, bueno en este caso he simplificado el proceso de intalacion para Ruby. El instalador hace uso de rbenv, el gestor de instalacion y actualizacion recomendado por los desarrolladores de Ruby y Ruby on Rails, pudiendo instalar multiples versiones simultaneamente y coexistir sin problemas, ademas de que hace mucho mas sencillo el proceso de actualizacion.

Código: bash
#!/bin/bash
#
##############################################################
#
# Author: B3N
# Name: ruby-installer
# Version: 1.0
# Description: Install the lastest version of Ruby using rbenv
# Licence: GPLv2
# Platform: RHEL/CentOS/Fedora
#
##############################################################


# Logo
echo
echo "============================================================"
echo "               Ruby Installer v1.0 - By B3N"
echo "============================================================"
echo
echo "[i] rbenv and ruby will be installed only for the user $USER"

# Dependencies
rpm -q openssl-devel readline-devel zlib-devel git > /dev/null
if [ $? -ne 0 ]; then
if [ `id -u` == 0 ]; then
echo "[+] Installing dependencies..."
yum install -y openssl-devel readline-devel zlib-devel git
if [ $? -ne 0 ]; then
exit 1
fi
else
echo "[+] Installing dependencies..."
su -c 'yum install -y openssl-devel readline-devel zlib-devel git'
if [ $? -ne 0 ]; then
exit 1
fi
fi
fi

# Clone rbenv repo
if [ -d ~/.rbenv ]; then
echo "[-] Directory ~/.rbenv exists."
else
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
if [ $? -eq 0 ]; then
echo "[+] rbenv repo cloned to ~/.rbenv."
fi
fi

# PATH
if [ -d ~/.rbenv/bin ]; then
grep 'export PATH="$HOME/.rbenv/bin:$PATH"' ~/.bashrc > /dev/null
if [ $? -ne 0 ]; then
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
export PATH="$HOME/.rbenv/bin:$PATH"
echo "[+] rbenv added to PATH"
else
echo "[-] rbenv is in the PATH."
fi
else
exit 1
fi

# Autocompletion
if [ -d ~/.rbenv/bin ]; then
grep 'eval "$(rbenv init -)"' ~/.bashrc > /dev/null
if [ $? -ne 0 ]; then
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
eval "$(rbenv init -)"
echo "[+] Autocompletion activated."
else
echo "[-] Autocompletion already activated."
fi
else
exit 1
fi

## Plugins:
# ruby-build
if [ -d ~/.rbenv/plugins/ruby-build ]; then
echo "[-] Directory ~/.rbenv/plugins/ruby-build exists."
else
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
if [ $? -eq 0 ]; then
echo "[+] Plugin ruby-build installed."
fi
fi
# rbenv-rehash
if [ -d ~/.rbenv/plugins/rbenv-gem-rehash ]; then
echo "[-] Directory ~/.rbenv/plugins/rbenv-gem-rehash exists."
else
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
if [ $? -eq 0 ]; then
echo "[+] Plugin rbenv-rehash installed."
fi
fi

# Install ruby
if [ -x ~/.rbenv/libexec/rbenv ]; then
rbenv install -l
read -p "Type version to install: " RV
if [ `rbenv version|awk -F " " {'print $1'}` == $RV ]; then
echo "[-] Ruby $RV already installed, nothing to do."
else
rbenv install -v -k $RV
rbenv global $RV
echo "[i] Restart your terminal to finish."
fi
else
echo "[-] rbenv is not installed."
fi
01010111 01100001 01101011 01100101 00100000 01110101
01110000 00100000 01001110 01100101 01101111