Skip to content

Instantly share code, notes, and snippets.

@troyfontaine
Last active May 11, 2020 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyfontaine/e4563d415c1913f37a83099a1134020b to your computer and use it in GitHub Desktop.
Save troyfontaine/e4563d415c1913f37a83099a1134020b to your computer and use it in GitHub Desktop.
Pipeline Script to install rbenv, rbenv gemset and ruby-build
#!/bin/bash
# Bash script to check if rbenv is installed along with a few necessities and if they don't exist
# to install them
TEST_RUBY_VERSION="2.6.3"
install_rbenv() {
echo "--- :construction: Installing Rbenv"
# Clone rbenv from Github
git clone https://github.com/rbenv/rbenv.git "$HOME/.rbenv" > /dev/null 2>&1
# Configure the shell
# shellcheck disable=SC2016
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> "$HOME/.bash_profile"
# Initialize rbenv
"$HOME/.rbenv/bin/rbenv" init
# Automatically start rbenv
# shellcheck disable=SC2016
echo 'eval "$(rbenv init -)"' >> "$HOME/.bash_profile"
# shellcheck disable=SC1090
source ~/.bash_profile
}
install_gemset() {
echo "--- :construction: Installing Rbenv Gemset plugin"
git clone git://github.com/jf/rbenv-gemset.git "$HOME/.rbenv/plugins/rbenv-gemset" > /dev/null 2>&1
}
install_rubybuild() {
# Install dependencies
#sudo yum groupinstall "Development Tools"
echo "--- :construction: Installing Dependencies for Ruby-build"
yum install -y gcc make tar bzip2 openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel > /dev/null 2>&1
echo "--- :construction: Installing Ruby-build"
# Setup the plugin
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$HOME/.rbenv/plugins/ruby-build" > /dev/null 2>&1
# Configure Rubygems for speed
echo -e "gem: --no-document\nbenchmark: false\nverbose: false\nupdate_sources: true\nbacktrace: true\nsources:\n- https://rubygems.org" > "$HOME/.gemrc"
if [ -d "$HOME/.rbenv/versions/$TEST_RUBY_VERSION" ]; then
exit
else
test_rubybuild
fi
}
test_rubybuild() {
echo "--- :construction: Installing Ruby $TEST_RUBY_VERSION"
# Test installing Ruby $TEST_RUBY_VERSION
rbenv install $TEST_RUBY_VERSION
}
command -v git >/dev/null 2>&1 || { echo >&2 "--- :stop: Git is required to run this script, but it's not installed. Exiting"; exit 1; }
# Check if rbenv is available
if [ -d "$HOME/.rbenv" ]; then
echo "--- :large_green_circle: Rbenv is available"
# rbenv is available, is ruby-build?
if [ -d "$HOME/.rbenv/plugins/ruby-build" ]; then
echo "--- :large_green_circle: Ruby-build is available"
else
install_ruby-build
fi
# rbenv is available, is rbenv-gemset?
if [ -d "$HOME/.rbenv/plugins/rbenv-gemset" ]; then
echo "--- :large_green_circle: Rbenv-gemset is available"
else
install_gemset
fi
else
# Nothing is installed, so we install everything
install_rbenv
install_rubybuild
install_gemset
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment