Skip to content

Instantly share code, notes, and snippets.

@lucasmartins
Last active August 29, 2015 14:01
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 lucasmartins/193e42dffd59437c67fe to your computer and use it in GitHub Desktop.
Save lucasmartins/193e42dffd59437c67fe to your computer and use it in GitHub Desktop.
Ruby recursive installer (for rbenv users)
#!/usr/bin/env ruby
# Ruby Recursive Build
# This script is intended for environment first setups automation, its homebrewed and tested only on my env.
# Use it at your own risk.
# I strongly recommend you to read the code through, and change it to fit your needs.
# It will look for your .ruby-version files and install all of 'em
# run this inside your Workspace folder
# Download it into your Workspace folder
# chmod +x ruby-recursive-building.rb
# ./ruby-recursive-building.rb
# wait & pray
EXTRAS=['bundler']
def detect_versions
versions = []
version_files = `find .|grep .ruby-version`.split("\n")
version_files.each do |version_file|
versions.push File.read(version_file).chop
end
versions.uniq
end
def will_install
detect_versions-installed_versions
end
def install_versions(versions)
versions.each {|v| install_version(v)}
end
def install_version(version)
puts "Installing #{version}..."
`rbenv install #{version}`
if $?.success?
install_extras(version)
else
raise 'something went wrong!'
end
end
def install_extras(version)
puts "Installing EXTRAS for #{version}..."
`rbenv shell #{version} && gem install #{EXTRAS.join(' ')}`
end
def installed_versions
versions = []
detected_versions = Dir.glob("#{ENV['HOME']}/.rbenv/versions/**")
detected_versions.each {|v| versions.push v.split('/').last }
versions.uniq
end
def run!
versions = will_install
puts 'Installing these versions:'
versions.each {|v| puts "\r#{v}"}
install_versions(versions)
end
run!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment