frachtraum 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +34 -0
- data/Gemfile +1 -1
- data/bin/frachtraum +1 -194
- data/frachtraum.conf.example +2 -2
- data/frachtraum.gemspec +1 -0
- data/lib/frachtraum/bsd.rb +17 -14
- data/lib/frachtraum/cli.rb +210 -0
- data/lib/frachtraum/config.rb +2 -2
- data/lib/frachtraum/linux.rb +3 -1
- data/lib/frachtraum/osx.rb +3 -1
- data/lib/frachtraum.rb +62 -38
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzA0MGRkZTg3NzhjZGE3NzE0ODI1NmFiZTgxM2JhMWM2ZjM3YWE0Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDM4OGU4ZjQyMTBhODA1YzgxOGI2ZDY2MWI4Y2NkZjViZTdhZTQ2ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWFlYTE2NTRjNmE1MzUzMmEyMzFiNzZkZmY5YzkyZTc3ZDI5ODRiMDQzNjFm
|
10
|
+
ODNiZWU3NGVkYmFmMzc5ZmE3MjNlYjhhYmQzMjA5ZWQ3Mjg0MDU0MTc3ZTVk
|
11
|
+
NzgwMjNmMzY1ODU5Y2ZjOTJiMGRiNzhkMWIzMjFjNzllYzRiZDY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTNhNmI5M2Y1MDZiNmY5ODUyOWIwMGU1ZDkxNjE5ZWI5OGM3ZmUwMWQzYjJi
|
14
|
+
ZmYzODRlZWFkYTE4ZWYxNjE5NzJkNWQ5MmQ1ZTUzNWYwMTAwNDAzMmY4ZDNh
|
15
|
+
ZTMxZmMyZDFmYmViMzFhYTQ0OTY2NDI2NWYzOTA5MTNhNjVhM2Y=
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
CHANGED
data/bin/frachtraum
CHANGED
@@ -2,198 +2,5 @@
|
|
2
2
|
# -*- encoding : utf-8 -*-
|
3
3
|
|
4
4
|
require 'frachtraum'
|
5
|
-
require 'thor'
|
6
|
-
require 'highline/import'
|
7
|
-
require 'rainbow'
|
8
5
|
|
9
|
-
|
10
|
-
HighLine.ask(prompt) { |q|
|
11
|
-
q.echo = false
|
12
|
-
# q.echo = "*"
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
class FrachtraumCLI < Thor
|
17
|
-
|
18
|
-
desc "attach [DEPOT]", "decrypt and mount depot(s)"
|
19
|
-
long_desc <<-LONGDESC
|
20
|
-
`frachtraum attach` will prompt you for a password.
|
21
|
-
|
22
|
-
The password is used to decrypt all depots specified
|
23
|
-
in #{Frachtraum::CONFIG_FILE}
|
24
|
-
|
25
|
-
You can optionally specify a single depot. In this case
|
26
|
-
only this depot will be decrypted and mounted.
|
27
|
-
LONGDESC
|
28
|
-
def attach(depot=nil)
|
29
|
-
|
30
|
-
password = prompt_password
|
31
|
-
|
32
|
-
Frachtraum.attach password, depot
|
33
|
-
end
|
34
|
-
|
35
|
-
# --------------
|
36
|
-
|
37
|
-
desc "capacity [OPTION]", "calculate storage capacity"
|
38
|
-
long_desc <<-LONGDESC
|
39
|
-
`frachtraum capacity` will output capacity...
|
40
|
-
|
41
|
-
lorem ipsum
|
42
|
-
LONGDESC
|
43
|
-
def capacity(option=nil)
|
44
|
-
c = Frachtraum.capacity
|
45
|
-
|
46
|
-
case option
|
47
|
-
when "smb", "samba"
|
48
|
-
puts "#{c[:total]/1000} #{c[:avail]/1000}"
|
49
|
-
else
|
50
|
-
puts ""
|
51
|
-
puts "Capacity:"
|
52
|
-
puts " Available: #{Frachtraum.pretty_SI_bytes(c[:avail])}"
|
53
|
-
puts " Used: #{Frachtraum.pretty_SI_bytes(c[:used])}"
|
54
|
-
puts " Total: #{Frachtraum.pretty_SI_bytes(c[:total])}"
|
55
|
-
puts ""
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# --------------
|
60
|
-
|
61
|
-
desc "list", "list depots and/or timemachine targets"
|
62
|
-
long_desc <<-LONGDESC
|
63
|
-
lorem ipsum
|
64
|
-
LONGDESC
|
65
|
-
option :simple, :type => :boolean
|
66
|
-
def list(subset=nil)
|
67
|
-
|
68
|
-
list_width = 60 # character length of list
|
69
|
-
|
70
|
-
if subset == "depot" || subset == "depots" || subset.nil?
|
71
|
-
if options[:simple]
|
72
|
-
Frachtraum::DEPOTS.each{ |depot| puts depot }
|
73
|
-
else
|
74
|
-
puts "" # empty line
|
75
|
-
puts "Depots:"
|
76
|
-
puts "" # empty line
|
77
|
-
Frachtraum::DEPOTS.each{ |dataset|
|
78
|
-
status =
|
79
|
-
if Frachtraum.zfs_dataset_exists?(dataset)
|
80
|
-
Rainbow("attached").green
|
81
|
-
else
|
82
|
-
Rainbow("UNAVAILABLE").red
|
83
|
-
end
|
84
|
-
status = "[#{status}]".rjust(list_width-dataset.length)
|
85
|
-
puts " #{dataset}#{status}"
|
86
|
-
}
|
87
|
-
puts "" # empty line
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
if subset == "timemachine" || subset == "tm" || subset.nil?
|
92
|
-
if options[:simple]
|
93
|
-
Frachtraum::TIMEMACHINE_TARGETS.each{ |depot| puts depot }
|
94
|
-
else
|
95
|
-
puts "" unless subset.nil? # empty line
|
96
|
-
puts "Timemachine targets:"
|
97
|
-
puts "" # empty line
|
98
|
-
Frachtraum::TIMEMACHINE_TARGETS.each{ |dataset|
|
99
|
-
status =
|
100
|
-
if Frachtraum.zfs_dataset_exists?(dataset)
|
101
|
-
Rainbow("attached").green
|
102
|
-
else
|
103
|
-
Rainbow("UNAVAILABLE").red
|
104
|
-
end
|
105
|
-
status = "[#{status}]".rjust(list_width-dataset.length)
|
106
|
-
puts " #{dataset}#{status}"
|
107
|
-
}
|
108
|
-
puts "" # empty line
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# --------------
|
114
|
-
|
115
|
-
desc "report", "lorem ipsum"
|
116
|
-
long_desc <<-LONGDESC
|
117
|
-
lorem ipsum
|
118
|
-
LONGDESC
|
119
|
-
def report()
|
120
|
-
# TODO
|
121
|
-
end
|
122
|
-
|
123
|
-
# --------------
|
124
|
-
|
125
|
-
desc "setupdisk", "setup a device as a new depot"
|
126
|
-
long_desc <<-LONGDESC
|
127
|
-
`frachtraum setup dev label` will setup...
|
128
|
-
|
129
|
-
lorem ispum
|
130
|
-
LONGDESC
|
131
|
-
options :compression => :string, :encryption => :string, :keylength => :integer, :mountpoint => :string
|
132
|
-
def setupdisk(dev,label)
|
133
|
-
|
134
|
-
compression = options[:compression] ? options[:compression] : Frachtraum::COMPRESSION
|
135
|
-
encryption = options[:encryption] ? options[:encryption] : Frachtraum::ENCRYPTION
|
136
|
-
keylength = options[:keylength] ? options[:keylength] : Frachtraum::KEYLENGTH
|
137
|
-
mountpoint = options[:mountpoint] ? options[:mountpoint] : Frachtraum::MOUNTPOINT
|
138
|
-
|
139
|
-
password1 = prompt_password("enter encryption password: ")
|
140
|
-
password2 = prompt_password("enter password again: ")
|
141
|
-
if password1.match(password2)
|
142
|
-
password = password1
|
143
|
-
else
|
144
|
-
abort "passwords not equal!"
|
145
|
-
end
|
146
|
-
|
147
|
-
puts ""
|
148
|
-
puts "Device: #{dev}"
|
149
|
-
puts "Label: #{label}"
|
150
|
-
puts "Compression: #{compression}"
|
151
|
-
puts "Encryption: #{encryption}"
|
152
|
-
puts "Keylength: #{keylength}"
|
153
|
-
puts "Mountpoint: #{mountpoint}"
|
154
|
-
puts ""
|
155
|
-
puts "ATTENTION! This is a destructive action. All data on the device will be"
|
156
|
-
puts "wiped. If you forget you password, you will not be able to access any"
|
157
|
-
puts "containing data any more."
|
158
|
-
puts ""
|
159
|
-
|
160
|
-
answer = HighLine.ask("Are you sure you want to continue? (type 'yes'): ") { |q| q.echo = true }
|
161
|
-
|
162
|
-
if answer.downcase.match("yes")
|
163
|
-
Frachtraum.setupdisk dev, label, password, compression, encryption, keylength, mountpoint
|
164
|
-
else
|
165
|
-
abort "ABORT -- device will not pe processed!"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# --------------
|
170
|
-
|
171
|
-
desc "sweep", "sweep the depots!"
|
172
|
-
long_desc <<-LONGDESC
|
173
|
-
`frachtraum sweep` will ...
|
174
|
-
|
175
|
-
lorem ipsum
|
176
|
-
LONGDESC
|
177
|
-
def sweep()
|
178
|
-
# TODO
|
179
|
-
Frachtraum::DEPOTS.each do |depot|
|
180
|
-
|
181
|
-
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# --------------
|
186
|
-
|
187
|
-
desc "test", "test system for compatibility"
|
188
|
-
long_desc <<-LONGDESC
|
189
|
-
`frachtraum test` will test...
|
190
|
-
|
191
|
-
lorem ipsum
|
192
|
-
LONGDESC
|
193
|
-
def test()
|
194
|
-
Frachtraum.run_system_test
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
FrachtraumCLI.start(ARGV)
|
6
|
+
Frachtraum::CLI.start(ARGV)
|
data/frachtraum.conf.example
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# Copy it to ~/.frachtraum.conf and edit it to your own needs
|
4
4
|
#
|
5
5
|
compression = lz4
|
6
|
-
|
6
|
+
volumes = volume1,volume2,volume3
|
7
7
|
encryption = AES-XTS
|
8
8
|
keylength = 4096
|
9
9
|
mountpoint = /frachtraum
|
10
|
-
tmtargets =
|
10
|
+
tmtargets = volume1/TimeMachine/user1,volume1/TimeMachine/user2
|
data/frachtraum.gemspec
CHANGED
data/lib/frachtraum/bsd.rb
CHANGED
@@ -2,29 +2,28 @@ module Frachtraum
|
|
2
2
|
|
3
3
|
REQUIRED_TOOLS_BSD = ['dd','grep','gpart','glabel','geli','zfs','zpool']
|
4
4
|
|
5
|
-
|
6
|
-
def attach_bsd(password, depot=nil)
|
5
|
+
def attach_bsd(password, volume=nil)
|
7
6
|
|
8
7
|
# if we provided a specific depot, run procedure only on that one
|
9
|
-
|
8
|
+
volumes = volume.nil? ? Frachtraum::VOLUMES : [ volume ]
|
10
9
|
|
11
10
|
# first of all, decrypt and mount all depots
|
12
|
-
|
13
|
-
print "decrypting /dev/label/#{
|
11
|
+
volumes.each do |v|
|
12
|
+
print "decrypting /dev/label/#{v}...".ljust(35,".") # TODO: the length should be dynamically calculated, for tm targets as well
|
14
13
|
|
15
|
-
output = %x( echo #{password} | geli attach -d -j - /dev/label/#{
|
14
|
+
output = %x( echo #{password} | geli attach -d -j - /dev/label/#{v} 2>&1 )
|
16
15
|
if $?.success?
|
17
|
-
output = %x( zfs mount #{
|
18
|
-
if $?.success? then puts "DONE"
|
19
|
-
else puts "FAILED! --> #{output}" end
|
16
|
+
output = %x( zfs mount #{v} 2>&1 )
|
17
|
+
if $?.success? then puts Rainbow("DONE").green
|
18
|
+
else puts Rainbow("FAILED!").red + " --> #{output}" end
|
20
19
|
else
|
21
|
-
puts "FAILED! --> #{output}"
|
20
|
+
puts Rainbow("FAILED!").red + " --> #{output}"
|
22
21
|
end
|
23
22
|
end # each
|
24
23
|
|
25
24
|
# mount timemachine targets as well
|
26
|
-
TIMEMACHINE_TARGETS.each do |tmtarget|
|
27
|
-
print "mounting timemachine target #{tmtarget}..."
|
25
|
+
Frachtraum::TIMEMACHINE_TARGETS.each do |tmtarget|
|
26
|
+
print "mounting timemachine target #{tmtarget}...".ljust(35,".") # TODO: the length should be dynamically calculated, for tm targets as well
|
28
27
|
|
29
28
|
output = %x( zfs mount #{tmtarget} 2>&1 )
|
30
29
|
if $?.success? then puts "DONE"
|
@@ -34,8 +33,8 @@ module Frachtraum
|
|
34
33
|
# restart samba so it reports the correct pool size
|
35
34
|
print "restarting samba server..."
|
36
35
|
output = %x( /usr/local/etc/rc.d/samba restart 2>&1 )
|
37
|
-
if $?.success? then puts "DONE"
|
38
|
-
else puts "FAILED! --> #{output}" end
|
36
|
+
if $?.success? then puts Rainbow("DONE").green
|
37
|
+
else puts Rainbow("FAILED!").red + " --> #{output}" end
|
39
38
|
end
|
40
39
|
|
41
40
|
def setupdisk_bsd(dev, label, password, compression, encryption, keylength, mountpoint)
|
@@ -72,4 +71,8 @@ module Frachtraum
|
|
72
71
|
|
73
72
|
end # setupdisk_bsd
|
74
73
|
|
74
|
+
# well, we need this line so attach can call attach_bsd
|
75
|
+
# but I honestly don't know why...
|
76
|
+
extend self
|
77
|
+
|
75
78
|
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
|
2
|
+
require 'thor'
|
3
|
+
require 'highline/import'
|
4
|
+
require 'rainbow'
|
5
|
+
require 'terminal-table'
|
6
|
+
|
7
|
+
def prompt_password(prompt="Password: ")
|
8
|
+
HighLine.ask(prompt) { |q| q.echo = false }
|
9
|
+
end
|
10
|
+
|
11
|
+
module Frachtraum
|
12
|
+
|
13
|
+
class Frachtraum::CLI < Thor
|
14
|
+
|
15
|
+
desc "attach [VOLUME]", "decrypt and mount volume(s)"
|
16
|
+
long_desc <<-LONGDESC
|
17
|
+
`frachtraum attach` will prompt you for a password.
|
18
|
+
|
19
|
+
The password is used to decrypt all volume specified
|
20
|
+
in #{Frachtraum::CONFIG_FILE}
|
21
|
+
|
22
|
+
You can optionally specify a single volume. In this case
|
23
|
+
only this volume will be decrypted and mounted.
|
24
|
+
LONGDESC
|
25
|
+
def attach(volume=nil)
|
26
|
+
|
27
|
+
password = prompt_password
|
28
|
+
|
29
|
+
Frachtraum.attach password, volume
|
30
|
+
end
|
31
|
+
|
32
|
+
# --------------
|
33
|
+
|
34
|
+
desc "capacity [OPTION]", "show overall storage capacity"
|
35
|
+
long_desc <<-LONGDESC
|
36
|
+
`frachtraum capacity` will output capacity...
|
37
|
+
|
38
|
+
lorem ipsum
|
39
|
+
LONGDESC
|
40
|
+
def capacity(option=nil)
|
41
|
+
c = Frachtraum.capacity
|
42
|
+
|
43
|
+
case option
|
44
|
+
when "smb", "samba"
|
45
|
+
puts "#{c[:total]/1000} #{c[:avail]/1000}"
|
46
|
+
else
|
47
|
+
puts ""
|
48
|
+
puts "Capacity:"
|
49
|
+
puts " Available: #{Frachtraum.pretty_SI_bytes(c[:avail])}"
|
50
|
+
puts " Used: #{Frachtraum.pretty_SI_bytes(c[:used])}"
|
51
|
+
puts " Total: #{Frachtraum.pretty_SI_bytes(c[:total])}"
|
52
|
+
puts ""
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# --------------
|
57
|
+
|
58
|
+
desc "list", "list volumes and/or timemachine targets"
|
59
|
+
long_desc <<-LONGDESC
|
60
|
+
lorem ipsum
|
61
|
+
LONGDESC
|
62
|
+
option :simple, :type => :boolean
|
63
|
+
def list(subset=nil)
|
64
|
+
|
65
|
+
# TODO: this needs to be a constant, or calculated as CONST + max length of volume/tm
|
66
|
+
list_width = 60 # character length of list
|
67
|
+
|
68
|
+
if subset == "volume" || subset == "volumes" || subset.nil?
|
69
|
+
if options[:simple]
|
70
|
+
Frachtraum::VOLUMES.each{ |volume| puts volume }
|
71
|
+
else
|
72
|
+
puts "" # empty line
|
73
|
+
puts "Volumes:"
|
74
|
+
puts "" # empty line
|
75
|
+
Frachtraum::VOLUMES.each{ |volume|
|
76
|
+
status =
|
77
|
+
if Frachtraum.zfs_dataset_exists?(volume)
|
78
|
+
Rainbow("attached").green
|
79
|
+
else
|
80
|
+
Rainbow("UNAVAILABLE").red
|
81
|
+
end
|
82
|
+
status = "[#{status}]".rjust(list_width-volume.length)
|
83
|
+
puts " #{volume}#{status}"
|
84
|
+
}
|
85
|
+
puts "" # empty line
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
if subset == "timemachine" || subset == "tm" || subset.nil?
|
90
|
+
if options[:simple]
|
91
|
+
Frachtraum::TIMEMACHINE_TARGETS.each{ |dataset| puts dataset }
|
92
|
+
else
|
93
|
+
puts "" unless subset.nil? # empty line
|
94
|
+
puts "Timemachine targets:"
|
95
|
+
puts "" # empty line
|
96
|
+
Frachtraum::TIMEMACHINE_TARGETS.each{ |dataset|
|
97
|
+
status =
|
98
|
+
if Frachtraum.zfs_dataset_exists?(dataset)
|
99
|
+
Rainbow("attached").green
|
100
|
+
else
|
101
|
+
Rainbow("UNAVAILABLE").red
|
102
|
+
end
|
103
|
+
status = "[#{status}]".rjust(list_width-dataset.length)
|
104
|
+
puts " #{dataset}#{status}"
|
105
|
+
}
|
106
|
+
puts "" # empty line
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# --------------
|
112
|
+
|
113
|
+
desc "report", "Print a detailed report on your frachtraum"
|
114
|
+
long_desc <<-LONGDESC
|
115
|
+
lorem ipsum
|
116
|
+
LONGDESC
|
117
|
+
def report()
|
118
|
+
|
119
|
+
report_rows = []
|
120
|
+
report_data = Frachtraum.report
|
121
|
+
report_data.keys.each do |volume|
|
122
|
+
volume_h = report_data[volume]
|
123
|
+
report_rows << [ volume,
|
124
|
+
Frachtraum.pretty_SI_bytes(volume_h[:used].to_i),
|
125
|
+
Frachtraum.pretty_SI_bytes(volume_h[:available].to_i),
|
126
|
+
volume_h[:compression],
|
127
|
+
volume_h[:compressratio]
|
128
|
+
]
|
129
|
+
end
|
130
|
+
|
131
|
+
# TODO
|
132
|
+
table = Terminal::Table.new :headings => ["VOLUMES", "USED", "AVAILABLE", "COMPRESSION", "COMPRESSRATIO"], :rows => report_rows
|
133
|
+
puts table
|
134
|
+
self.capacity
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
# --------------
|
139
|
+
|
140
|
+
desc "setupdisk", "setup a device as a new volume"
|
141
|
+
long_desc <<-LONGDESC
|
142
|
+
`frachtraum setup dev label` will setup...
|
143
|
+
|
144
|
+
lorem ispum
|
145
|
+
LONGDESC
|
146
|
+
options :compression => :string, :encryption => :string, :keylength => :integer, :mountpoint => :string
|
147
|
+
def setupdisk(dev,label)
|
148
|
+
|
149
|
+
compression = options[:compression] ? options[:compression] : Frachtraum::COMPRESSION
|
150
|
+
encryption = options[:encryption] ? options[:encryption] : Frachtraum::ENCRYPTION
|
151
|
+
keylength = options[:keylength] ? options[:keylength] : Frachtraum::KEYLENGTH
|
152
|
+
mountpoint = options[:mountpoint] ? options[:mountpoint] : Frachtraum::MOUNTPOINT
|
153
|
+
|
154
|
+
password1 = prompt_password("enter encryption password: ")
|
155
|
+
password2 = prompt_password("enter password again: ")
|
156
|
+
if password1.match(password2)
|
157
|
+
password = password1
|
158
|
+
else
|
159
|
+
abort "passwords not equal!"
|
160
|
+
end
|
161
|
+
|
162
|
+
puts ""
|
163
|
+
puts "Device: #{dev}"
|
164
|
+
puts "Label: #{label}"
|
165
|
+
puts "Compression: #{compression}"
|
166
|
+
puts "Encryption: #{encryption}"
|
167
|
+
puts "Keylength: #{keylength}"
|
168
|
+
puts "Mountpoint: #{mountpoint}"
|
169
|
+
puts ""
|
170
|
+
puts "ATTENTION! This is a destructive action. All data on the device will be"
|
171
|
+
puts "wiped. If you forget you password, you will not be able to access any"
|
172
|
+
puts "containing data any more."
|
173
|
+
puts ""
|
174
|
+
|
175
|
+
answer = HighLine.ask("Are you sure you want to continue? (type 'yes'): ") { |q| q.echo = true }
|
176
|
+
|
177
|
+
if answer.downcase.match("yes")
|
178
|
+
Frachtraum.setupdisk dev, label, password, compression, encryption, keylength, mountpoint
|
179
|
+
else
|
180
|
+
abort "ABORT -- device will not pe processed!"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# --------------
|
185
|
+
|
186
|
+
desc "sweep [VOLUME]", "sweep the volumes!"
|
187
|
+
long_desc <<-LONGDESC
|
188
|
+
`frachtraum sweep` will ...
|
189
|
+
|
190
|
+
lorem ipsum
|
191
|
+
LONGDESC
|
192
|
+
def sweep(volume=nil)
|
193
|
+
Frachtraum.sweep volume
|
194
|
+
end
|
195
|
+
|
196
|
+
# --------------
|
197
|
+
|
198
|
+
desc "test", "test system for compatibility"
|
199
|
+
long_desc <<-LONGDESC
|
200
|
+
`frachtraum test` will test...
|
201
|
+
|
202
|
+
lorem ipsum
|
203
|
+
LONGDESC
|
204
|
+
def test()
|
205
|
+
Frachtraum.run_system_test
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
data/lib/frachtraum/config.rb
CHANGED
@@ -10,7 +10,7 @@ module Frachtraum
|
|
10
10
|
KEYLENGTH = config['keylength']
|
11
11
|
MOUNTPOINT = config['mountpoint']
|
12
12
|
|
13
|
-
|
13
|
+
VOLUMES = config['volumes'].split(',')
|
14
14
|
TIMEMACHINE_TARGETS = config['tmtargets'].split(',')
|
15
15
|
else
|
16
16
|
COMPRESSION = 'lz4'
|
@@ -18,7 +18,7 @@ module Frachtraum
|
|
18
18
|
KEYLENGTH = 4096
|
19
19
|
MOUNTPOINT = '/frachtraum'
|
20
20
|
|
21
|
-
|
21
|
+
VOLUMES = []
|
22
22
|
TIMEMACHINE_TARGETS = []
|
23
23
|
end
|
24
24
|
end
|
data/lib/frachtraum/linux.rb
CHANGED
@@ -2,7 +2,7 @@ module Frachtraum
|
|
2
2
|
|
3
3
|
REQUIRED_TOOLS_LINUX = [] # not yet supported
|
4
4
|
|
5
|
-
def attach_linux(password,
|
5
|
+
def attach_linux(password, volume)
|
6
6
|
# TODO
|
7
7
|
abort "not yet implemented"
|
8
8
|
end
|
@@ -12,4 +12,6 @@ module Frachtraum
|
|
12
12
|
abort "not yet implemented"
|
13
13
|
end # setupdisk_linux
|
14
14
|
|
15
|
+
extend self
|
16
|
+
|
15
17
|
end
|
data/lib/frachtraum/osx.rb
CHANGED
@@ -8,7 +8,7 @@ module Frachtraum
|
|
8
8
|
|
9
9
|
REQUIRED_TOOLS_OSX = [] # not yet supported
|
10
10
|
|
11
|
-
def attach_osx(password,
|
11
|
+
def attach_osx(password, volume)
|
12
12
|
# TODO
|
13
13
|
abort "not yet implemented"
|
14
14
|
end
|
@@ -18,4 +18,6 @@ module Frachtraum
|
|
18
18
|
abort "not yet implemented"
|
19
19
|
end # setupdisk_osx
|
20
20
|
|
21
|
+
extend self
|
22
|
+
|
21
23
|
end
|
data/lib/frachtraum.rb
CHANGED
@@ -7,15 +7,15 @@ require 'open3'
|
|
7
7
|
require 'parseconfig'
|
8
8
|
|
9
9
|
require 'frachtraum/config'
|
10
|
+
require 'frachtraum/cli'
|
10
11
|
require 'frachtraum/bsd'
|
11
12
|
require 'frachtraum/linux'
|
12
|
-
|
13
|
+
require 'frachtraum/osx'
|
13
14
|
|
14
15
|
module Frachtraum
|
15
16
|
|
16
|
-
VERSION = '0.0.
|
17
|
+
VERSION = '0.0.2'.freeze
|
17
18
|
|
18
|
-
|
19
19
|
# Kibibyte, Mebibyte, Gibibyte, etc... all the IEC sizes
|
20
20
|
BYTES_IN_KiB = 2**10
|
21
21
|
BYTES_IN_MiB = 2**20
|
@@ -38,9 +38,9 @@ module Frachtraum
|
|
38
38
|
|
39
39
|
exit_status = wait_thr.value
|
40
40
|
if exit_status.success?
|
41
|
-
puts "done"
|
41
|
+
puts Rainbow("done").green
|
42
42
|
else
|
43
|
-
abort "FAILED! --> #{stdout_err}"
|
43
|
+
abort Rainbow("FAILED!").red + " --> #{stdout_err}"
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end # exec_cmd
|
@@ -65,10 +65,12 @@ module Frachtraum
|
|
65
65
|
end
|
66
66
|
module_function :pretty_IEC_bytes
|
67
67
|
|
68
|
-
def attach(password,
|
68
|
+
def attach(password, volume=nil)
|
69
69
|
case RUBY_PLATFORM
|
70
|
-
when /bsd/
|
71
|
-
when /linux/
|
70
|
+
when /bsd/ then attach_bsd password, volume
|
71
|
+
when /linux/ then attach_linux password, volume
|
72
|
+
#when /darwin/ then attach_osx password, volume
|
73
|
+
else abort "OS not supported"
|
72
74
|
end
|
73
75
|
end
|
74
76
|
module_function :attach
|
@@ -76,9 +78,9 @@ module Frachtraum
|
|
76
78
|
def capacity()
|
77
79
|
total_used = 0
|
78
80
|
total_avail = 0
|
79
|
-
|
80
|
-
used = %x( zfs get -o value -Hp used #{
|
81
|
-
avail = %x( zfs get -o value -Hp available #{
|
81
|
+
Frachtraum::VOLUMES.each do |volume|
|
82
|
+
used = %x( zfs get -o value -Hp used #{volume} 2>&1 )
|
83
|
+
avail = %x( zfs get -o value -Hp available #{volume} 2>&1 )
|
82
84
|
|
83
85
|
total_used += (used =="" ? 0 : used).to_i # / 1000 # 1024
|
84
86
|
total_avail += (avail=="" ? 0 : avail).to_i # / 1000 # 1024
|
@@ -90,31 +92,67 @@ module Frachtraum
|
|
90
92
|
end
|
91
93
|
module_function :capacity
|
92
94
|
|
95
|
+
def report()
|
96
|
+
|
97
|
+
report_table = {}
|
98
|
+
reported_values = [:used,:available,:compression,:compressratio]
|
99
|
+
|
100
|
+
(Frachtraum::VOLUMES + Frachtraum::TIMEMACHINE_TARGETS).each do |dataset|
|
101
|
+
dataset_info = {}
|
102
|
+
if zfs_dataset_exists?(dataset)
|
103
|
+
reported_values.each do |repval|
|
104
|
+
dataset_info[repval] = %x( zfs get -o value -Hp #{repval.to_s} #{dataset} )
|
105
|
+
end
|
106
|
+
else
|
107
|
+
reported_values.each {|repval| dataset_info[repval] = "N/A" }
|
108
|
+
end
|
109
|
+
report_table[dataset] = dataset_info
|
110
|
+
end
|
111
|
+
|
112
|
+
return report_table
|
113
|
+
end
|
114
|
+
module_function :report
|
115
|
+
|
93
116
|
|
94
117
|
def setupdisk(dev, label, password, compression, encryption, keylength, mountpoint)
|
95
118
|
|
96
119
|
abort "untested procedure -- won't continue"
|
97
120
|
|
98
121
|
case RUBY_PLATFORM
|
99
|
-
when /bsd/
|
100
|
-
when /linux/
|
122
|
+
when /bsd/ then setupdisk_bsd dev, label, password, compression, encryption, keylength, mountpoint
|
123
|
+
when /linux/ then setupdisk_linux dev, label, password, compression, encryption, keylength, mountpoint
|
124
|
+
#when /darwin/ then setupdisk_osx dev, label, password, compression, encryption, keylength, mountpoint
|
101
125
|
else abort "OS not supported"
|
102
126
|
end
|
103
127
|
end
|
104
128
|
module_function :setupdisk
|
105
129
|
|
130
|
+
def sweep(volume)
|
131
|
+
|
132
|
+
target_volumes = volume.nil? ? Frachtraum::VOLUMES : volume
|
133
|
+
|
134
|
+
# TODO
|
135
|
+
abort "sweeping not supported yet"
|
136
|
+
|
137
|
+
target_volumes.each do |volume|
|
138
|
+
if zfs_dataset_exists?(volume)
|
139
|
+
# TODO
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
module_function :sweep
|
144
|
+
|
106
145
|
|
107
146
|
def run_system_test()
|
108
147
|
tool_list = []
|
109
148
|
case RUBY_PLATFORM
|
110
|
-
when /bsd/
|
111
|
-
when /linux/
|
149
|
+
when /bsd/ then tool_list = REQUIRED_TOOLS_BSD
|
150
|
+
when /linux/ then tool_list = REQUIRED_TOOLS_LINUX
|
151
|
+
#when /darwin/ then tool_list = REQUIRED_TOOLS_OSX
|
112
152
|
else abort "OS not supported"
|
113
153
|
end
|
114
154
|
|
115
|
-
tool_list.each
|
116
|
-
find_executable tool
|
117
|
-
end
|
155
|
+
tool_list.each { |tool| find_executable tool }
|
118
156
|
|
119
157
|
# find_executable seems to create such file in case executable is not found
|
120
158
|
File.delete 'mkmf.log' if File.exists?('mkmf.log')
|
@@ -125,30 +163,16 @@ module Frachtraum
|
|
125
163
|
def zfs_dataset_exists?(dataset)
|
126
164
|
output = %x( zfs get -H mounted #{dataset} 2>&1 )
|
127
165
|
case output
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
166
|
+
when /yes/
|
167
|
+
return true
|
168
|
+
when /dataset does not exist/, /permission denied/
|
169
|
+
return false
|
170
|
+
else
|
171
|
+
abort "can't handle output of zfs_dataset_exists?: #{output}"
|
134
172
|
end
|
135
173
|
end
|
136
174
|
module_function :zfs_dataset_exists?
|
137
175
|
|
138
|
-
def zfs_dataset_compression_ratio(dataset)
|
139
|
-
cmd = "zfs get compressratio #{dataset} | grep compressratio"
|
140
|
-
Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
|
141
|
-
output = stdout_err.gets
|
142
|
-
if output == ""
|
143
|
-
return "N/A"
|
144
|
-
else
|
145
|
-
parts = output.split(' ')
|
146
|
-
return parts[2] # => ratio
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
module_function :zfs_dataset_compression_ratio
|
151
|
-
|
152
176
|
end # Frachtraum
|
153
177
|
|
154
178
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frachtraum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maximilian Irro
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 2.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: terminal-table
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.5
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.5
|
69
83
|
description: lorem ipsum
|
70
84
|
email: max@disposia.org
|
71
85
|
executables:
|
@@ -73,6 +87,7 @@ executables:
|
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
90
|
+
- .gitignore
|
76
91
|
- Gemfile
|
77
92
|
- LICENSE
|
78
93
|
- README.md
|
@@ -81,6 +96,7 @@ files:
|
|
81
96
|
- frachtraum.gemspec
|
82
97
|
- lib/frachtraum.rb
|
83
98
|
- lib/frachtraum/bsd.rb
|
99
|
+
- lib/frachtraum/cli.rb
|
84
100
|
- lib/frachtraum/config.rb
|
85
101
|
- lib/frachtraum/linux.rb
|
86
102
|
- lib/frachtraum/osx.rb
|