#!/usr/bin/env ruby # Filename: grml-paste # Purpose: paste files to the online grml paste bot # Authors: grml-team (grml.org), (c) 2007 Nico Golde # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2 ########################################################################## require 'uri' require 'net/http' url = URI.parse('http://paste.grml.org/paste') def usage $stderr.puts "usage: #{$0} [-n nick] [-s summary] [-f source] [-h|--help]\n" $stderr.puts "\t -n \tset your nickname (defaults to Anonymuos)" $stderr.puts "\t -s \tspecify a summary of your paste (defaults to none)" $stderr.puts "\t -f \tsets the file to read from, you don't need this for reading from stdin" $stderr.puts "\t --help\t\tprint this help" Kernel.exit(1) end file = nil summary = "none" nick = "Anonymous" channel = "#grml" text = "" ARGV.each_index do |i| if ARGV[i] == '-h' or ARGV[i] == '--help' then usage elsif ARGV[i] == '-n' and ARGV[i+1] != nil then nick = ARGV[i+1] elsif ARGV[i] == '-s' and ARGV[i+1] != nil then summary = ARGV[i+1] elsif ARGV[i] == '-f' and ARGV[i+1] != nil then file = ARGV[i+1] end end if file == nil or file == "-" f = STDIN else begin f = File.open(file) rescue $stderr.puts "Error: couldn't open file: #{file}" Kernel.exit(1) end end f.each_line do |line| text << line end begin res = Net::HTTP.post_form(url,{'Paste it' => 'Paste it', 'paste' => text, 'channel' => channel, 'summary' => summary, 'nick' => nick}) rescue $stderr.puts "Unable to post HTTP request" Kernel.exit(1) end results = res.body.scan(/ 0 then result = results[0].sub(/