Skip to content

Instantly share code, notes, and snippets.

@nakajijapan
Last active December 16, 2015 03:39
Show Gist options
  • Save nakajijapan/5371410 to your computer and use it in GitHub Desktop.
Save nakajijapan/5371410 to your computer and use it in GitHub Desktop.
ruby-buildでバージョン指定してコンパイルしてtarで固める。(puppetで撒く用の処理)
#!/usr/bin/env ruby
require 'colorize'
def exec_cmd(str)
puts "[CMD] #{str}".colorize(:green)
result = ''
result = system(str)
puts "[OUTPUT] #{result}".colorize(:blue)
end
# ruby compile
Dir.chdir("/usr/local/rbenv/plugins/ruby-build")
exec_cmd 'pwd'
exec_cmd 'git pull origin master'
rbenv_install = '/usr/local/rbenv/plugins/ruby-build/bin/rbenv-install'
exec_cmd rbenv_install + ' -l'
p 'which ruby version?'
while line = STDIN.gets
line.strip!
if line == 'h'
exec_cmd rbenv_install
else
version = line
puts "input: #{version}"
break
end
end
raise "no version..." if version == ''
exec_cmd rbenv_install + ' ' + version
exec_cmd "rbenv local #{version}"
exec_cmd "rbenv global #{version}"
exec_cmd 'gem install bundler'
Dir.chdir("/usr/local/rbenv/versions")
exec_cmd "tar czvf rbenv_#{version}.tgz #{version}/"
exec_cmd("mkdir /etc/#{version}")
exec_cmd("mv rbenv_#{version}.tgz /etc/#{version}/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment