# File lib/thor/runner.rb, line 19
  def install(name)
    initialize_thorfiles

    base = name
    package = :file

    begin
      if File.directory?(File.expand_path(name))
        base, package = File.join(name, "main.thor"), :directory
        contents = open(base).read
      else
        contents = open(name).read
      end
    rescue OpenURI::HTTPError
      raise Error, "Error opening URI `#{name}'"
    rescue Errno::ENOENT
      raise Error, "Error opening file `#{name}'"
    end
    
    is_uri = File.exist?(name) ? false : true
    
    puts "Your Thorfile contains: "
    puts contents
    print "Do you wish to continue [y/N]? "
    response = Readline.readline
    
    return false unless response =~ /^\s*y/i
    
    constants = Thor::Util.constants_in_contents(contents, base)
    
    as = options["as"] || begin
      first_line = contents.split("\n")[0]
      (match = first_line.match(/\s*#\s*module:\s*([^\n]*)/)) ? match[1].strip : nil
    end
        
    if !as
      print "Please specify a name for #{name} in the system repository [#{name}]: "
      as = Readline.readline
      as = name if as.empty?
    end
    
    FileUtils.mkdir_p thor_root
    
    yaml_file = File.join(thor_root, "thor.yml")
    FileUtils.touch(yaml_file)
    yaml = thor_yaml
    
    location = (options[:relative] || is_uri) ? name : File.expand_path(name)
    yaml[as] = {:filename => Digest::MD5.hexdigest(name + as), :location => location, :constants => constants}
    
    save_yaml(yaml)
    
    puts "Storing thor file in your system repository"
    
    destination = File.join(thor_root, yaml[as][:filename])
    
    if package == :file
      File.open(destination, "w") {|f| f.puts contents }
    else
      FileUtils.cp_r(name, destination)
    end
    
    yaml[as][:filename] # Indicate sucess
  end