diskman 1.0.5 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/diskman +28 -27
- data/lib/diskman/chooser.rb +1 -1
- data/lib/diskman/commands/fdisk.rb +1 -1
- data/lib/diskman/commands/mkfs.rb +1 -1
- data/lib/diskman/commands/write.rb +3 -3
- data/lib/diskman/confirmer.rb +2 -2
- data/lib/diskman/device.rb +3 -3
- data/lib/diskman/root_device.rb +2 -2
- data/lib/diskman/system.rb +2 -2
- data/lib/diskman/version.rb +1 -1
- data/lib/diskman.rb +1 -1
- metadata +21 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 356141ac045d586f1d8dec632762474496de583c2cd1f9199b392ad273baf123
|
4
|
+
data.tar.gz: '09057fecdaa82c8fddac9a7ed21c2d172f0cc1e342331d226967f908e0330906'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c5c298f9849ef5e25d952b8bc782749c2b98075ef9289f2379f708932c4041bb301cb22dcbe0fa90337fae41103af8b8f9c0079ba7a414935222094b621ffc7
|
7
|
+
data.tar.gz: e840f6c4bb49c3a6f8559494986c082515d3ff8f8c9b705d9d4f9a32bd9794308e21d6044296a03c5dd8305f34a626ce10d2aeb7cfb488491c1931bc9da9d4cb
|
data/bin/diskman
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require_relative '../lib/diskman'
|
3
|
+
require 'docopt'
|
4
|
+
|
3
5
|
include Diskman
|
4
6
|
|
5
|
-
|
7
|
+
Params = Struct.new(
|
8
|
+
:version,
|
9
|
+
:list,
|
10
|
+
:write,
|
11
|
+
:fdisk,
|
12
|
+
:mkfs,
|
13
|
+
:file,
|
14
|
+
keyword_init: true,
|
15
|
+
)
|
6
16
|
|
7
17
|
class Main
|
8
18
|
def initialize(opts)
|
@@ -14,30 +24,21 @@ class Main
|
|
14
24
|
end
|
15
25
|
|
16
26
|
def params
|
17
|
-
@params ||=
|
27
|
+
@params ||= Params.new(
|
18
28
|
version: @opts['--version'],
|
19
|
-
help: @opts['--help'],
|
20
29
|
list: @opts['--list'],
|
21
30
|
write: @opts['write'],
|
22
31
|
fdisk: @opts['fdisk'],
|
23
32
|
mkfs: @opts['mkfs'],
|
24
33
|
file: @opts['<file>'],
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def exit_usage
|
29
|
-
puts DOCS
|
30
|
-
exit 0
|
31
|
-
end
|
32
|
-
|
33
|
-
def exit_version
|
34
|
-
puts Diskman::VERSION
|
35
|
-
exit 0
|
34
|
+
)
|
36
35
|
end
|
37
36
|
|
38
37
|
def run
|
39
|
-
|
40
|
-
|
38
|
+
if params.version
|
39
|
+
puts VERSION
|
40
|
+
exit
|
41
|
+
end
|
41
42
|
|
42
43
|
if params.mkfs
|
43
44
|
Command::Mkfs.new.run(list: params.list)
|
@@ -46,25 +47,25 @@ class Main
|
|
46
47
|
elsif params.fdisk
|
47
48
|
Command::Fdisk.new.run
|
48
49
|
end
|
49
|
-
rescue Interrupt
|
50
|
+
rescue Interrupt # rubocop:disable Lint/SuppressedException
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
usage = <<~EOF
|
55
|
+
Usage:
|
55
56
|
#{File.basename($0)} write <file>
|
56
57
|
#{File.basename($0)} fdisk
|
57
|
-
#{File.basename($0)} mkfs [
|
58
|
+
#{File.basename($0)} mkfs [--list]
|
58
59
|
#{File.basename($0)} ( --version | --help )
|
59
60
|
|
60
|
-
|
61
|
-
-v, --version
|
62
|
-
-h, --help
|
61
|
+
Options:
|
62
|
+
-v, --version Show version
|
63
|
+
-h, --help Show this help
|
63
64
|
EOF
|
64
65
|
|
65
66
|
begin
|
66
|
-
Main.run(Docopt
|
67
|
-
rescue Docopt::Exit
|
68
|
-
puts
|
69
|
-
exit
|
67
|
+
Main.run(Docopt.docopt(usage))
|
68
|
+
rescue Docopt::Exit
|
69
|
+
puts usage
|
70
|
+
exit 2
|
70
71
|
end
|
data/lib/diskman/chooser.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Command
|
2
2
|
class Write
|
3
3
|
def run(file:)
|
4
|
-
if !File.
|
4
|
+
if !File.exist?(file)
|
5
5
|
puts ('Unable to read ' + file).red
|
6
6
|
raise Interrupt
|
7
7
|
end
|
@@ -10,13 +10,13 @@ module Command
|
|
10
10
|
device = device.choose_with_partitions
|
11
11
|
|
12
12
|
size = File.size(file)
|
13
|
-
cmd = device.get_write_command(file
|
13
|
+
cmd = device.get_write_command(file)
|
14
14
|
|
15
15
|
puts "File: #{file.yellow} (#{System.bytes2human(size)})"
|
16
16
|
puts "Device: #{device.to_s.yellow}"
|
17
17
|
puts "Command: #{cmd.yellow}"
|
18
18
|
|
19
|
-
System.exec!
|
19
|
+
System.exec!(cmd)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/diskman/confirmer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Diskman
|
2
2
|
# Confirms whether the user wants to do something destructive.
|
3
3
|
class Confirmer
|
4
|
-
YES = '
|
4
|
+
YES = 'yes'
|
5
5
|
|
6
6
|
def self.check!
|
7
7
|
new.check!
|
@@ -9,7 +9,7 @@ module Diskman
|
|
9
9
|
|
10
10
|
def check!
|
11
11
|
puts
|
12
|
-
puts 'Are you sure? Type "%s"
|
12
|
+
puts 'Are you sure? Type "%s"' % YES
|
13
13
|
puts
|
14
14
|
|
15
15
|
print '> '
|
data/lib/diskman/device.rb
CHANGED
@@ -16,7 +16,7 @@ module Diskman
|
|
16
16
|
'sudo mkfs.%s %s' % [fs, @path]
|
17
17
|
end
|
18
18
|
|
19
|
-
def get_write_command(path
|
19
|
+
def get_write_command(path)
|
20
20
|
dd = 'sudo dd if="%s" of="%s" bs=%dK status=progress'
|
21
21
|
dd % [path, @path, 4096]
|
22
22
|
end
|
@@ -27,8 +27,8 @@ module Diskman
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def <=>(
|
31
|
-
@path <=>
|
30
|
+
def <=>(other)
|
31
|
+
@path <=> other.path
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/diskman/root_device.rb
CHANGED
@@ -35,7 +35,7 @@ module Diskman
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def get_with_partitions
|
38
|
-
Dir[@path + '*'].
|
38
|
+
Dir[@path + '*'].map do |file|
|
39
39
|
file =~ %r[/dev/(.*)] && Device.new($1)
|
40
40
|
end.sort
|
41
41
|
end
|
@@ -45,7 +45,7 @@ module Diskman
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def get_prop(name)
|
48
|
-
file =
|
48
|
+
file = '/sys/class/block/%s/%s' % [@name, name]
|
49
49
|
File.read(file).strip.gsub(/\s+/, ' ')
|
50
50
|
end
|
51
51
|
|
data/lib/diskman/system.rb
CHANGED
@@ -15,7 +15,7 @@ module Diskman
|
|
15
15
|
Confirmer.check! if safe
|
16
16
|
prepare_sudo_session! if sudo
|
17
17
|
puts
|
18
|
-
exec
|
18
|
+
exec(cmd)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Convert bytes into a human-friendly representation.
|
@@ -26,7 +26,7 @@ module Diskman
|
|
26
26
|
# advertised.
|
27
27
|
k = 1000
|
28
28
|
|
29
|
-
suffixes = [
|
29
|
+
suffixes = %w[T G M K B]
|
30
30
|
|
31
31
|
suffixes.each_with_index do |suffix, i|
|
32
32
|
threshold = k ** (suffixes.length - i - 1)
|
data/lib/diskman/version.rb
CHANGED
data/lib/diskman.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diskman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crdx
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.8.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.8.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: docopt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.6.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.6.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: require_all
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
47
|
+
version: '3.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,19 +81,19 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.8'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.21.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.21.0
|
97
97
|
description:
|
98
98
|
email:
|
99
99
|
executables:
|
@@ -116,7 +116,8 @@ files:
|
|
116
116
|
homepage: https://github.com/crdx/diskman
|
117
117
|
licenses:
|
118
118
|
- MIT
|
119
|
-
metadata:
|
119
|
+
metadata:
|
120
|
+
rubygems_mfa_required: 'true'
|
120
121
|
post_install_message:
|
121
122
|
rdoc_options: []
|
122
123
|
require_paths:
|
@@ -125,14 +126,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
126
|
requirements:
|
126
127
|
- - ">="
|
127
128
|
- !ruby/object:Gem::Version
|
128
|
-
version: '0'
|
129
|
+
version: '3.0'
|
129
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
131
|
requirements:
|
131
132
|
- - ">="
|
132
133
|
- !ruby/object:Gem::Version
|
133
134
|
version: '0'
|
134
135
|
requirements: []
|
135
|
-
rubygems_version: 3.2.
|
136
|
+
rubygems_version: 3.2.29
|
136
137
|
signing_key:
|
137
138
|
specification_version: 4
|
138
139
|
summary: Interactive command line interface for safely managing disks
|