helm/rake/pkg/rbenv.rake

104 lines
2.5 KiB
Ruby
Raw Normal View History

2014-12-13 16:33:21 -08:00
RBENV_ROOT = File.expand_path('~/.rbenv')
2014-09-05 14:03:26 -07:00
def rbenv_installed?
2014-12-13 16:33:21 -08:00
Dir.exist?(RBENV_ROOT)
2014-09-05 14:03:26 -07:00
end
def rbenv_versions
2014-12-13 16:33:21 -08:00
return [] unless Dir.exist? "#{RBENV_ROOT}/versions"
`ls -1 #{RBENV_ROOT}/versions`.split("\n")
2014-09-05 14:03:26 -07:00
end
def rbenv_plugins
Dir.glob("#{RBENV_ROOT}/plugins/*")
end
def rbenv_set_default_gems(*gems)
default_gems_file = "#{RBENV_ROOT}/default-gems"
File.write(default_gems_file, gems.join("\n"))
end
def rbenv_version_installed?(version)
rbenv_versions.include?(version)
2014-09-05 14:03:26 -07:00
end
###
2014-12-13 16:33:21 -08:00
desc 'Install/update rbenv & all rubies'
task rbenv: 'rbenv:update'
2014-04-11 00:31:44 -07:00
namespace :rbenv do
2014-08-30 23:50:03 -07:00
task :install do
unless rbenv_installed?
2014-12-13 16:33:21 -08:00
echo 'Installing rbenv'
github 'sstephenson/rbenv', RBENV_ROOT
2014-09-05 14:03:26 -07:00
mkdir_p "#{RBENV_ROOT}/plugins"
2014-12-13 16:33:21 -08:00
['sstephenson/rbenv-vars',
'sstephenson/ruby-build',
'sstephenson/rbenv-default-gems',
'sstephenson/rbenv-gem-rehash',
'fesplugas/rbenv-installer',
'fesplugas/rbenv-bootstrap',
'rkh/rbenv-update',
'rkh/rbenv-whatis',
'rkh/rbenv-use'
2014-09-05 14:03:26 -07:00
].each do |pkg|
echo "Installing #{pkg}", 2
2014-12-13 16:33:21 -08:00
github pkg, "#{RBENV_ROOT}/plugins/#{pkg.split('/')[1]}"
2014-09-05 14:03:26 -07:00
end
2014-12-13 16:33:21 -08:00
echo 'Initializing rbenv', 2
2014-09-05 14:03:26 -07:00
sh_safe "eval \"$(#{RBENV_ROOT}/bin/rbenv init -)\""
end
2014-09-05 14:03:26 -07:00
# Set default gems
2014-10-09 15:31:53 -07:00
rbenv_set_default_gems(
'bundler',
'rspec',
2014-12-13 16:33:21 -08:00
'doing',
2014-10-09 15:31:53 -07:00
'pry',
'pry-doc',
2014-12-13 16:33:21 -08:00
'pry-byebug',
'pry-rescue',
'pry-stack_explorer',
'ripper-tags',
'gem-ripper-tags'
2014-10-09 15:31:53 -07:00
)
2014-09-01 08:31:11 -07:00
# Install global ruby + gems
2015-05-13 16:23:52 -07:00
ruby_version = '2.1.6'
unless rbenv_version_installed? ruby_version
2014-09-05 14:03:26 -07:00
echo "Setting up default ruby (#{ruby_version})", 2
sh_safe "rbenv install #{ruby_version}"
sh_safe "rbenv global #{ruby_version}"
sh_safe "RBENV_VERSION=#{ruby_version} #{RBENV_ROOT}/shims/gem install -f jekyll sass mercenary colorize pry pry-doc pry-byebug rake"
2014-04-11 00:31:44 -07:00
end
2014-08-30 23:50:03 -07:00
end
2014-12-13 16:33:21 -08:00
task update: 'rbenv:install' do
echo 'Updating rbenv & plugins'
sh_safe 'rbenv update'
2014-09-05 14:03:26 -07:00
rbenv_versions.each do |version|
echo "Updating ruby #{version}"
2014-04-11 00:31:44 -07:00
2014-09-05 14:03:26 -07:00
cmd = "#{RBENV_ROOT}/shims/gem"
2014-12-13 16:33:21 -08:00
cmd = "sudo #{cmd}" if version == 'system'
2014-08-30 23:50:03 -07:00
2014-09-05 14:03:26 -07:00
sh_safe "RBENV_VERSION=#{version} #{cmd} update --system -f"
sh_safe "RBENV_VERSION=#{version} #{cmd} update -f"
sh_safe "RBENV_VERSION=#{version} #{cmd} clean"
2014-04-13 08:46:20 -07:00
end
2014-12-13 16:33:21 -08:00
sh_safe 'rbenv rehash'
2014-08-30 23:50:03 -07:00
end
2014-04-11 00:31:44 -07:00
2014-09-01 08:31:11 -07:00
if rbenv_installed?
task :remove do
2014-12-13 16:33:21 -08:00
echo 'Deleting rbenv'
sh_safe "rm -rf #{RBENV_ROOT}"
2014-04-11 00:31:44 -07:00
end
2014-08-30 23:50:03 -07:00
end
end