rsite 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/rsite-cli +146 -0
- data/lib/rsite/utils.rb +95 -0
- data/lib/rsite.rb +5 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 678cfef79b7c8babc3596f257459d9fda942e326
|
4
|
+
data.tar.gz: 7af9d0497ad888cb6ed017a796cccb32e8b24d5d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43481c1e6786ef5974fa2af4bf7827d3b0f761bfe75a24992244af32e8fdc2f07744351cecb015cae5e94fe26fc3213180c2d7ca8663c93903cb1d9164abd494
|
7
|
+
data.tar.gz: cedb8abd212b925a22fb072604e56855789af8fbb7569e86ea1983a565d34e96b581b2308d1e44f77976813e18fe250043328a73173c064e83dccd9b2d3024e3
|
data/bin/rsite-cli
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'rsite'
|
5
|
+
require 'ruby-fcp'
|
6
|
+
|
7
|
+
options = { index: 'index.html' }
|
8
|
+
|
9
|
+
opts = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: #{$0} [options]"
|
11
|
+
|
12
|
+
opts.on("-u", "--uri URI",
|
13
|
+
"USK@(requires insert uri, kinda the only reason to use this), SSK@(only use this for full directory uploads)") do |u|
|
14
|
+
options[:uri] = u
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("-o", "--request-uri URI",
|
18
|
+
"USK@(its the only sort that applies)") do |u|
|
19
|
+
options[:ouri] = u
|
20
|
+
end
|
21
|
+
opts.on("-p", "--path path",
|
22
|
+
"if this is directory make sure you specified -d option") do |p|
|
23
|
+
options[:path] = p
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("-i", "--index defaultfile",
|
27
|
+
"default file for directory uploads, I believe it defaults to index.html") do |i|
|
28
|
+
options[:index] = i
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-h", "--server host:port",
|
32
|
+
"Must be a freenet client protocol server") do |s|
|
33
|
+
options[:server] = s
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("-f", "--full",
|
37
|
+
"Full insert, basically use ClientPutDirectory and no redirection from old editions, if this is your first time running rsite, you gotta do this. If your editions seemed fudged up this is also another good fixer for that.") do |s|
|
38
|
+
options[:full] = s
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-s", "--save",
|
42
|
+
"Save your current insert options for directory") do |s|
|
43
|
+
options[:save] = s
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on("-v", "--fix-editions",
|
47
|
+
"fix the edition value") do |s|
|
48
|
+
options[:vr] = s
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on('-e', "--edition value", "specify previous edition values") do |s|
|
52
|
+
options[:e] = s
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
56
|
+
puts opts
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
end.parse!
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
if options.has_key? :server
|
65
|
+
host, port = options[:server].chomp.lstrip.split(':')
|
66
|
+
else
|
67
|
+
host, port = "127.0.0.1", 9481
|
68
|
+
end
|
69
|
+
|
70
|
+
client = FCPClient.new("rsite-#{SecureRandom.hex}", host, port)
|
71
|
+
|
72
|
+
if options.has_key? :path and File.directory? options[:path].chomp.lstrip
|
73
|
+
path = options[:path].chomp.lstrip
|
74
|
+
rsite = RSUtils.new(path)
|
75
|
+
unless options.has_key? :uri
|
76
|
+
if File.exist? File.join(path,'.inserturi')
|
77
|
+
options[:uri] = YAML::load(File.read( File.join path, '.inserturi'))
|
78
|
+
end
|
79
|
+
if File.exist? File.join(path,'.uri')
|
80
|
+
options[:ouri] = YAML::load(File.read( File.join path, '.uri'))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if options.has_key? :save
|
85
|
+
if options.has_key? :uri and options.has_key? :ouri
|
86
|
+
rsite.save_uris(options[:uri].chomp.lstrip, options[:ouri].chomp.lstrip)
|
87
|
+
else
|
88
|
+
puts "I have no idea what you are trying to save..."
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
if options.has_key? :uri
|
94
|
+
uri = options[:uri].chomp.lstrip
|
95
|
+
|
96
|
+
if options.has_key? [:e]
|
97
|
+
puts "Applying previous edition value specified"
|
98
|
+
rsite.version = options[:e].to_i
|
99
|
+
end
|
100
|
+
|
101
|
+
if options[:vr]
|
102
|
+
if options.has_key? :ouri
|
103
|
+
rsite.version = client.usks_latest(options[:ouri].chomp.lstrip)
|
104
|
+
rsite.directory_hash
|
105
|
+
rsite.serialize
|
106
|
+
else
|
107
|
+
puts "You need a request uri either in .uri of this path or specified by option -o"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
if options[:full]
|
112
|
+
response = client.simple_dir_put(uri, path, {"DefaultName" => options[:index]}).pop
|
113
|
+
elsif options.has_key? :ouri
|
114
|
+
filez = rsite.format_file_list(rsite.update,options[:ouri].chomp.lstrip)
|
115
|
+
if filez.size == 0
|
116
|
+
puts "Nothing to do no new files"
|
117
|
+
client.close
|
118
|
+
exit
|
119
|
+
else
|
120
|
+
response = client.put_complex_dir(uri, filez, true, { "ClientToken" => SecureRandom.hex, "Persistence" => 'forever', "DefaultName" => options[:index], "Verbosity" => 1111111}).pop
|
121
|
+
end
|
122
|
+
else
|
123
|
+
puts "Complex directory's require a request URI to determine past editions you could go ahead and perform a full upload with the -f option"
|
124
|
+
client.close
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
|
128
|
+
if response[:head].include? "PutFailed" or response[:head].include? "ProtocolError"
|
129
|
+
puts "Failed somewhere along the way"
|
130
|
+
client.close
|
131
|
+
else
|
132
|
+
rsite.clear_current
|
133
|
+
rsite.version = response["URI"].split('/')[-1].to_i
|
134
|
+
rsite.directory_hash
|
135
|
+
rsite.serialize
|
136
|
+
client.close
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
else
|
141
|
+
puts "I am guessing this is your first run, or your path is incorrect. Well to go ahead and initialize a directory for use do:"
|
142
|
+
puts "$#{$0} -p path_to_site -u insert-uri-of-site -o request-uri-of-site -s -f"
|
143
|
+
puts "or: $#{$0} -p path_to_site -g"
|
144
|
+
puts "-h for more options"
|
145
|
+
exit
|
146
|
+
end
|
data/lib/rsite/utils.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'base64'
|
3
|
+
require 'yaml'
|
4
|
+
require 'find'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
class RSUtils
|
8
|
+
|
9
|
+
attr_reader :current, :path
|
10
|
+
attr_accessor :client, :version
|
11
|
+
|
12
|
+
def initialize(path)
|
13
|
+
@filehashfilepath = File.join(path,'.filehashes')
|
14
|
+
@inserturifilepath = File.join(path,'.inserturi')
|
15
|
+
@ourifilepath = File.join(path,'.uri')
|
16
|
+
@path = path
|
17
|
+
@current ={}
|
18
|
+
@version = 0
|
19
|
+
directory_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def clear_current
|
23
|
+
@current = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def directory_hash
|
27
|
+
Find.find(@path) do |p|
|
28
|
+
Find.prune if File.split(p)[1][0] == '.'
|
29
|
+
unless File.directory? p
|
30
|
+
unless (p.include? @inserturifilepath or p.include? @filehashfilepath) or p.include? @ourifilepath
|
31
|
+
@current[(Digest::SHA256.new << File.read(p)).base64digest] = p
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def files_to_update
|
38
|
+
last = YAML::load(File.read(@filehashfilepath))
|
39
|
+
@version = last[0] if @version == 0
|
40
|
+
@current.keys - last[1].keys
|
41
|
+
end
|
42
|
+
|
43
|
+
def save_uris(uri,ouri)
|
44
|
+
File.open(@inserturifilepath, 'w+') do |file|
|
45
|
+
file.puts YAML::dump uri
|
46
|
+
end
|
47
|
+
File.open(@ourifilepath, 'w+') do |file|
|
48
|
+
file.puts YAML::dump ouri
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def serialize
|
53
|
+
File.open(@filehashfilepath, 'w+') do |file|
|
54
|
+
file.puts YAML::dump [@version, @current]
|
55
|
+
end
|
56
|
+
puts 'hashes stored in .filehashes'
|
57
|
+
end
|
58
|
+
|
59
|
+
def update
|
60
|
+
if File.exist? @filehashfilepath
|
61
|
+
updateables = files_to_update
|
62
|
+
return updateables
|
63
|
+
else
|
64
|
+
puts "Perform full upload to initialize the directory for use"
|
65
|
+
return []
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def format_file_list(updateable,uri)
|
70
|
+
files = []
|
71
|
+
unless updateable.size == 0
|
72
|
+
updateable.each do |u|
|
73
|
+
name = @current[u].sub @path, ''
|
74
|
+
name.sub! '\\' '/' if File::SEPARATOR == '\\'
|
75
|
+
name = name[1..-1] if name[0] == '/'
|
76
|
+
file = {name: name, uploadfrom: 'disk', filename: @current[u]}
|
77
|
+
files.push file
|
78
|
+
end
|
79
|
+
end
|
80
|
+
unless files.size == 0
|
81
|
+
(@current.keys - updateable).each do |u|
|
82
|
+
name = @current[u].sub @path, ''
|
83
|
+
name.sub! '\\' '/' if File::SEPARATOR == '\\'
|
84
|
+
name = name[1..-1] if name[0] == '/'
|
85
|
+
ssk = uri.split '@'
|
86
|
+
ssk = 'SSK@'+(ssk[1].split('/')[0...-1].join('/'))+"-#{@version}/"+name
|
87
|
+
file = {name: name, uploadfrom: 'redirect', targeturi: ssk}
|
88
|
+
files.push file
|
89
|
+
end
|
90
|
+
end
|
91
|
+
files
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
data/lib/rsite.rb
ADDED
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hikiko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A blog generating and puting utility for freenet
|
14
|
+
email: kerben@i2pmail.org
|
15
|
+
executables:
|
16
|
+
- rsite-cli
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/rsite-cli
|
21
|
+
- lib/rsite.rb
|
22
|
+
- lib/rsite/utils.rb
|
23
|
+
homepage: https://github.com/kerben/rsite
|
24
|
+
licenses:
|
25
|
+
- Unlicense
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.2.2
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: RSite
|
47
|
+
test_files: []
|