frachtraum 0.0.9 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/frachtraum.rb +53 -50
- data/lib/frachtraum/bsd.rb +39 -39
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjFhYTE5ZTJhZThiZjE1OTM2YjQ3MmEwMDlmOTA3YmE4MzdiYmJiNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDQyZGNmOThjZTJmMjliYjUwOTU5NGU3ZmY2NzUzM2E5NWQxNzliNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjAwN2M1MjMwOGZmMDBiYjE2ODBhMWQ3MTc2Nzg5Y2ViMmU4NmRjOTE0MWY0
|
10
|
+
YzQwMDNlNjNlZTA1NDFkMGNiZTk0MmIwYjE4ZTIyNGMyNmIzZjNkZDNmNWJm
|
11
|
+
MmMyMmRhZmYzZWFiZTg4MDJiZjQ0M2JiMGYxZDczNTIzOWRiZjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTQzODI3Y2E2NThlZGUwMWIzNTYyMDFiODkzNjg0NDJkZDU4YTg4YzUwNjY3
|
14
|
+
ODE2YmY1MzdhZDlmMmU2ZTdkMDRhOTk4MDFhZWIwMmU5ZjAwZjA4ZWNhM2I5
|
15
|
+
YjliMjU1ODQ5YjRlOTdmZDc4YWZiMjA4NjA3M2VmODUyZTlmMTg=
|
data/lib/frachtraum.rb
CHANGED
@@ -13,41 +13,45 @@ require 'frachtraum/linux'
|
|
13
13
|
require 'frachtraum/osx'
|
14
14
|
|
15
15
|
module Frachtraum
|
16
|
-
|
17
|
-
VERSION = '0.0.
|
18
|
-
|
16
|
+
|
17
|
+
VERSION = '0.0.12'.freeze
|
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
|
22
22
|
BYTES_IN_GiB = 2**30
|
23
23
|
BYTES_IN_TiB = 2**40
|
24
24
|
|
25
|
-
# these define a KB as 1000 bits, according to the SI prefix
|
25
|
+
# these define a KB as 1000 bits, according to the SI prefix
|
26
26
|
BYTES_IN_KB = 10**3
|
27
27
|
BYTES_IN_MB = 10**6
|
28
28
|
BYTES_IN_GB = 10**9
|
29
29
|
BYTES_IN_TB = 10**12
|
30
|
-
|
30
|
+
|
31
31
|
OUTPUT_DOTS_LEN = 40 # TODO: the length should be dynamically calculated, based on the strlen of longest tmtarget or volume
|
32
|
-
|
32
|
+
|
33
|
+
|
34
|
+
CHECKMARK = "\u2713" # => ✓
|
35
|
+
BALLOTX = "\u2717" # => ✗
|
36
|
+
|
33
37
|
def exec_cmd(msg, cmd)
|
34
|
-
|
38
|
+
|
35
39
|
print msg
|
36
|
-
|
40
|
+
|
37
41
|
Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
|
38
42
|
puts line while line = stdout_err.gets
|
39
|
-
|
43
|
+
|
40
44
|
exit_status = wait_thr.value
|
41
45
|
if exit_status.success?
|
42
46
|
puts Rainbow("done").green
|
43
47
|
else
|
44
|
-
abort Rainbow("FAILED!").red + " --> #{stdout_err}"
|
48
|
+
abort Rainbow("FAILED!").red + " --> #{stdout_err}"
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end # exec_cmd
|
48
|
-
|
52
|
+
|
49
53
|
# ---------------
|
50
|
-
|
54
|
+
|
51
55
|
def pretty_SI_bytes(bytes)
|
52
56
|
return "%.1f TB" % (bytes.to_f / BYTES_IN_TB) if bytes > BYTES_IN_TB
|
53
57
|
return "%.1f GB" % (bytes.to_f / BYTES_IN_GB) if bytes > BYTES_IN_GB
|
@@ -56,7 +60,7 @@ module Frachtraum
|
|
56
60
|
return "#{bytes} B"
|
57
61
|
end
|
58
62
|
module_function :pretty_SI_bytes
|
59
|
-
|
63
|
+
|
60
64
|
def pretty_IEC_bytes(bytes)
|
61
65
|
return "%.1f TiB" % (bytes.to_f / BYTES_IN_TiB) if bytes > BYTES_IN_TiB
|
62
66
|
return "%.1f GiB" % (bytes.to_f / BYTES_IN_GiB) if bytes > BYTES_IN_GiB
|
@@ -65,7 +69,7 @@ module Frachtraum
|
|
65
69
|
return "#{bytes} B"
|
66
70
|
end
|
67
71
|
module_function :pretty_IEC_bytes
|
68
|
-
|
72
|
+
|
69
73
|
def attach(password, volume=nil)
|
70
74
|
case RUBY_PLATFORM
|
71
75
|
when /bsd/ then attach_bsd password, volume
|
@@ -75,70 +79,72 @@ module Frachtraum
|
|
75
79
|
end
|
76
80
|
end
|
77
81
|
module_function :attach
|
78
|
-
|
82
|
+
|
79
83
|
def capacity()
|
80
84
|
total_used = 0
|
81
85
|
total_avail = 0
|
82
86
|
Frachtraum::VOLUMES.each do |volume|
|
83
87
|
used = %x( zfs get -o value -Hp used #{volume} 2>&1 )
|
84
88
|
avail = %x( zfs get -o value -Hp available #{volume} 2>&1 )
|
85
|
-
|
89
|
+
|
86
90
|
total_used += (used =="" ? 0 : used).to_i # / 1000 # 1024
|
87
91
|
total_avail += (avail=="" ? 0 : avail).to_i # / 1000 # 1024
|
88
92
|
end
|
89
|
-
|
93
|
+
|
90
94
|
total = total_used + total_avail
|
91
|
-
|
95
|
+
|
92
96
|
return {:total => total, :avail => total_avail, :used => total_used}
|
93
97
|
end
|
94
98
|
module_function :capacity
|
95
|
-
|
99
|
+
|
96
100
|
def report()
|
97
|
-
|
101
|
+
|
98
102
|
report_table = {}
|
99
103
|
reported_values = [:used,:available,:compression,:compressratio]
|
100
|
-
|
104
|
+
|
101
105
|
(Frachtraum::VOLUMES + Frachtraum::TIMEMACHINE_TARGETS).each do |dataset|
|
102
106
|
volume_info = {}
|
103
|
-
|
107
|
+
|
104
108
|
# fetch the values
|
105
109
|
if zfs_volume_exists?(dataset)
|
106
110
|
reported_values.each do |repval|
|
107
111
|
volume_info[repval] = %x( zfs get -o value -Hp #{repval.to_s} #{dataset} )
|
108
112
|
end
|
109
113
|
else
|
110
|
-
reported_values.each {|repval| volume_info[repval] = "N/A" }
|
114
|
+
reported_values.each {|repval| volume_info[repval] = "N/A" }
|
111
115
|
end
|
112
|
-
|
116
|
+
|
113
117
|
# calculate a total size for each volume
|
114
|
-
volume_info[:total] =
|
118
|
+
volume_info[:total] =
|
115
119
|
if volume_info[:used]=="N/A" || volume_info[:available]=="N/A"
|
116
120
|
"N/A"
|
117
|
-
else
|
121
|
+
else
|
118
122
|
(volume_info[:used].to_i + volume_info[:available].to_i)
|
119
123
|
end
|
120
|
-
|
121
|
-
volume_info[:usage] =
|
124
|
+
|
125
|
+
volume_info[:usage] =
|
122
126
|
if volume_info[:total] == 0
|
123
127
|
"0 %"
|
124
128
|
elsif volume_info[:used]=="N/A" || volume_info[:total]=="N/A"
|
125
129
|
"N/A"
|
130
|
+
elsif volume_info[:available].to_i == 0
|
131
|
+
"100 %"
|
126
132
|
else
|
127
133
|
(100 * volume_info[:used].to_f / volume_info[:total].to_f ).to_i.to_s + " %"
|
128
134
|
end
|
129
|
-
|
135
|
+
|
130
136
|
report_table[dataset] = volume_info
|
131
137
|
end
|
132
138
|
|
133
139
|
return report_table
|
134
140
|
end
|
135
141
|
module_function :report
|
136
|
-
|
137
|
-
|
142
|
+
|
143
|
+
|
138
144
|
def setupdisk(dev, label, password, compression, encryption, keylength, mountpoint)
|
139
|
-
|
145
|
+
|
140
146
|
abort "untested procedure -- won't continue"
|
141
|
-
|
147
|
+
|
142
148
|
case RUBY_PLATFORM
|
143
149
|
when /bsd/ then setupdisk_bsd dev, label, password, compression, encryption, keylength, mountpoint
|
144
150
|
when /linux/ then setupdisk_linux dev, label, password, compression, encryption, keylength, mountpoint
|
@@ -147,54 +153,51 @@ module Frachtraum
|
|
147
153
|
end
|
148
154
|
end
|
149
155
|
module_function :setupdisk
|
150
|
-
|
156
|
+
|
151
157
|
def sweep(volume)
|
152
|
-
|
158
|
+
|
153
159
|
target_volumes = volume.nil? ? Frachtraum::VOLUMES : volume
|
154
|
-
|
160
|
+
|
155
161
|
# TODO
|
156
162
|
abort "sweeping not supported yet"
|
157
|
-
|
158
|
-
target_volumes.each do |volume|
|
163
|
+
|
164
|
+
target_volumes.each do |volume|
|
159
165
|
if zfs_volume_exists?(volume)
|
160
166
|
# TODO
|
161
167
|
end
|
162
168
|
end
|
163
169
|
end
|
164
170
|
module_function :sweep
|
165
|
-
|
171
|
+
|
166
172
|
|
167
173
|
def run_system_test()
|
168
|
-
tool_list = []
|
174
|
+
tool_list = []
|
169
175
|
case RUBY_PLATFORM
|
170
176
|
when /bsd/ then tool_list = REQUIRED_TOOLS_BSD
|
171
177
|
when /linux/ then tool_list = REQUIRED_TOOLS_LINUX
|
172
178
|
#when /darwin/ then tool_list = REQUIRED_TOOLS_OSX
|
173
179
|
else abort "OS not supported"
|
174
180
|
end
|
175
|
-
|
181
|
+
|
176
182
|
tool_list.each { |tool| find_executable tool }
|
177
|
-
|
183
|
+
|
178
184
|
# find_executable seems to create such file in case executable is not found
|
179
185
|
File.delete 'mkmf.log' if File.exists?('mkmf.log')
|
180
186
|
end # run_system_test
|
181
187
|
module_function :run_system_test
|
182
|
-
|
183
|
-
|
188
|
+
|
189
|
+
|
184
190
|
def zfs_volume_exists?(dataset)
|
185
191
|
output = %x( zfs get -H mounted #{dataset} 2>&1 )
|
186
192
|
case output
|
187
193
|
when /yes/
|
188
194
|
return true
|
189
|
-
when /dataset does not exist/, /permission denied/
|
195
|
+
when /dataset does not exist/, /permission denied/
|
190
196
|
return false
|
191
|
-
else
|
197
|
+
else
|
192
198
|
abort "can't handle output of zfs_volume_exists?: #{output}"
|
193
199
|
end
|
194
200
|
end
|
195
201
|
module_function :zfs_volume_exists?
|
196
|
-
|
197
|
-
end # Frachtraum
|
198
|
-
|
199
|
-
|
200
202
|
|
203
|
+
end # Frachtraum
|
data/lib/frachtraum/bsd.rb
CHANGED
@@ -1,79 +1,79 @@
|
|
1
1
|
module Frachtraum
|
2
|
-
|
2
|
+
|
3
3
|
REQUIRED_TOOLS_BSD = ['dd','grep','gpart','glabel','geli','zfs','zpool']
|
4
|
-
|
4
|
+
|
5
5
|
def attach_bsd(password, volume=nil)
|
6
|
-
|
6
|
+
|
7
7
|
# if we provided a specific depot, run procedure only on that one
|
8
8
|
volumes = volume.nil? ? Frachtraum::VOLUMES : [ volume ]
|
9
|
-
|
9
|
+
|
10
10
|
# first of all, decrypt and mount all depots
|
11
|
-
volumes.each do |v|
|
12
|
-
print "decrypting #{v}...".ljust(OUTPUT_DOTS_LEN,".")
|
13
|
-
|
11
|
+
volumes.each do |v|
|
12
|
+
print "decrypting #{v}...".ljust(OUTPUT_DOTS_LEN,".")
|
13
|
+
|
14
14
|
output = %x( echo #{password} | geli attach -d -j - /dev/label/#{v} 2>&1 )
|
15
|
-
if $?.success?
|
15
|
+
if $?.success?
|
16
16
|
output = %x( zfs mount #{v} 2>&1 )
|
17
|
-
if $?.success? then puts Rainbow(
|
18
|
-
else puts Rainbow("
|
19
|
-
else
|
20
|
-
puts Rainbow("
|
17
|
+
if $?.success? then puts Rainbow(CHECKMARK).green
|
18
|
+
else puts Rainbow("#{BALLOTX}\n#{output}").red end
|
19
|
+
else
|
20
|
+
puts Rainbow("#{BALLOTX}\n#{output}").red
|
21
21
|
end
|
22
22
|
end # volumes.each
|
23
|
-
|
23
|
+
|
24
24
|
# mount timemachine targets as well
|
25
25
|
Frachtraum::TIMEMACHINE_TARGETS.each do |tmtarget|
|
26
|
-
print "mounting
|
26
|
+
print "mounting #{tmtarget}...".ljust(OUTPUT_DOTS_LEN,".")
|
27
27
|
|
28
28
|
output = %x( zfs mount #{tmtarget} 2>&1 )
|
29
|
-
if $?.success? then puts Rainbow(
|
30
|
-
else puts Rainbow("
|
29
|
+
if $?.success? then puts Rainbow(CHECKMARK).green
|
30
|
+
else puts Rainbow("#{BALLOTX}\n#{output}").red end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# restart samba so it reports the correct pool size
|
34
|
-
print "restarting samba server...".ljust(OUTPUT_DOTS_LEN,".")
|
35
|
-
|
34
|
+
print "restarting samba server...".ljust(OUTPUT_DOTS_LEN,".")
|
35
|
+
|
36
36
|
output = %x( /usr/local/etc/rc.d/samba restart 2>&1 )
|
37
|
-
if $?.success? then puts Rainbow(
|
38
|
-
else puts Rainbow("
|
37
|
+
if $?.success? then puts Rainbow(CHECKMARK).green
|
38
|
+
else puts Rainbow("#{BALLOTX}\n#{output}").red end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def setupdisk_bsd(dev, label, password, compression, encryption, keylength, mountpoint)
|
42
|
-
|
42
|
+
|
43
43
|
# TODO password promt, confirmation question, etc..
|
44
44
|
abort "implementation not ready yet"
|
45
|
-
|
46
|
-
|
47
|
-
exec_cmd "destroying previous partitioning on /dev/#{dev}...",
|
45
|
+
|
46
|
+
|
47
|
+
exec_cmd "destroying previous partitioning on /dev/#{dev}...",
|
48
48
|
"dd if=/dev/zero of=/dev/#{dev} bs=512 count=1"
|
49
|
-
|
50
|
-
exec_cmd "creating gpart container on /dev/#{dev}...",
|
49
|
+
|
50
|
+
exec_cmd "creating gpart container on /dev/#{dev}...",
|
51
51
|
"gpart create -s GPT #{dev}"
|
52
52
|
|
53
|
-
exec_cmd "labeling /dev/#{dev} with '#{label}'...",
|
53
|
+
exec_cmd "labeling /dev/#{dev} with '#{label}'...",
|
54
54
|
"glabel label -v #{label} /dev/#{dev}"
|
55
55
|
|
56
56
|
exec_cmd "initialising /dev/#{dev} as password protected GEOM provider with #{encryption} encryption...",
|
57
57
|
"echo #{password} | geli init -s #{keylength} -e #{encryption} -J - /dev/label/#{label}"
|
58
|
-
|
59
|
-
exec_cmd "attaching /dev/label/#{label} as GEOM provider, creating device /dev/label/#{label}.eli...",
|
58
|
+
|
59
|
+
exec_cmd "attaching /dev/label/#{label} as GEOM provider, creating device /dev/label/#{label}.eli...",
|
60
60
|
"echo #{password} | geli attach -d -j - /dev/label/#{label}"
|
61
61
|
|
62
|
-
exec_cmd "creating zpool #{mountpoint}/#{label} on encrypted device /dev/label/#{label}.eli...",
|
62
|
+
exec_cmd "creating zpool #{mountpoint}/#{label} on encrypted device /dev/label/#{label}.eli...",
|
63
63
|
"zpool create -m #{mountpoint}/#{label} #{label} /dev/label/#{label}.eli"
|
64
64
|
|
65
|
-
exec_cmd "setting compression '#{compression}' for new zfs on #{mountpoint}/#{label}...",
|
66
|
-
"zfs set compression=#{compression} #{label}"
|
65
|
+
exec_cmd "setting compression '#{compression}' for new zfs on #{mountpoint}/#{label}...",
|
66
|
+
"zfs set compression=#{compression} #{label}"
|
67
67
|
|
68
|
-
exec_cmd "setting permissions...",
|
68
|
+
exec_cmd "setting permissions...",
|
69
69
|
"chmod -R 775 #{mountpoint}/#{label}"
|
70
70
|
|
71
71
|
puts "setup finished"
|
72
|
-
|
72
|
+
|
73
73
|
end # setupdisk_bsd
|
74
|
-
|
74
|
+
|
75
75
|
# well, we need this line so attach can call attach_bsd
|
76
76
|
# but I honestly don't know why...
|
77
77
|
extend self
|
78
|
-
|
79
|
-
end
|
78
|
+
|
79
|
+
end
|