summaryrefslogtreecommitdiffstats
path: root/up.rb
blob: 83492cd1e6bf3fb0ea4ffc2a0c9cbd8328570b6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!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