class RailsPwnerer::Scaffolds::RubyGems
Public Class Methods
go()
click to toggle source
standalone runner
# File lib/rails_pwnerer/scaffolds/rubygems.rb 84 def self.go 85 self.new.run 86 end
pre_go()
click to toggle source
called before packages get installed
# File lib/rails_pwnerer/scaffolds/rubygems.rb 79 def self.pre_go 80 self.new.preflight 81 end
Public Instance Methods
configure_rubygems()
click to toggle source
sets up good defaults for Rubygems
# File lib/rails_pwnerer/scaffolds/rubygems.rb 49 def configure_rubygems 50 File.open('/etc/gemrc', 'w') do |f| 51 f.write "gem: --no-force --no-rdoc --no-ri --no-user-install --wrappers\n" 52 end 53 end
google_lucky_uri(query)
click to toggle source
retrieves the URI for a Google “I’m Feeling Lucky” search
# File lib/rails_pwnerer/scaffolds/rubygems.rb 8 def google_lucky_uri(query) 9 uri = URI.parse "http://www.google.com/search?q=#{URI.escape query}&btnI=Lucky" 10 response = Net::HTTP.start(uri.host, uri.port) { |http| http.get "#{uri.path}?#{uri.query}" } 11 response.header['location'] 12 end
install_rubygems()
click to toggle source
installs Rubygems on the system
# File lib/rails_pwnerer/scaffolds/rubygems.rb 25 def install_rubygems 26 with_temp_dir(:root => true) do 27 tgz_uri = rubyforge_download_uri('rubygems', 'rubygems', 'tgz') 28 file_name = File.basename tgz_uri.path 29 loop do 30 request_path = tgz_uri.query.to_s.empty? ? tgz_uri.path : "#{tgz_uri.path}?#{tgz_uri.query}" 31 response = Net::HTTP.start(tgz_uri.host, tgz_uri.port) { |http| http.get request_path } 32 if response.kind_of? Net::HTTPRedirection 33 tgz_uri = URI.parse response.header['location'] 34 next 35 end 36 File.open(file_name, 'wb') { |f| f.write response.body } 37 break 38 end 39 40 system "tar -xzf #{file_name}" 41 File.unlink file_name 42 Dir.chdir(Dir.glob('*').first) do 43 system "ruby setup.rb" 44 end 45 end 46 end
preflight()
click to toggle source
# File lib/rails_pwnerer/scaffolds/rubygems.rb 72 def preflight 73 # save old lib path, in case we need to wipe it 74 # we need to do this because setting up packages might wipe Ubuntu's gems 75 @@old_gems = path_to_gemdir 76 end
rubyforge_download_uri(project, gem_name = project, extension = ".gem")
click to toggle source
retrieves the download URI for a RubyForge project
# File lib/rails_pwnerer/scaffolds/rubygems.rb 15 def rubyforge_download_uri(project, gem_name = project, extension = ".gem") 16 frs_uri = URI.parse google_lucky_uri("#{project} download page") 17 frs_contents = Net::HTTP.get frs_uri 18 frs_links = frs_contents.scan(/\<a.+href=\"(.+?)\"\>/).flatten. 19 select { |link| link.index('.tgz') && link.index("#{gem_name}-") } 20 latest_link = frs_links.sort_by { |n| n.match(/#{gem_name}-(.*)\.#{extension}/)[1] }.last 21 return frs_uri.merge(latest_link) 22 end
run()
click to toggle source
# File lib/rails_pwnerer/scaffolds/rubygems.rb 55 def run 56 # get the old path set by pre-go 57 old_gems = @@old_gems 58 59 # remove the Debian gems package and install from source 60 remove_packages %w(rubygems) 61 install_rubygems 62 63 # configure rubygems so it doesn't waste time 64 configure_rubygems 65 66 # remove the gems that are trailing behind 67 new_gems = path_to_gemdir 68 return if new_gems == old_gems # don't wipe the new dir by mistake 69 FileUtils.rm_r old_gems 70 end