Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created June 26, 2009 13:15
Show Gist options
  • Save troelskn/136461 to your computer and use it in GitHub Desktop.
Save troelskn/136461 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def parse_missing_required(input)
matches = input.match(/Missing these required gems:([\s\S]*)You're running:/)
matches[1].strip.split("\n").map do |line|
m = line.match(/^\s*(\S+)\s+(\S+\s+[0-9.]+)/)
p line if m.nil?
{:name => m[1], :version => m[2]}
end
end
def parse_missing_rake(input)
matches = input.scan(/\s+-\s+\[ \]\s+(\S+)\s+(\S+\s+[0-9.]+)/)
matches.map do |match|
{:name => match[0], :version => match[1]}
end
end
def get_requirements
puts ">>> rake gems"
result = `rake gems 2>&1`
if result =~ /Missing these required gems:/
parse_missing_required result
else
parse_missing_rake result
end
end
$installed_gems = []
def install_gem!(gemspec)
raise "Already installed #{gemspec[:name]} once. Make sure that GEM_HOME and GEM_PATH are set correctly." $installed_gems.include? gemspec[:name]
$installed_gems << gemspec[:name]
puts ">>> gem install #{gemspec[:name]} --version '#{gemspec[:version]}'"
puts `gem install #{gemspec[:name]} --version '#{gemspec[:version]}'`
end
def install_all!
puts "[Checking for missing requirements]"
requirements = get_requirements
if requirements.any?
puts "[Installing missing requirements]"
if `whoami`.strip != 'root'
puts "Must be run as root"
exit -1
end
requirements.each do |gemspec|
install_gem! gemspec
end
install_all!
end
end
install_all!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment