helm/rake/pkg/rbenv.rake

66 lines
1.6 KiB
Ruby
Raw Normal View History

2014-08-30 23:50:03 -07:00
desc "Install/update rbenv & all rubies"
2014-04-13 08:46:20 -07:00
task :rbenv => 'rbenv:update'
2014-04-11 00:31:44 -07:00
RBENV_ROOT = File.expand_path("~/.rbenv")
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?
echo "Installing rbenv"
sh_safe "curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
github "sstephenson/rbenv", RBENV_ROOT
mkdir_p "#{rbenv_root}/plugins"
[ "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"
].each { |pkg| github pkg, "#{RBENV_ROOT}/plugins/" }
2014-09-01 08:31:11 -07:00
sh_safe "eval $(~/.rbenv/bin/rbenv init -)"
2014-04-11 00:31:44 -07:00
end
2014-08-30 23:50:03 -07:00
end
task :update => "rbenv:install" do
echo "Updating rbenv & plugins"
2014-09-01 08:31:11 -07:00
sh_safe "rbenv update"
rbenv_versions do |version|
echo "Updating ruby #{version}"
2014-04-11 00:31:44 -07:00
2014-08-30 23:50:03 -07:00
cmd = "gem"
cmd = "sudo #{cmd}" if version == "system"
2014-08-30 23:50:03 -07:00
sh_safe "RBENV_VERSION=#{version} #{cmd} #{GEM_BIN} update"
sh_safe "RBENV_VERSION=#{version} #{cmd} #{GEM_BIN} clean"
2014-04-13 08:46:20 -07:00
end
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?
desc "Remove rbenv & installed rubies"
task :remove do
2014-08-30 23:50:03 -07: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
####
def rbenv_installed?
system("which rbenv")
end
def rbenv_versions
`ls -1 #{RBENV_ROOT}/versions`.split("\n") if Dir.exists? "#{RBENV_ROOT}/versions"
2014-08-30 23:50:03 -07:00
end
2014-04-11 00:31:44 -07:00
def rbenv_plugins
Dir.glob("#{RBENV_ROOT}/plugins/*")
2014-04-11 00:31:44 -07:00
end