#!/usr/bin/env ruby require 'json' require 'uri' require 'net/http' require File.dirname(__FILE__) + '/../lib/nuri/targz' module Nuri module Util TarGzip = Object.new.extend(Util::Tar) def self.install_modules(address, port, modules, protocol="http", open_timeout=2, read_timeout=10) data = {} modules.each do |module_name| raise Exception, "Module #{module_name} is not exist!" if not ::File.directory?(module_name) data[module_name] = TarGzip.targzip(module_name, module_name).read end begin url = "#{protocol}://#{address}:#{port}/modules" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = open_timeout http.read_timeout = read_timeout request = Net::HTTP::Put.new(uri.request_uri) request.set_form_data(data) response = http.request(request) (response.code == '200') rescue Exception => e $stderr.puts "Cannot install module with URL: #{url}" $stderr.puts e false end end end end if $0 == __FILE__ if ARGV.length < 2 puts "Usage: #{$0.split('/').last}
:[port]