up/up.rb

29 lines
887 B
Ruby
Executable File

#!env ruby
require 'rubygems'
require 'digest/md5'
require 'net/scp'
require 'open-uri'
# set up all the constants here, in case we ever need to change them
UPLOAD_BASE_PATH = "/home/arachnist/public_html/c/"
LINK_BASE_PATH = "https://arachnist.is-a.cat/c/"
HOST = "i.am-a.cat"
USERNAME = "arachnist"
ARGV.each do |path|
Process.fork {
# add the dot here, so that if we get a file without dot, we don't have
# to conditionally add the dot later on
ext = "." + path.sub(/.*[.]([^.]*)/, '\1') if path.match(/[^.]+[.][^.]+/)
# make sure ext isn't nil
ext = ext.nil? ? "" : ext
content = open(path).read
md5 = Digest::MD5.hexdigest(content)
Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext)
printf("%s\t=> %s%s%s\n", path, LINK_BASE_PATH, md5, ext)
}
end
Process.waitall