This is a script to manage a team's set of ruby gems by pulling from a MediaWiki article that contains YAML, of the following form:
gems: {fastercsv: '1.2.0', soap4r: '>1.5.5' }
require 'net/http'
require 'yaml'
# install a given gem and version, may also give a URL
def gem_install(gem, version, url=nil)
# only install if not already installed
listed = `gem list #{gem} --no-details --local`
unless listed =~ %r"^#{gem} "
puts "== Installing #{gem}"
puts `sudo gem install #{gem} -f -y -v '#{version}'`
end
end
# First try and find a local or given gems.yml file
gems_config_file = ARGV[0].nil? ? 'gems.yml' : ARGV[0]
gems = nil
begin
gems = YAML::load_file( gems_config_file )
rescue Errno::ENOENT => e
puts "Could not find file... looking remotely in the wiki Gems.yml"
url = URI.parse('http://wikiserver/')
res = Net::HTTP.start(url.host, url.port) do |http|
http.get("/index.php?action=raw&title=Gems.yml")
end
data = res.body
gems = YAML::load(data)
end
gems['gems'].each { |gem| gem_install(gem[0], gem[1]) }