#!/usr/bin/env ruby ## # gem_server_dumb can be used to serve gems for consumption by `gem --remote-install`. # Unlike gem_server, which serves from an installed gem directory, # gem_server_dumb serves from a directory like that produced by gem_mirror. # The specified directory should contain a file called "yaml" (the source index) and a # directory called "gems" containing the gems specified in the yaml file. # # gem_server_dumb starts an HTTP server on the given port, and serves the yaml file and # the gems. # # Usage: gem_server [-p portnum] -d gem_path # port_num:: The TCP port the HTTP server will bind to (defaults to 8808) # gem_path:: # Root gem directory containing "yaml" file and "gems" subdirectory. # It defaults to your installed gem directory, but this is wrong, since this # is # subdirectories. if __FILE__ == $0 require 'webrick' require 'optparse' Socket.do_not_reverse_lookup=true options = {} ARGV.options do |opts| opts.on_tail("--help", "show this message") {puts opts; exit} opts.on('-pPORT','--port=PORT', "Specify the port to listen on") { |options[:port]| } opts.on('-dGEMDIR','--dir=GEMDIR', "Specify the directory from which to serve Gems") { |options[:gemdir]| } opts.parse! end raise "you must specify a gem directory with -d" unless options[:gemdir] s = WEBrick::HTTPServer.new(:Port => options[:port] || 8808) # XXX TODO: This works if you mount it from a gem_mirrored directory, but not actually for Gem.dir, # so this is a stupid default! s.mount( "/", WEBrick::HTTPServlet::FileHandler, options[:gemdir] || Gem.dir, true) trap("INT") { s.shutdown; exit! } s.start end